Commit 16d3de63 authored by Steven's avatar Steven

chore: update resource binary endpoint

parent 2c50d346
...@@ -1736,31 +1736,6 @@ paths: ...@@ -1736,31 +1736,6 @@ paths:
format: date-time format: date-time
tags: tags:
- UserService - UserService
/file/{name}:
get:
summary: GetResourceBinary returns a resource binary by name.
operationId: ResourceService_GetResourceBinary
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/apiHttpBody'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: |-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
pattern: resources/[^/]+
tags:
- ResourceService
/file/{name}/avatar: /file/{name}/avatar:
get: get:
summary: GetUserAvatarBinary gets the avatar of a user. summary: GetUserAvatarBinary gets the avatar of a user.
...@@ -1796,6 +1771,36 @@ paths: ...@@ -1796,6 +1771,36 @@ paths:
format: byte format: byte
tags: tags:
- UserService - UserService
/file/{name}/{filename}:
get:
summary: GetResourceBinary returns a resource binary by name.
operationId: ResourceService_GetResourceBinary
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/apiHttpBody'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: |-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
pattern: resources/[^/]+
- name: filename
description: The filename of the resource. Mainly used for downloading.
in: path
required: true
type: string
tags:
- ResourceService
definitions: definitions:
MemoServiceRebuildMemoPropertyBody: MemoServiceRebuildMemoPropertyBody:
type: object type: object
......
...@@ -35,8 +35,8 @@ service ResourceService { ...@@ -35,8 +35,8 @@ service ResourceService {
} }
// GetResourceBinary returns a resource binary by name. // GetResourceBinary returns a resource binary by name.
rpc GetResourceBinary(GetResourceBinaryRequest) returns (google.api.HttpBody) { rpc GetResourceBinary(GetResourceBinaryRequest) returns (google.api.HttpBody) {
option (google.api.http) = {get: "/file/{name=resources/*}"}; option (google.api.http) = {get: "/file/{name=resources/*}/{filename}"};
option (google.api.method_signature) = "name"; option (google.api.method_signature) = "name,filename";
} }
// UpdateResource updates a resource. // UpdateResource updates a resource.
rpc UpdateResource(UpdateResourceRequest) returns (Resource) { rpc UpdateResource(UpdateResourceRequest) returns (Resource) {
...@@ -109,6 +109,9 @@ message GetResourceBinaryRequest { ...@@ -109,6 +109,9 @@ message GetResourceBinaryRequest {
// Format: resources/{id} // Format: resources/{id}
// id is the system generated unique identifier. // id is the system generated unique identifier.
string name = 1; string name = 1;
// The filename of the resource. Mainly used for downloading.
string filename = 2;
} }
message UpdateResourceRequest { message UpdateResourceRequest {
......
This diff is collapsed.
...@@ -184,6 +184,16 @@ func request_ResourceService_GetResourceBinary_0(ctx context.Context, marshaler ...@@ -184,6 +184,16 @@ func request_ResourceService_GetResourceBinary_0(ctx context.Context, marshaler
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err)
} }
val, ok = pathParams["filename"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "filename")
}
protoReq.Filename, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "filename", err)
}
msg, err := client.GetResourceBinary(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) msg, err := client.GetResourceBinary(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err return msg, metadata, err
...@@ -210,6 +220,16 @@ func local_request_ResourceService_GetResourceBinary_0(ctx context.Context, mars ...@@ -210,6 +220,16 @@ func local_request_ResourceService_GetResourceBinary_0(ctx context.Context, mars
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err)
} }
val, ok = pathParams["filename"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "filename")
}
protoReq.Filename, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "filename", err)
}
msg, err := server.GetResourceBinary(ctx, &protoReq) msg, err := server.GetResourceBinary(ctx, &protoReq)
return msg, metadata, err return msg, metadata, err
...@@ -481,7 +501,7 @@ func RegisterResourceServiceHandlerServer(ctx context.Context, mux *runtime.Serv ...@@ -481,7 +501,7 @@ func RegisterResourceServiceHandlerServer(ctx context.Context, mux *runtime.Serv
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error var err error
var annotatedContext context.Context var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResourceBinary", runtime.WithHTTPPathPattern("/file/{name=resources/*}")) annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResourceBinary", runtime.WithHTTPPathPattern("/file/{name=resources/*}/{filename}"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
...@@ -683,7 +703,7 @@ func RegisterResourceServiceHandlerClient(ctx context.Context, mux *runtime.Serv ...@@ -683,7 +703,7 @@ func RegisterResourceServiceHandlerClient(ctx context.Context, mux *runtime.Serv
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error var err error
var annotatedContext context.Context var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResourceBinary", runtime.WithHTTPPathPattern("/file/{name=resources/*}")) annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResourceBinary", runtime.WithHTTPPathPattern("/file/{name=resources/*}/{filename}"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
...@@ -755,7 +775,7 @@ var ( ...@@ -755,7 +775,7 @@ var (
pattern_ResourceService_GetResource_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "resources", "name"}, "")) pattern_ResourceService_GetResource_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "resources", "name"}, ""))
pattern_ResourceService_GetResourceBinary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 2, 5, 2}, []string{"file", "resources", "name"}, "")) pattern_ResourceService_GetResourceBinary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 2, 5, 2, 1, 0, 4, 1, 5, 3}, []string{"file", "resources", "name", "filename"}, ""))
pattern_ResourceService_UpdateResource_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "resources", "resource.name"}, "")) pattern_ResourceService_UpdateResource_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "resources", "resource.name"}, ""))
......
...@@ -129,7 +129,7 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st ...@@ -129,7 +129,7 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st
if resource.StorageType == storepb.ResourceStorageType_EXTERNAL || resource.StorageType == storepb.ResourceStorageType_S3 { if resource.StorageType == storepb.ResourceStorageType_EXTERNAL || resource.StorageType == storepb.ResourceStorageType_S3 {
enclosure.Url = resource.Reference enclosure.Url = resource.Reference
} else { } else {
enclosure.Url = fmt.Sprintf("%s/file/resources/%d", baseURL, resource.ID) enclosure.Url = fmt.Sprintf("%s/file/resources/%d/%s", baseURL, resource.ID, resource.Filename)
} }
enclosure.Length = strconv.Itoa(int(resource.Size)) enclosure.Length = strconv.Itoa(int(resource.Size))
enclosure.Type = resource.Type enclosure.Type = resource.Type
......
...@@ -5,7 +5,7 @@ export const getResourceUrl = (resource: Resource) => { ...@@ -5,7 +5,7 @@ export const getResourceUrl = (resource: Resource) => {
return resource.externalLink; return resource.externalLink;
} }
return `${window.location.origin}/file/${resource.name}`; return `${window.location.origin}/file/${resource.name}/${resource.filename}`;
}; };
export const getResourceType = (resource: Resource) => { export const getResourceType = (resource: Resource) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment