From bb5809cae452e3d7eb27fcab7d59e909a584a1ec Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 17 Jun 2025 22:15:19 +0800 Subject: [PATCH] refactor: attachment service --- proto/api/v1/attachment_service.proto | 173 +++++ proto/api/v1/memo_service.proto | 26 +- proto/api/v1/resource_service.proto | 113 --- proto/gen/api/v1/attachment_service.pb.go | 687 ++++++++++++++++++ proto/gen/api/v1/attachment_service.pb.gw.go | 615 ++++++++++++++++ .../gen/api/v1/attachment_service_grpc.pb.go | 325 +++++++++ proto/gen/api/v1/memo_service.pb.go | 190 ++--- proto/gen/api/v1/memo_service.pb.gw.go | 124 ++-- proto/gen/api/v1/memo_service_grpc.pb.go | 94 +-- proto/gen/api/v1/resource_service.pb.go | 578 --------------- proto/gen/api/v1/resource_service.pb.gw.go | 587 --------------- proto/gen/api/v1/resource_service_grpc.pb.go | 325 --------- proto/gen/apidocs.swagger.yaml | 594 ++++++++------- ...ource_service.go => attachment_service.go} | 166 +++-- ..._service.go => memo_attachment_service.go} | 24 +- server/router/api/v1/memo_service.go | 20 +- .../router/api/v1/memo_service_converter.go | 6 +- server/router/api/v1/resource_name.go | 8 +- server/router/api/v1/v1.go | 6 +- server/router/rss/rss.go | 2 +- server/server.go | 4 +- web/src/components/MemoAttachmentListView.tsx | 95 +++ .../EmbeddedContent/EmbeddedMemo.tsx | 4 +- .../EmbeddedContent/EmbeddedResource.tsx | 14 +- .../MemoContent/EmbeddedContent/index.tsx | 2 +- .../ActionButton/UploadResourceButton.tsx | 15 +- ...rceListView.tsx => AttachmentListView.tsx} | 38 +- web/src/components/MemoEditor/index.tsx | 65 +- .../components/MemoEditor/types/context.ts | 10 +- web/src/components/MemoResource.tsx | 8 +- web/src/components/MemoResourceListView.tsx | 95 --- web/src/components/MemoView.tsx | 4 +- web/src/components/Navigation.tsx | 10 +- web/src/components/ResourceIcon.tsx | 10 +- web/src/grpcweb.ts | 4 +- web/src/layouts/RootLayout.tsx | 4 +- web/src/locales/en.json | 3 +- .../pages/{Resources.tsx => Attachments.tsx} | 66 +- web/src/router/index.tsx | 8 +- web/src/store/v2/attachment.ts | 59 ++ web/src/store/v2/index.ts | 4 +- web/src/store/v2/resource.ts | 59 -- ...ource_service.ts => attachment_service.ts} | 612 ++++++++++------ web/src/types/proto/api/v1/memo_service.ts | 152 ++-- web/src/utils/attachment.ts | 45 ++ web/src/utils/resource.ts | 45 -- 46 files changed, 3330 insertions(+), 2768 deletions(-) create mode 100644 proto/api/v1/attachment_service.proto delete mode 100644 proto/api/v1/resource_service.proto create mode 100644 proto/gen/api/v1/attachment_service.pb.go create mode 100644 proto/gen/api/v1/attachment_service.pb.gw.go create mode 100644 proto/gen/api/v1/attachment_service_grpc.pb.go delete mode 100644 proto/gen/api/v1/resource_service.pb.go delete mode 100644 proto/gen/api/v1/resource_service.pb.gw.go delete mode 100644 proto/gen/api/v1/resource_service_grpc.pb.go rename server/router/api/v1/{resource_service.go => attachment_service.go} (71%) rename server/router/api/v1/{memo_resource_service.go => memo_attachment_service.go} (71%) create mode 100644 web/src/components/MemoAttachmentListView.tsx rename web/src/components/MemoEditor/{ResourceListView.tsx => AttachmentListView.tsx} (54%) delete mode 100644 web/src/components/MemoResourceListView.tsx rename web/src/pages/{Resources.tsx => Attachments.tsx} (74%) create mode 100644 web/src/store/v2/attachment.ts delete mode 100644 web/src/store/v2/resource.ts rename web/src/types/proto/api/v1/{resource_service.ts => attachment_service.ts} (51%) create mode 100644 web/src/utils/attachment.ts delete mode 100644 web/src/utils/resource.ts diff --git a/proto/api/v1/attachment_service.proto b/proto/api/v1/attachment_service.proto new file mode 100644 index 000000000..0ea313b2b --- /dev/null +++ b/proto/api/v1/attachment_service.proto @@ -0,0 +1,173 @@ +syntax = "proto3"; + +package memos.api.v1; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/httpbody.proto"; +import "google/api/resource.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "gen/api/v1"; + +service AttachmentService { + // CreateAttachment creates a new attachment. + rpc CreateAttachment(CreateAttachmentRequest) returns (Attachment) { + option (google.api.http) = { + post: "/api/v1/attachments" + body: "attachment" + }; + option (google.api.method_signature) = "attachment"; + } + // ListAttachments lists all attachments. + rpc ListAttachments(ListAttachmentsRequest) returns (ListAttachmentsResponse) { + option (google.api.http) = {get: "/api/v1/attachments"}; + } + // GetAttachment returns a attachment by name. + rpc GetAttachment(GetAttachmentRequest) returns (Attachment) { + option (google.api.http) = {get: "/api/v1/{name=attachments/*}"}; + option (google.api.method_signature) = "name"; + } + // GetAttachmentBinary returns a attachment binary by name. + rpc GetAttachmentBinary(GetAttachmentBinaryRequest) returns (google.api.HttpBody) { + option (google.api.http) = {get: "/file/{name=attachments/*}/{filename}"}; + option (google.api.method_signature) = "name,filename"; + } + // UpdateAttachment updates a attachment. + rpc UpdateAttachment(UpdateAttachmentRequest) returns (Attachment) { + option (google.api.http) = { + patch: "/api/v1/{attachment.name=attachments/*}" + body: "attachment" + }; + option (google.api.method_signature) = "attachment,update_mask"; + } + // DeleteAttachment deletes a attachment by name. + rpc DeleteAttachment(DeleteAttachmentRequest) returns (google.protobuf.Empty) { + option (google.api.http) = {delete: "/api/v1/{name=attachments/*}"}; + option (google.api.method_signature) = "name"; + } +} + +message Attachment { + option (google.api.resource) = { + type: "memos.api.v1/Attachment" + pattern: "attachments/{attachment}" + singular: "attachment" + plural: "attachments" + }; + + reserved 2; + + // The name of the attachment. + // Format: attachments/{attachment} + string name = 1 [(google.api.field_behavior) = IDENTIFIER]; + + // Output only. The creation timestamp. + google.protobuf.Timestamp create_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // The filename of the attachment. + string filename = 4 [(google.api.field_behavior) = REQUIRED]; + + // Input only. The content of the attachment. + bytes content = 5 [(google.api.field_behavior) = INPUT_ONLY]; + + // Optional. The external link of the attachment. + string external_link = 6 [(google.api.field_behavior) = OPTIONAL]; + + // The MIME type of the attachment. + string type = 7 [(google.api.field_behavior) = REQUIRED]; + + // Output only. The size of the attachment in bytes. + int64 size = 8 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Optional. The related memo. Refer to `Memo.name`. + // Format: memos/{memo} + optional string memo = 9 [(google.api.field_behavior) = OPTIONAL]; +} + +message CreateAttachmentRequest { + // Required. The attachment to create. + Attachment attachment = 1 [(google.api.field_behavior) = REQUIRED]; + + // Optional. The attachment ID to use for this attachment. + // If empty, a unique ID will be generated. + string attachment_id = 2 [(google.api.field_behavior) = OPTIONAL]; +} + +message ListAttachmentsRequest { + // Optional. The maximum number of attachments to return. + // The service may return fewer than this value. + // If unspecified, at most 50 attachments will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + int32 page_size = 1 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. A page token, received from a previous `ListAttachments` call. + // Provide this to retrieve the subsequent page. + string page_token = 2 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Filter to apply to the list results. + // Example: "type=image/png" or "filename:*.jpg" + // Supported operators: =, !=, <, <=, >, >=, : + // Supported fields: filename, type, size, create_time, memo + string filter = 3 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. The order to sort results by. + // Example: "create_time desc" or "filename asc" + string order_by = 4 [(google.api.field_behavior) = OPTIONAL]; +} + +message ListAttachmentsResponse { + // The list of attachments. + repeated Attachment attachments = 1; + + // A token that can be sent as `page_token` to retrieve the next page. + // If this field is omitted, there are no subsequent pages. + string next_page_token = 2; + + // The total count of attachments (may be approximate). + int32 total_size = 3; +} + +message GetAttachmentRequest { + // Required. The attachment name of the attachment to retrieve. + // Format: attachments/{attachment} + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = {type: "memos.api.v1/Attachment"} + ]; +} + +message GetAttachmentBinaryRequest { + // Required. The attachment name of the attachment. + // Format: attachments/{attachment} + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = {type: "memos.api.v1/Attachment"} + ]; + + // The filename of the attachment. Mainly used for downloading. + string filename = 2 [(google.api.field_behavior) = REQUIRED]; + + // Optional. A flag indicating if the thumbnail version of the attachment should be returned. + bool thumbnail = 3 [(google.api.field_behavior) = OPTIONAL]; +} + +message UpdateAttachmentRequest { + // Required. The attachment which replaces the attachment on the server. + Attachment attachment = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. The list of fields to update. + google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; +} + +message DeleteAttachmentRequest { + // Required. The attachment name of the attachment to delete. + // Format: attachments/{attachment} + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = {type: "memos.api.v1/Attachment"} + ]; +} diff --git a/proto/api/v1/memo_service.proto b/proto/api/v1/memo_service.proto index 5cca17fa0..a055def22 100644 --- a/proto/api/v1/memo_service.proto +++ b/proto/api/v1/memo_service.proto @@ -2,10 +2,10 @@ syntax = "proto3"; package memos.api.v1; +import "api/v1/attachment_service.proto"; import "api/v1/common.proto"; import "api/v1/markdown_service.proto"; import "api/v1/reaction_service.proto"; -import "api/v1/resource_service.proto"; import "google/api/annotations.proto"; import "google/api/client.proto"; import "google/api/field_behavior.proto"; @@ -59,17 +59,17 @@ service MemoService { rpc DeleteMemoTag(DeleteMemoTagRequest) returns (google.protobuf.Empty) { option (google.api.http) = {delete: "/api/v1/{parent=memos/*}/tags/{tag}"}; } - // SetMemoResources sets resources for a memo. - rpc SetMemoResources(SetMemoResourcesRequest) returns (google.protobuf.Empty) { + // SetMemoAttachments sets attachments for a memo. + rpc SetMemoAttachments(SetMemoAttachmentsRequest) returns (google.protobuf.Empty) { option (google.api.http) = { - patch: "/api/v1/{name=memos/*}/resources" + patch: "/api/v1/{name=memos/*}/attachments" body: "*" }; option (google.api.method_signature) = "name"; } - // ListMemoResources lists resources for a memo. - rpc ListMemoResources(ListMemoResourcesRequest) returns (ListMemoResourcesResponse) { - option (google.api.http) = {get: "/api/v1/{name=memos/*}/resources"}; + // ListMemoAttachments lists attachments for a memo. + rpc ListMemoAttachments(ListMemoAttachmentsRequest) returns (ListMemoAttachmentsResponse) { + option (google.api.http) = {get: "/api/v1/{name=memos/*}/attachments"}; option (google.api.method_signature) = "name"; } // SetMemoRelations sets relations for a memo. @@ -157,7 +157,7 @@ message Memo { bool pinned = 12; - repeated Resource resources = 14; + repeated Attachment attachments = 14; repeated MemoRelation relations = 15; @@ -269,20 +269,20 @@ message DeleteMemoTagRequest { bool delete_related_memos = 3; } -message SetMemoResourcesRequest { +message SetMemoAttachmentsRequest { // The name of the memo. string name = 1; - repeated Resource resources = 2; + repeated Attachment attachments = 2; } -message ListMemoResourcesRequest { +message ListMemoAttachmentsRequest { // The name of the memo. string name = 1; } -message ListMemoResourcesResponse { - repeated Resource resources = 1; +message ListMemoAttachmentsResponse { + repeated Attachment attachments = 1; } message MemoRelation { diff --git a/proto/api/v1/resource_service.proto b/proto/api/v1/resource_service.proto deleted file mode 100644 index 9a4dcdd0e..000000000 --- a/proto/api/v1/resource_service.proto +++ /dev/null @@ -1,113 +0,0 @@ -syntax = "proto3"; - -package memos.api.v1; - -import "google/api/annotations.proto"; -import "google/api/client.proto"; -import "google/api/field_behavior.proto"; -import "google/api/httpbody.proto"; -import "google/protobuf/empty.proto"; -import "google/protobuf/field_mask.proto"; -import "google/protobuf/timestamp.proto"; - -option go_package = "gen/api/v1"; - -service ResourceService { - // CreateResource creates a new resource. - rpc CreateResource(CreateResourceRequest) returns (Resource) { - option (google.api.http) = { - post: "/api/v1/resources" - body: "resource" - }; - } - // ListResources lists all resources. - rpc ListResources(ListResourcesRequest) returns (ListResourcesResponse) { - option (google.api.http) = {get: "/api/v1/resources"}; - } - // GetResource returns a resource by name. - rpc GetResource(GetResourceRequest) returns (Resource) { - option (google.api.http) = {get: "/api/v1/{name=resources/*}"}; - option (google.api.method_signature) = "name"; - } - // GetResourceBinary returns a resource binary by name. - rpc GetResourceBinary(GetResourceBinaryRequest) returns (google.api.HttpBody) { - option (google.api.http) = {get: "/file/{name=resources/*}/{filename}"}; - option (google.api.method_signature) = "name,filename"; - } - // UpdateResource updates a resource. - rpc UpdateResource(UpdateResourceRequest) returns (Resource) { - option (google.api.http) = { - patch: "/api/v1/{resource.name=resources/*}" - body: "resource" - }; - option (google.api.method_signature) = "resource,update_mask"; - } - // DeleteResource deletes a resource by name. - rpc DeleteResource(DeleteResourceRequest) returns (google.protobuf.Empty) { - option (google.api.http) = {delete: "/api/v1/{name=resources/*}"}; - option (google.api.method_signature) = "name"; - } -} - -message Resource { - reserved 2; - - // The name of the resource. - // Format: resources/{resource}, resource is the user defined if or uuid. - string name = 1 [ - (google.api.field_behavior) = OUTPUT_ONLY, - (google.api.field_behavior) = IDENTIFIER - ]; - - google.protobuf.Timestamp create_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY]; - - string filename = 4; - - bytes content = 5 [(google.api.field_behavior) = INPUT_ONLY]; - - string external_link = 6; - - string type = 7; - - int64 size = 8; - - // The related memo. Refer to `Memo.name`. - optional string memo = 9; -} - -message CreateResourceRequest { - Resource resource = 1; -} - -message ListResourcesRequest {} - -message ListResourcesResponse { - repeated Resource resources = 1; -} - -message GetResourceRequest { - // The name of the resource. - string name = 1; -} - -message GetResourceBinaryRequest { - // The name of the resource. - string name = 1; - - // The filename of the resource. Mainly used for downloading. - string filename = 2; - - // A flag indicating if the thumbnail version of the resource should be returned - bool thumbnail = 3; -} - -message UpdateResourceRequest { - Resource resource = 1; - - google.protobuf.FieldMask update_mask = 2; -} - -message DeleteResourceRequest { - // The name of the resource. - string name = 1; -} diff --git a/proto/gen/api/v1/attachment_service.pb.go b/proto/gen/api/v1/attachment_service.pb.go new file mode 100644 index 000000000..c4c391c70 --- /dev/null +++ b/proto/gen/api/v1/attachment_service.pb.go @@ -0,0 +1,687 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.6 +// protoc (unknown) +// source: api/v1/attachment_service.proto + +package apiv1 + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + httpbody "google.golang.org/genproto/googleapis/api/httpbody" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Attachment struct { + state protoimpl.MessageState `protogen:"open.v1"` + // The name of the attachment. + // Format: attachments/{attachment} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Output only. The creation timestamp. + CreateTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` + // The filename of the attachment. + Filename string `protobuf:"bytes,4,opt,name=filename,proto3" json:"filename,omitempty"` + // Input only. The content of the attachment. + Content []byte `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"` + // Optional. The external link of the attachment. + ExternalLink string `protobuf:"bytes,6,opt,name=external_link,json=externalLink,proto3" json:"external_link,omitempty"` + // The MIME type of the attachment. + Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"` + // Output only. The size of the attachment in bytes. + Size int64 `protobuf:"varint,8,opt,name=size,proto3" json:"size,omitempty"` + // Optional. The related memo. Refer to `Memo.name`. + // Format: memos/{memo} + Memo *string `protobuf:"bytes,9,opt,name=memo,proto3,oneof" json:"memo,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Attachment) Reset() { + *x = Attachment{} + mi := &file_api_v1_attachment_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Attachment) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Attachment) ProtoMessage() {} + +func (x *Attachment) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Attachment.ProtoReflect.Descriptor instead. +func (*Attachment) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{0} +} + +func (x *Attachment) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Attachment) GetCreateTime() *timestamppb.Timestamp { + if x != nil { + return x.CreateTime + } + return nil +} + +func (x *Attachment) GetFilename() string { + if x != nil { + return x.Filename + } + return "" +} + +func (x *Attachment) GetContent() []byte { + if x != nil { + return x.Content + } + return nil +} + +func (x *Attachment) GetExternalLink() string { + if x != nil { + return x.ExternalLink + } + return "" +} + +func (x *Attachment) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *Attachment) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *Attachment) GetMemo() string { + if x != nil && x.Memo != nil { + return *x.Memo + } + return "" +} + +type CreateAttachmentRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The attachment to create. + Attachment *Attachment `protobuf:"bytes,1,opt,name=attachment,proto3" json:"attachment,omitempty"` + // Optional. The attachment ID to use for this attachment. + // If empty, a unique ID will be generated. + AttachmentId string `protobuf:"bytes,2,opt,name=attachment_id,json=attachmentId,proto3" json:"attachment_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CreateAttachmentRequest) Reset() { + *x = CreateAttachmentRequest{} + mi := &file_api_v1_attachment_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateAttachmentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateAttachmentRequest) ProtoMessage() {} + +func (x *CreateAttachmentRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateAttachmentRequest.ProtoReflect.Descriptor instead. +func (*CreateAttachmentRequest) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateAttachmentRequest) GetAttachment() *Attachment { + if x != nil { + return x.Attachment + } + return nil +} + +func (x *CreateAttachmentRequest) GetAttachmentId() string { + if x != nil { + return x.AttachmentId + } + return "" +} + +type ListAttachmentsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Optional. The maximum number of attachments to return. + // The service may return fewer than this value. + // If unspecified, at most 50 attachments will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + PageSize int32 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` + // Optional. A page token, received from a previous `ListAttachments` call. + // Provide this to retrieve the subsequent page. + PageToken string `protobuf:"bytes,2,opt,name=page_token,json=pageToken,proto3" json:"page_token,omitempty"` + // Optional. Filter to apply to the list results. + // Example: "type=image/png" or "filename:*.jpg" + // Supported operators: =, !=, <, <=, >, >=, : + // Supported fields: filename, type, size, create_time, memo + Filter string `protobuf:"bytes,3,opt,name=filter,proto3" json:"filter,omitempty"` + // Optional. The order to sort results by. + // Example: "create_time desc" or "filename asc" + OrderBy string `protobuf:"bytes,4,opt,name=order_by,json=orderBy,proto3" json:"order_by,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListAttachmentsRequest) Reset() { + *x = ListAttachmentsRequest{} + mi := &file_api_v1_attachment_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListAttachmentsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListAttachmentsRequest) ProtoMessage() {} + +func (x *ListAttachmentsRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListAttachmentsRequest.ProtoReflect.Descriptor instead. +func (*ListAttachmentsRequest) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{2} +} + +func (x *ListAttachmentsRequest) GetPageSize() int32 { + if x != nil { + return x.PageSize + } + return 0 +} + +func (x *ListAttachmentsRequest) GetPageToken() string { + if x != nil { + return x.PageToken + } + return "" +} + +func (x *ListAttachmentsRequest) GetFilter() string { + if x != nil { + return x.Filter + } + return "" +} + +func (x *ListAttachmentsRequest) GetOrderBy() string { + if x != nil { + return x.OrderBy + } + return "" +} + +type ListAttachmentsResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + // The list of attachments. + Attachments []*Attachment `protobuf:"bytes,1,rep,name=attachments,proto3" json:"attachments,omitempty"` + // A token that can be sent as `page_token` to retrieve the next page. + // If this field is omitted, there are no subsequent pages. + NextPageToken string `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3" json:"next_page_token,omitempty"` + // The total count of attachments (may be approximate). + TotalSize int32 `protobuf:"varint,3,opt,name=total_size,json=totalSize,proto3" json:"total_size,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListAttachmentsResponse) Reset() { + *x = ListAttachmentsResponse{} + mi := &file_api_v1_attachment_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListAttachmentsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListAttachmentsResponse) ProtoMessage() {} + +func (x *ListAttachmentsResponse) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListAttachmentsResponse.ProtoReflect.Descriptor instead. +func (*ListAttachmentsResponse) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{3} +} + +func (x *ListAttachmentsResponse) GetAttachments() []*Attachment { + if x != nil { + return x.Attachments + } + return nil +} + +func (x *ListAttachmentsResponse) GetNextPageToken() string { + if x != nil { + return x.NextPageToken + } + return "" +} + +func (x *ListAttachmentsResponse) GetTotalSize() int32 { + if x != nil { + return x.TotalSize + } + return 0 +} + +type GetAttachmentRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The attachment name of the attachment to retrieve. + // Format: attachments/{attachment} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetAttachmentRequest) Reset() { + *x = GetAttachmentRequest{} + mi := &file_api_v1_attachment_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetAttachmentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetAttachmentRequest) ProtoMessage() {} + +func (x *GetAttachmentRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetAttachmentRequest.ProtoReflect.Descriptor instead. +func (*GetAttachmentRequest) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{4} +} + +func (x *GetAttachmentRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type GetAttachmentBinaryRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The attachment name of the attachment. + // Format: attachments/{attachment} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The filename of the attachment. Mainly used for downloading. + Filename string `protobuf:"bytes,2,opt,name=filename,proto3" json:"filename,omitempty"` + // Optional. A flag indicating if the thumbnail version of the attachment should be returned. + Thumbnail bool `protobuf:"varint,3,opt,name=thumbnail,proto3" json:"thumbnail,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetAttachmentBinaryRequest) Reset() { + *x = GetAttachmentBinaryRequest{} + mi := &file_api_v1_attachment_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetAttachmentBinaryRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetAttachmentBinaryRequest) ProtoMessage() {} + +func (x *GetAttachmentBinaryRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetAttachmentBinaryRequest.ProtoReflect.Descriptor instead. +func (*GetAttachmentBinaryRequest) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{5} +} + +func (x *GetAttachmentBinaryRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *GetAttachmentBinaryRequest) GetFilename() string { + if x != nil { + return x.Filename + } + return "" +} + +func (x *GetAttachmentBinaryRequest) GetThumbnail() bool { + if x != nil { + return x.Thumbnail + } + return false +} + +type UpdateAttachmentRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The attachment which replaces the attachment on the server. + Attachment *Attachment `protobuf:"bytes,1,opt,name=attachment,proto3" json:"attachment,omitempty"` + // Required. The list of fields to update. + UpdateMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=update_mask,json=updateMask,proto3" json:"update_mask,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UpdateAttachmentRequest) Reset() { + *x = UpdateAttachmentRequest{} + mi := &file_api_v1_attachment_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UpdateAttachmentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateAttachmentRequest) ProtoMessage() {} + +func (x *UpdateAttachmentRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateAttachmentRequest.ProtoReflect.Descriptor instead. +func (*UpdateAttachmentRequest) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{6} +} + +func (x *UpdateAttachmentRequest) GetAttachment() *Attachment { + if x != nil { + return x.Attachment + } + return nil +} + +func (x *UpdateAttachmentRequest) GetUpdateMask() *fieldmaskpb.FieldMask { + if x != nil { + return x.UpdateMask + } + return nil +} + +type DeleteAttachmentRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Required. The attachment name of the attachment to delete. + // Format: attachments/{attachment} + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeleteAttachmentRequest) Reset() { + *x = DeleteAttachmentRequest{} + mi := &file_api_v1_attachment_service_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeleteAttachmentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteAttachmentRequest) ProtoMessage() {} + +func (x *DeleteAttachmentRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_v1_attachment_service_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeleteAttachmentRequest.ProtoReflect.Descriptor instead. +func (*DeleteAttachmentRequest) Descriptor() ([]byte, []int) { + return file_api_v1_attachment_service_proto_rawDescGZIP(), []int{7} +} + +func (x *DeleteAttachmentRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +var File_api_v1_attachment_service_proto protoreflect.FileDescriptor + +const file_api_v1_attachment_service_proto_rawDesc = "" + + "\n" + + "\x1fapi/v1/attachment_service.proto\x12\fmemos.api.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/httpbody.proto\x1a\x19google/api/resource.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\x81\x03\n" + + "\n" + + "Attachment\x12\x17\n" + + "\x04name\x18\x01 \x01(\tB\x03\xe0A\bR\x04name\x12@\n" + + "\vcreate_time\x18\x03 \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x03R\n" + + "createTime\x12\x1f\n" + + "\bfilename\x18\x04 \x01(\tB\x03\xe0A\x02R\bfilename\x12\x1d\n" + + "\acontent\x18\x05 \x01(\fB\x03\xe0A\x04R\acontent\x12(\n" + + "\rexternal_link\x18\x06 \x01(\tB\x03\xe0A\x01R\fexternalLink\x12\x17\n" + + "\x04type\x18\a \x01(\tB\x03\xe0A\x02R\x04type\x12\x17\n" + + "\x04size\x18\b \x01(\x03B\x03\xe0A\x03R\x04size\x12\x1c\n" + + "\x04memo\x18\t \x01(\tB\x03\xe0A\x01H\x00R\x04memo\x88\x01\x01:O\xeaAL\n" + + "\x17memos.api.v1/Attachment\x12\x18attachments/{attachment}*\vattachments2\n" + + "attachmentB\a\n" + + "\x05_memoJ\x04\b\x02\x10\x03\"\x82\x01\n" + + "\x17CreateAttachmentRequest\x12=\n" + + "\n" + + "attachment\x18\x01 \x01(\v2\x18.memos.api.v1.AttachmentB\x03\xe0A\x02R\n" + + "attachment\x12(\n" + + "\rattachment_id\x18\x02 \x01(\tB\x03\xe0A\x01R\fattachmentId\"\x9b\x01\n" + + "\x16ListAttachmentsRequest\x12 \n" + + "\tpage_size\x18\x01 \x01(\x05B\x03\xe0A\x01R\bpageSize\x12\"\n" + + "\n" + + "page_token\x18\x02 \x01(\tB\x03\xe0A\x01R\tpageToken\x12\x1b\n" + + "\x06filter\x18\x03 \x01(\tB\x03\xe0A\x01R\x06filter\x12\x1e\n" + + "\border_by\x18\x04 \x01(\tB\x03\xe0A\x01R\aorderBy\"\x9c\x01\n" + + "\x17ListAttachmentsResponse\x12:\n" + + "\vattachments\x18\x01 \x03(\v2\x18.memos.api.v1.AttachmentR\vattachments\x12&\n" + + "\x0fnext_page_token\x18\x02 \x01(\tR\rnextPageToken\x12\x1d\n" + + "\n" + + "total_size\x18\x03 \x01(\x05R\ttotalSize\"K\n" + + "\x14GetAttachmentRequest\x123\n" + + "\x04name\x18\x01 \x01(\tB\x1f\xe0A\x02\xfaA\x19\n" + + "\x17memos.api.v1/AttachmentR\x04name\"\x95\x01\n" + + "\x1aGetAttachmentBinaryRequest\x123\n" + + "\x04name\x18\x01 \x01(\tB\x1f\xe0A\x02\xfaA\x19\n" + + "\x17memos.api.v1/AttachmentR\x04name\x12\x1f\n" + + "\bfilename\x18\x02 \x01(\tB\x03\xe0A\x02R\bfilename\x12!\n" + + "\tthumbnail\x18\x03 \x01(\bB\x03\xe0A\x01R\tthumbnail\"\x9a\x01\n" + + "\x17UpdateAttachmentRequest\x12=\n" + + "\n" + + "attachment\x18\x01 \x01(\v2\x18.memos.api.v1.AttachmentB\x03\xe0A\x02R\n" + + "attachment\x12@\n" + + "\vupdate_mask\x18\x02 \x01(\v2\x1a.google.protobuf.FieldMaskB\x03\xe0A\x02R\n" + + "updateMask\"N\n" + + "\x17DeleteAttachmentRequest\x123\n" + + "\x04name\x18\x01 \x01(\tB\x1f\xe0A\x02\xfaA\x19\n" + + "\x17memos.api.v1/AttachmentR\x04name2\xdb\x06\n" + + "\x11AttachmentService\x12\x89\x01\n" + + "\x10CreateAttachment\x12%.memos.api.v1.CreateAttachmentRequest\x1a\x18.memos.api.v1.Attachment\"4\xdaA\n" + + "attachment\x82\xd3\xe4\x93\x02!:\n" + + "attachment\"\x13/api/v1/attachments\x12{\n" + + "\x0fListAttachments\x12$.memos.api.v1.ListAttachmentsRequest\x1a%.memos.api.v1.ListAttachmentsResponse\"\x1b\x82\xd3\xe4\x93\x02\x15\x12\x13/api/v1/attachments\x12z\n" + + "\rGetAttachment\x12\".memos.api.v1.GetAttachmentRequest\x1a\x18.memos.api.v1.Attachment\"+\xdaA\x04name\x82\xd3\xe4\x93\x02\x1e\x12\x1c/api/v1/{name=attachments/*}\x12\x94\x01\n" + + "\x13GetAttachmentBinary\x12(.memos.api.v1.GetAttachmentBinaryRequest\x1a\x14.google.api.HttpBody\"=\xdaA\rname,filename\x82\xd3\xe4\x93\x02'\x12%/file/{name=attachments/*}/{filename}\x12\xa9\x01\n" + + "\x10UpdateAttachment\x12%.memos.api.v1.UpdateAttachmentRequest\x1a\x18.memos.api.v1.Attachment\"T\xdaA\x16attachment,update_mask\x82\xd3\xe4\x93\x025:\n" + + "attachment2'/api/v1/{attachment.name=attachments/*}\x12~\n" + + "\x10DeleteAttachment\x12%.memos.api.v1.DeleteAttachmentRequest\x1a\x16.google.protobuf.Empty\"+\xdaA\x04name\x82\xd3\xe4\x93\x02\x1e*\x1c/api/v1/{name=attachments/*}B\xae\x01\n" + + "\x10com.memos.api.v1B\x16AttachmentServiceProtoP\x01Z0github.com/usememos/memos/proto/gen/api/v1;apiv1\xa2\x02\x03MAX\xaa\x02\fMemos.Api.V1\xca\x02\fMemos\\Api\\V1\xe2\x02\x18Memos\\Api\\V1\\GPBMetadata\xea\x02\x0eMemos::Api::V1b\x06proto3" + +var ( + file_api_v1_attachment_service_proto_rawDescOnce sync.Once + file_api_v1_attachment_service_proto_rawDescData []byte +) + +func file_api_v1_attachment_service_proto_rawDescGZIP() []byte { + file_api_v1_attachment_service_proto_rawDescOnce.Do(func() { + file_api_v1_attachment_service_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_api_v1_attachment_service_proto_rawDesc), len(file_api_v1_attachment_service_proto_rawDesc))) + }) + return file_api_v1_attachment_service_proto_rawDescData +} + +var file_api_v1_attachment_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_api_v1_attachment_service_proto_goTypes = []any{ + (*Attachment)(nil), // 0: memos.api.v1.Attachment + (*CreateAttachmentRequest)(nil), // 1: memos.api.v1.CreateAttachmentRequest + (*ListAttachmentsRequest)(nil), // 2: memos.api.v1.ListAttachmentsRequest + (*ListAttachmentsResponse)(nil), // 3: memos.api.v1.ListAttachmentsResponse + (*GetAttachmentRequest)(nil), // 4: memos.api.v1.GetAttachmentRequest + (*GetAttachmentBinaryRequest)(nil), // 5: memos.api.v1.GetAttachmentBinaryRequest + (*UpdateAttachmentRequest)(nil), // 6: memos.api.v1.UpdateAttachmentRequest + (*DeleteAttachmentRequest)(nil), // 7: memos.api.v1.DeleteAttachmentRequest + (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp + (*fieldmaskpb.FieldMask)(nil), // 9: google.protobuf.FieldMask + (*httpbody.HttpBody)(nil), // 10: google.api.HttpBody + (*emptypb.Empty)(nil), // 11: google.protobuf.Empty +} +var file_api_v1_attachment_service_proto_depIdxs = []int32{ + 8, // 0: memos.api.v1.Attachment.create_time:type_name -> google.protobuf.Timestamp + 0, // 1: memos.api.v1.CreateAttachmentRequest.attachment:type_name -> memos.api.v1.Attachment + 0, // 2: memos.api.v1.ListAttachmentsResponse.attachments:type_name -> memos.api.v1.Attachment + 0, // 3: memos.api.v1.UpdateAttachmentRequest.attachment:type_name -> memos.api.v1.Attachment + 9, // 4: memos.api.v1.UpdateAttachmentRequest.update_mask:type_name -> google.protobuf.FieldMask + 1, // 5: memos.api.v1.AttachmentService.CreateAttachment:input_type -> memos.api.v1.CreateAttachmentRequest + 2, // 6: memos.api.v1.AttachmentService.ListAttachments:input_type -> memos.api.v1.ListAttachmentsRequest + 4, // 7: memos.api.v1.AttachmentService.GetAttachment:input_type -> memos.api.v1.GetAttachmentRequest + 5, // 8: memos.api.v1.AttachmentService.GetAttachmentBinary:input_type -> memos.api.v1.GetAttachmentBinaryRequest + 6, // 9: memos.api.v1.AttachmentService.UpdateAttachment:input_type -> memos.api.v1.UpdateAttachmentRequest + 7, // 10: memos.api.v1.AttachmentService.DeleteAttachment:input_type -> memos.api.v1.DeleteAttachmentRequest + 0, // 11: memos.api.v1.AttachmentService.CreateAttachment:output_type -> memos.api.v1.Attachment + 3, // 12: memos.api.v1.AttachmentService.ListAttachments:output_type -> memos.api.v1.ListAttachmentsResponse + 0, // 13: memos.api.v1.AttachmentService.GetAttachment:output_type -> memos.api.v1.Attachment + 10, // 14: memos.api.v1.AttachmentService.GetAttachmentBinary:output_type -> google.api.HttpBody + 0, // 15: memos.api.v1.AttachmentService.UpdateAttachment:output_type -> memos.api.v1.Attachment + 11, // 16: memos.api.v1.AttachmentService.DeleteAttachment:output_type -> google.protobuf.Empty + 11, // [11:17] is the sub-list for method output_type + 5, // [5:11] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_api_v1_attachment_service_proto_init() } +func file_api_v1_attachment_service_proto_init() { + if File_api_v1_attachment_service_proto != nil { + return + } + file_api_v1_attachment_service_proto_msgTypes[0].OneofWrappers = []any{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_api_v1_attachment_service_proto_rawDesc), len(file_api_v1_attachment_service_proto_rawDesc)), + NumEnums: 0, + NumMessages: 8, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_api_v1_attachment_service_proto_goTypes, + DependencyIndexes: file_api_v1_attachment_service_proto_depIdxs, + MessageInfos: file_api_v1_attachment_service_proto_msgTypes, + }.Build() + File_api_v1_attachment_service_proto = out.File + file_api_v1_attachment_service_proto_goTypes = nil + file_api_v1_attachment_service_proto_depIdxs = nil +} diff --git a/proto/gen/api/v1/attachment_service.pb.gw.go b/proto/gen/api/v1/attachment_service.pb.gw.go new file mode 100644 index 000000000..c4e45204f --- /dev/null +++ b/proto/gen/api/v1/attachment_service.pb.gw.go @@ -0,0 +1,615 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: api/v1/attachment_service.proto + +/* +Package apiv1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package apiv1 + +import ( + "context" + "errors" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var ( + _ codes.Code + _ io.Reader + _ status.Status + _ = errors.New + _ = runtime.String + _ = utilities.NewDoubleArray + _ = metadata.Join +) + +var filter_AttachmentService_CreateAttachment_0 = &utilities.DoubleArray{Encoding: map[string]int{"attachment": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} + +func request_AttachmentService_CreateAttachment_0(ctx context.Context, marshaler runtime.Marshaler, client AttachmentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq CreateAttachmentRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Attachment); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_CreateAttachment_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.CreateAttachment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_AttachmentService_CreateAttachment_0(ctx context.Context, marshaler runtime.Marshaler, server AttachmentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq CreateAttachmentRequest + metadata runtime.ServerMetadata + ) + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Attachment); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_CreateAttachment_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.CreateAttachment(ctx, &protoReq) + return msg, metadata, err +} + +var filter_AttachmentService_ListAttachments_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + +func request_AttachmentService_ListAttachments_0(ctx context.Context, marshaler runtime.Marshaler, client AttachmentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq ListAttachmentsRequest + metadata runtime.ServerMetadata + ) + io.Copy(io.Discard, req.Body) + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_ListAttachments_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.ListAttachments(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_AttachmentService_ListAttachments_0(ctx context.Context, marshaler runtime.Marshaler, server AttachmentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq ListAttachmentsRequest + metadata runtime.ServerMetadata + ) + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_ListAttachments_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.ListAttachments(ctx, &protoReq) + return msg, metadata, err +} + +func request_AttachmentService_GetAttachment_0(ctx context.Context, marshaler runtime.Marshaler, client AttachmentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq GetAttachmentRequest + metadata runtime.ServerMetadata + err error + ) + io.Copy(io.Discard, req.Body) + val, ok := pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + msg, err := client.GetAttachment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_AttachmentService_GetAttachment_0(ctx context.Context, marshaler runtime.Marshaler, server AttachmentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq GetAttachmentRequest + metadata runtime.ServerMetadata + err error + ) + val, ok := pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + msg, err := server.GetAttachment(ctx, &protoReq) + return msg, metadata, err +} + +var filter_AttachmentService_GetAttachmentBinary_0 = &utilities.DoubleArray{Encoding: map[string]int{"name": 0, "filename": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} + +func request_AttachmentService_GetAttachmentBinary_0(ctx context.Context, marshaler runtime.Marshaler, client AttachmentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq GetAttachmentBinaryRequest + metadata runtime.ServerMetadata + err error + ) + io.Copy(io.Discard, req.Body) + val, ok := pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + protoReq.Name, err = runtime.String(val) + if err != nil { + 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) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_GetAttachmentBinary_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.GetAttachmentBinary(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_AttachmentService_GetAttachmentBinary_0(ctx context.Context, marshaler runtime.Marshaler, server AttachmentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq GetAttachmentBinaryRequest + metadata runtime.ServerMetadata + err error + ) + val, ok := pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + protoReq.Name, err = runtime.String(val) + if err != nil { + 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) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_GetAttachmentBinary_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.GetAttachmentBinary(ctx, &protoReq) + return msg, metadata, err +} + +var filter_AttachmentService_UpdateAttachment_0 = &utilities.DoubleArray{Encoding: map[string]int{"attachment": 0, "name": 1}, Base: []int{1, 2, 1, 0, 0}, Check: []int{0, 1, 2, 3, 2}} + +func request_AttachmentService_UpdateAttachment_0(ctx context.Context, marshaler runtime.Marshaler, client AttachmentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq UpdateAttachmentRequest + metadata runtime.ServerMetadata + err error + ) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Attachment); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 { + if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Attachment); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } else { + protoReq.UpdateMask = fieldMask + } + } + val, ok := pathParams["attachment.name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "attachment.name") + } + err = runtime.PopulateFieldFromPath(&protoReq, "attachment.name", val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "attachment.name", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_UpdateAttachment_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.UpdateAttachment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_AttachmentService_UpdateAttachment_0(ctx context.Context, marshaler runtime.Marshaler, server AttachmentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq UpdateAttachmentRequest + metadata runtime.ServerMetadata + err error + ) + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Attachment); err != nil && !errors.Is(err, io.EOF) { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 { + if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Attachment); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } else { + protoReq.UpdateMask = fieldMask + } + } + val, ok := pathParams["attachment.name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "attachment.name") + } + err = runtime.PopulateFieldFromPath(&protoReq, "attachment.name", val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "attachment.name", err) + } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_AttachmentService_UpdateAttachment_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.UpdateAttachment(ctx, &protoReq) + return msg, metadata, err +} + +func request_AttachmentService_DeleteAttachment_0(ctx context.Context, marshaler runtime.Marshaler, client AttachmentServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq DeleteAttachmentRequest + metadata runtime.ServerMetadata + err error + ) + io.Copy(io.Discard, req.Body) + val, ok := pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + msg, err := client.DeleteAttachment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err +} + +func local_request_AttachmentService_DeleteAttachment_0(ctx context.Context, marshaler runtime.Marshaler, server AttachmentServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var ( + protoReq DeleteAttachmentRequest + metadata runtime.ServerMetadata + err error + ) + val, ok := pathParams["name"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") + } + protoReq.Name, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) + } + msg, err := server.DeleteAttachment(ctx, &protoReq) + return msg, metadata, err +} + +// RegisterAttachmentServiceHandlerServer registers the http handlers for service AttachmentService to "mux". +// UnaryRPC :call AttachmentServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterAttachmentServiceHandlerFromEndpoint instead. +// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. +func RegisterAttachmentServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AttachmentServiceServer) error { + mux.Handle(http.MethodPost, pattern_AttachmentService_CreateAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.AttachmentService/CreateAttachment", runtime.WithHTTPPathPattern("/api/v1/attachments")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AttachmentService_CreateAttachment_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_CreateAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodGet, pattern_AttachmentService_ListAttachments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.AttachmentService/ListAttachments", runtime.WithHTTPPathPattern("/api/v1/attachments")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AttachmentService_ListAttachments_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_ListAttachments_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodGet, pattern_AttachmentService_GetAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.AttachmentService/GetAttachment", runtime.WithHTTPPathPattern("/api/v1/{name=attachments/*}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AttachmentService_GetAttachment_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_GetAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodGet, pattern_AttachmentService_GetAttachmentBinary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.AttachmentService/GetAttachmentBinary", runtime.WithHTTPPathPattern("/file/{name=attachments/*}/{filename}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AttachmentService_GetAttachmentBinary_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_GetAttachmentBinary_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPatch, pattern_AttachmentService_UpdateAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.AttachmentService/UpdateAttachment", runtime.WithHTTPPathPattern("/api/v1/{attachment.name=attachments/*}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AttachmentService_UpdateAttachment_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_UpdateAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodDelete, pattern_AttachmentService_DeleteAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.AttachmentService/DeleteAttachment", runtime.WithHTTPPathPattern("/api/v1/{name=attachments/*}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_AttachmentService_DeleteAttachment_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_DeleteAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + + return nil +} + +// RegisterAttachmentServiceHandlerFromEndpoint is same as RegisterAttachmentServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterAttachmentServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.NewClient(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + return RegisterAttachmentServiceHandler(ctx, mux, conn) +} + +// RegisterAttachmentServiceHandler registers the http handlers for service AttachmentService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterAttachmentServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterAttachmentServiceHandlerClient(ctx, mux, NewAttachmentServiceClient(conn)) +} + +// RegisterAttachmentServiceHandlerClient registers the http handlers for service AttachmentService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AttachmentServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AttachmentServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "AttachmentServiceClient" to call the correct interceptors. This client ignores the HTTP middlewares. +func RegisterAttachmentServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AttachmentServiceClient) error { + mux.Handle(http.MethodPost, pattern_AttachmentService_CreateAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.AttachmentService/CreateAttachment", runtime.WithHTTPPathPattern("/api/v1/attachments")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AttachmentService_CreateAttachment_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_CreateAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodGet, pattern_AttachmentService_ListAttachments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.AttachmentService/ListAttachments", runtime.WithHTTPPathPattern("/api/v1/attachments")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AttachmentService_ListAttachments_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_ListAttachments_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodGet, pattern_AttachmentService_GetAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.AttachmentService/GetAttachment", runtime.WithHTTPPathPattern("/api/v1/{name=attachments/*}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AttachmentService_GetAttachment_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_GetAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodGet, pattern_AttachmentService_GetAttachmentBinary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.AttachmentService/GetAttachmentBinary", runtime.WithHTTPPathPattern("/file/{name=attachments/*}/{filename}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AttachmentService_GetAttachmentBinary_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_GetAttachmentBinary_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodPatch, pattern_AttachmentService_UpdateAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.AttachmentService/UpdateAttachment", runtime.WithHTTPPathPattern("/api/v1/{attachment.name=attachments/*}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AttachmentService_UpdateAttachment_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_UpdateAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + mux.Handle(http.MethodDelete, pattern_AttachmentService_DeleteAttachment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.AttachmentService/DeleteAttachment", runtime.WithHTTPPathPattern("/api/v1/{name=attachments/*}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_AttachmentService_DeleteAttachment_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + forward_AttachmentService_DeleteAttachment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + }) + return nil +} + +var ( + pattern_AttachmentService_CreateAttachment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "attachments"}, "")) + pattern_AttachmentService_ListAttachments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "attachments"}, "")) + pattern_AttachmentService_GetAttachment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "attachments", "name"}, "")) + pattern_AttachmentService_GetAttachmentBinary_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", "attachments", "name", "filename"}, "")) + pattern_AttachmentService_UpdateAttachment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "attachments", "attachment.name"}, "")) + pattern_AttachmentService_DeleteAttachment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "attachments", "name"}, "")) +) + +var ( + forward_AttachmentService_CreateAttachment_0 = runtime.ForwardResponseMessage + forward_AttachmentService_ListAttachments_0 = runtime.ForwardResponseMessage + forward_AttachmentService_GetAttachment_0 = runtime.ForwardResponseMessage + forward_AttachmentService_GetAttachmentBinary_0 = runtime.ForwardResponseMessage + forward_AttachmentService_UpdateAttachment_0 = runtime.ForwardResponseMessage + forward_AttachmentService_DeleteAttachment_0 = runtime.ForwardResponseMessage +) diff --git a/proto/gen/api/v1/attachment_service_grpc.pb.go b/proto/gen/api/v1/attachment_service_grpc.pb.go new file mode 100644 index 000000000..fa07861a3 --- /dev/null +++ b/proto/gen/api/v1/attachment_service_grpc.pb.go @@ -0,0 +1,325 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: api/v1/attachment_service.proto + +package apiv1 + +import ( + context "context" + httpbody "google.golang.org/genproto/googleapis/api/httpbody" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + AttachmentService_CreateAttachment_FullMethodName = "/memos.api.v1.AttachmentService/CreateAttachment" + AttachmentService_ListAttachments_FullMethodName = "/memos.api.v1.AttachmentService/ListAttachments" + AttachmentService_GetAttachment_FullMethodName = "/memos.api.v1.AttachmentService/GetAttachment" + AttachmentService_GetAttachmentBinary_FullMethodName = "/memos.api.v1.AttachmentService/GetAttachmentBinary" + AttachmentService_UpdateAttachment_FullMethodName = "/memos.api.v1.AttachmentService/UpdateAttachment" + AttachmentService_DeleteAttachment_FullMethodName = "/memos.api.v1.AttachmentService/DeleteAttachment" +) + +// AttachmentServiceClient is the client API for AttachmentService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type AttachmentServiceClient interface { + // CreateAttachment creates a new attachment. + CreateAttachment(ctx context.Context, in *CreateAttachmentRequest, opts ...grpc.CallOption) (*Attachment, error) + // ListAttachments lists all attachments. + ListAttachments(ctx context.Context, in *ListAttachmentsRequest, opts ...grpc.CallOption) (*ListAttachmentsResponse, error) + // GetAttachment returns a attachment by name. + GetAttachment(ctx context.Context, in *GetAttachmentRequest, opts ...grpc.CallOption) (*Attachment, error) + // GetAttachmentBinary returns a attachment binary by name. + GetAttachmentBinary(ctx context.Context, in *GetAttachmentBinaryRequest, opts ...grpc.CallOption) (*httpbody.HttpBody, error) + // UpdateAttachment updates a attachment. + UpdateAttachment(ctx context.Context, in *UpdateAttachmentRequest, opts ...grpc.CallOption) (*Attachment, error) + // DeleteAttachment deletes a attachment by name. + DeleteAttachment(ctx context.Context, in *DeleteAttachmentRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) +} + +type attachmentServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewAttachmentServiceClient(cc grpc.ClientConnInterface) AttachmentServiceClient { + return &attachmentServiceClient{cc} +} + +func (c *attachmentServiceClient) CreateAttachment(ctx context.Context, in *CreateAttachmentRequest, opts ...grpc.CallOption) (*Attachment, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Attachment) + err := c.cc.Invoke(ctx, AttachmentService_CreateAttachment_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *attachmentServiceClient) ListAttachments(ctx context.Context, in *ListAttachmentsRequest, opts ...grpc.CallOption) (*ListAttachmentsResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ListAttachmentsResponse) + err := c.cc.Invoke(ctx, AttachmentService_ListAttachments_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *attachmentServiceClient) GetAttachment(ctx context.Context, in *GetAttachmentRequest, opts ...grpc.CallOption) (*Attachment, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Attachment) + err := c.cc.Invoke(ctx, AttachmentService_GetAttachment_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *attachmentServiceClient) GetAttachmentBinary(ctx context.Context, in *GetAttachmentBinaryRequest, opts ...grpc.CallOption) (*httpbody.HttpBody, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(httpbody.HttpBody) + err := c.cc.Invoke(ctx, AttachmentService_GetAttachmentBinary_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *attachmentServiceClient) UpdateAttachment(ctx context.Context, in *UpdateAttachmentRequest, opts ...grpc.CallOption) (*Attachment, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Attachment) + err := c.cc.Invoke(ctx, AttachmentService_UpdateAttachment_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *attachmentServiceClient) DeleteAttachment(ctx context.Context, in *DeleteAttachmentRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, AttachmentService_DeleteAttachment_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AttachmentServiceServer is the server API for AttachmentService service. +// All implementations must embed UnimplementedAttachmentServiceServer +// for forward compatibility. +type AttachmentServiceServer interface { + // CreateAttachment creates a new attachment. + CreateAttachment(context.Context, *CreateAttachmentRequest) (*Attachment, error) + // ListAttachments lists all attachments. + ListAttachments(context.Context, *ListAttachmentsRequest) (*ListAttachmentsResponse, error) + // GetAttachment returns a attachment by name. + GetAttachment(context.Context, *GetAttachmentRequest) (*Attachment, error) + // GetAttachmentBinary returns a attachment binary by name. + GetAttachmentBinary(context.Context, *GetAttachmentBinaryRequest) (*httpbody.HttpBody, error) + // UpdateAttachment updates a attachment. + UpdateAttachment(context.Context, *UpdateAttachmentRequest) (*Attachment, error) + // DeleteAttachment deletes a attachment by name. + DeleteAttachment(context.Context, *DeleteAttachmentRequest) (*emptypb.Empty, error) + mustEmbedUnimplementedAttachmentServiceServer() +} + +// UnimplementedAttachmentServiceServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedAttachmentServiceServer struct{} + +func (UnimplementedAttachmentServiceServer) CreateAttachment(context.Context, *CreateAttachmentRequest) (*Attachment, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateAttachment not implemented") +} +func (UnimplementedAttachmentServiceServer) ListAttachments(context.Context, *ListAttachmentsRequest) (*ListAttachmentsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListAttachments not implemented") +} +func (UnimplementedAttachmentServiceServer) GetAttachment(context.Context, *GetAttachmentRequest) (*Attachment, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetAttachment not implemented") +} +func (UnimplementedAttachmentServiceServer) GetAttachmentBinary(context.Context, *GetAttachmentBinaryRequest) (*httpbody.HttpBody, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetAttachmentBinary not implemented") +} +func (UnimplementedAttachmentServiceServer) UpdateAttachment(context.Context, *UpdateAttachmentRequest) (*Attachment, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateAttachment not implemented") +} +func (UnimplementedAttachmentServiceServer) DeleteAttachment(context.Context, *DeleteAttachmentRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeleteAttachment not implemented") +} +func (UnimplementedAttachmentServiceServer) mustEmbedUnimplementedAttachmentServiceServer() {} +func (UnimplementedAttachmentServiceServer) testEmbeddedByValue() {} + +// UnsafeAttachmentServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to AttachmentServiceServer will +// result in compilation errors. +type UnsafeAttachmentServiceServer interface { + mustEmbedUnimplementedAttachmentServiceServer() +} + +func RegisterAttachmentServiceServer(s grpc.ServiceRegistrar, srv AttachmentServiceServer) { + // If the following call pancis, it indicates UnimplementedAttachmentServiceServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&AttachmentService_ServiceDesc, srv) +} + +func _AttachmentService_CreateAttachment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateAttachmentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AttachmentServiceServer).CreateAttachment(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AttachmentService_CreateAttachment_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AttachmentServiceServer).CreateAttachment(ctx, req.(*CreateAttachmentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AttachmentService_ListAttachments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListAttachmentsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AttachmentServiceServer).ListAttachments(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AttachmentService_ListAttachments_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AttachmentServiceServer).ListAttachments(ctx, req.(*ListAttachmentsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AttachmentService_GetAttachment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetAttachmentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AttachmentServiceServer).GetAttachment(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AttachmentService_GetAttachment_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AttachmentServiceServer).GetAttachment(ctx, req.(*GetAttachmentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AttachmentService_GetAttachmentBinary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetAttachmentBinaryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AttachmentServiceServer).GetAttachmentBinary(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AttachmentService_GetAttachmentBinary_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AttachmentServiceServer).GetAttachmentBinary(ctx, req.(*GetAttachmentBinaryRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AttachmentService_UpdateAttachment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateAttachmentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AttachmentServiceServer).UpdateAttachment(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AttachmentService_UpdateAttachment_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AttachmentServiceServer).UpdateAttachment(ctx, req.(*UpdateAttachmentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _AttachmentService_DeleteAttachment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteAttachmentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AttachmentServiceServer).DeleteAttachment(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: AttachmentService_DeleteAttachment_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AttachmentServiceServer).DeleteAttachment(ctx, req.(*DeleteAttachmentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// AttachmentService_ServiceDesc is the grpc.ServiceDesc for AttachmentService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var AttachmentService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "memos.api.v1.AttachmentService", + HandlerType: (*AttachmentServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateAttachment", + Handler: _AttachmentService_CreateAttachment_Handler, + }, + { + MethodName: "ListAttachments", + Handler: _AttachmentService_ListAttachments_Handler, + }, + { + MethodName: "GetAttachment", + Handler: _AttachmentService_GetAttachment_Handler, + }, + { + MethodName: "GetAttachmentBinary", + Handler: _AttachmentService_GetAttachmentBinary_Handler, + }, + { + MethodName: "UpdateAttachment", + Handler: _AttachmentService_UpdateAttachment_Handler, + }, + { + MethodName: "DeleteAttachment", + Handler: _AttachmentService_DeleteAttachment_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "api/v1/attachment_service.proto", +} diff --git a/proto/gen/api/v1/memo_service.pb.go b/proto/gen/api/v1/memo_service.pb.go index fef0fdebb..a4731ca58 100644 --- a/proto/gen/api/v1/memo_service.pb.go +++ b/proto/gen/api/v1/memo_service.pb.go @@ -143,7 +143,7 @@ type Memo struct { Visibility Visibility `protobuf:"varint,10,opt,name=visibility,proto3,enum=memos.api.v1.Visibility" json:"visibility,omitempty"` Tags []string `protobuf:"bytes,11,rep,name=tags,proto3" json:"tags,omitempty"` Pinned bool `protobuf:"varint,12,opt,name=pinned,proto3" json:"pinned,omitempty"` - Resources []*Resource `protobuf:"bytes,14,rep,name=resources,proto3" json:"resources,omitempty"` + Attachments []*Attachment `protobuf:"bytes,14,rep,name=attachments,proto3" json:"attachments,omitempty"` Relations []*MemoRelation `protobuf:"bytes,15,rep,name=relations,proto3" json:"relations,omitempty"` Reactions []*Reaction `protobuf:"bytes,16,rep,name=reactions,proto3" json:"reactions,omitempty"` Property *Memo_Property `protobuf:"bytes,17,opt,name=property,proto3" json:"property,omitempty"` @@ -265,9 +265,9 @@ func (x *Memo) GetPinned() bool { return false } -func (x *Memo) GetResources() []*Resource { +func (x *Memo) GetAttachments() []*Attachment { if x != nil { - return x.Resources + return x.Attachments } return nil } @@ -856,29 +856,29 @@ func (x *DeleteMemoTagRequest) GetDeleteRelatedMemos() bool { return false } -type SetMemoResourcesRequest struct { +type SetMemoAttachmentsRequest struct { state protoimpl.MessageState `protogen:"open.v1"` // The name of the memo. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Resources []*Resource `protobuf:"bytes,2,rep,name=resources,proto3" json:"resources,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Attachments []*Attachment `protobuf:"bytes,2,rep,name=attachments,proto3" json:"attachments,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *SetMemoResourcesRequest) Reset() { - *x = SetMemoResourcesRequest{} +func (x *SetMemoAttachmentsRequest) Reset() { + *x = SetMemoAttachmentsRequest{} mi := &file_api_v1_memo_service_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *SetMemoResourcesRequest) String() string { +func (x *SetMemoAttachmentsRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*SetMemoResourcesRequest) ProtoMessage() {} +func (*SetMemoAttachmentsRequest) ProtoMessage() {} -func (x *SetMemoResourcesRequest) ProtoReflect() protoreflect.Message { +func (x *SetMemoAttachmentsRequest) ProtoReflect() protoreflect.Message { mi := &file_api_v1_memo_service_proto_msgTypes[10] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -890,26 +890,26 @@ func (x *SetMemoResourcesRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use SetMemoResourcesRequest.ProtoReflect.Descriptor instead. -func (*SetMemoResourcesRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use SetMemoAttachmentsRequest.ProtoReflect.Descriptor instead. +func (*SetMemoAttachmentsRequest) Descriptor() ([]byte, []int) { return file_api_v1_memo_service_proto_rawDescGZIP(), []int{10} } -func (x *SetMemoResourcesRequest) GetName() string { +func (x *SetMemoAttachmentsRequest) GetName() string { if x != nil { return x.Name } return "" } -func (x *SetMemoResourcesRequest) GetResources() []*Resource { +func (x *SetMemoAttachmentsRequest) GetAttachments() []*Attachment { if x != nil { - return x.Resources + return x.Attachments } return nil } -type ListMemoResourcesRequest struct { +type ListMemoAttachmentsRequest struct { state protoimpl.MessageState `protogen:"open.v1"` // The name of the memo. Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -917,20 +917,20 @@ type ListMemoResourcesRequest struct { sizeCache protoimpl.SizeCache } -func (x *ListMemoResourcesRequest) Reset() { - *x = ListMemoResourcesRequest{} +func (x *ListMemoAttachmentsRequest) Reset() { + *x = ListMemoAttachmentsRequest{} mi := &file_api_v1_memo_service_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *ListMemoResourcesRequest) String() string { +func (x *ListMemoAttachmentsRequest) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ListMemoResourcesRequest) ProtoMessage() {} +func (*ListMemoAttachmentsRequest) ProtoMessage() {} -func (x *ListMemoResourcesRequest) ProtoReflect() protoreflect.Message { +func (x *ListMemoAttachmentsRequest) ProtoReflect() protoreflect.Message { mi := &file_api_v1_memo_service_proto_msgTypes[11] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -942,39 +942,39 @@ func (x *ListMemoResourcesRequest) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ListMemoResourcesRequest.ProtoReflect.Descriptor instead. -func (*ListMemoResourcesRequest) Descriptor() ([]byte, []int) { +// Deprecated: Use ListMemoAttachmentsRequest.ProtoReflect.Descriptor instead. +func (*ListMemoAttachmentsRequest) Descriptor() ([]byte, []int) { return file_api_v1_memo_service_proto_rawDescGZIP(), []int{11} } -func (x *ListMemoResourcesRequest) GetName() string { +func (x *ListMemoAttachmentsRequest) GetName() string { if x != nil { return x.Name } return "" } -type ListMemoResourcesResponse struct { +type ListMemoAttachmentsResponse struct { state protoimpl.MessageState `protogen:"open.v1"` - Resources []*Resource `protobuf:"bytes,1,rep,name=resources,proto3" json:"resources,omitempty"` + Attachments []*Attachment `protobuf:"bytes,1,rep,name=attachments,proto3" json:"attachments,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } -func (x *ListMemoResourcesResponse) Reset() { - *x = ListMemoResourcesResponse{} +func (x *ListMemoAttachmentsResponse) Reset() { + *x = ListMemoAttachmentsResponse{} mi := &file_api_v1_memo_service_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } -func (x *ListMemoResourcesResponse) String() string { +func (x *ListMemoAttachmentsResponse) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ListMemoResourcesResponse) ProtoMessage() {} +func (*ListMemoAttachmentsResponse) ProtoMessage() {} -func (x *ListMemoResourcesResponse) ProtoReflect() protoreflect.Message { +func (x *ListMemoAttachmentsResponse) ProtoReflect() protoreflect.Message { mi := &file_api_v1_memo_service_proto_msgTypes[12] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -986,14 +986,14 @@ func (x *ListMemoResourcesResponse) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ListMemoResourcesResponse.ProtoReflect.Descriptor instead. -func (*ListMemoResourcesResponse) Descriptor() ([]byte, []int) { +// Deprecated: Use ListMemoAttachmentsResponse.ProtoReflect.Descriptor instead. +func (*ListMemoAttachmentsResponse) Descriptor() ([]byte, []int) { return file_api_v1_memo_service_proto_rawDescGZIP(), []int{12} } -func (x *ListMemoResourcesResponse) GetResources() []*Resource { +func (x *ListMemoAttachmentsResponse) GetAttachments() []*Attachment { if x != nil { - return x.Resources + return x.Attachments } return nil } @@ -1666,7 +1666,7 @@ var File_api_v1_memo_service_proto protoreflect.FileDescriptor const file_api_v1_memo_service_proto_rawDesc = "" + "\n" + - "\x19api/v1/memo_service.proto\x12\fmemos.api.v1\x1a\x13api/v1/common.proto\x1a\x1dapi/v1/markdown_service.proto\x1a\x1dapi/v1/reaction_service.proto\x1a\x1dapi/v1/resource_service.proto\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xee\a\n" + + "\x19api/v1/memo_service.proto\x12\fmemos.api.v1\x1a\x1fapi/v1/attachment_service.proto\x1a\x13api/v1/common.proto\x1a\x1dapi/v1/markdown_service.proto\x1a\x1dapi/v1/reaction_service.proto\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\xf4\a\n" + "\x04Memo\x12\x1a\n" + "\x04name\x18\x01 \x01(\tB\x06\xe0A\x03\xe0A\bR\x04name\x12)\n" + "\x05state\x18\x03 \x01(\x0e2\x13.memos.api.v1.StateR\x05state\x12\x18\n" + @@ -1683,8 +1683,8 @@ const file_api_v1_memo_service_proto_rawDesc = "" + " \x01(\x0e2\x18.memos.api.v1.VisibilityR\n" + "visibility\x12\x17\n" + "\x04tags\x18\v \x03(\tB\x03\xe0A\x03R\x04tags\x12\x16\n" + - "\x06pinned\x18\f \x01(\bR\x06pinned\x124\n" + - "\tresources\x18\x0e \x03(\v2\x16.memos.api.v1.ResourceR\tresources\x128\n" + + "\x06pinned\x18\f \x01(\bR\x06pinned\x12:\n" + + "\vattachments\x18\x0e \x03(\v2\x18.memos.api.v1.AttachmentR\vattachments\x128\n" + "\trelations\x18\x0f \x03(\v2\x1a.memos.api.v1.MemoRelationR\trelations\x129\n" + "\treactions\x18\x10 \x03(\v2\x16.memos.api.v1.ReactionB\x03\xe0A\x03R\treactions\x12<\n" + "\bproperty\x18\x11 \x01(\v2\x1b.memos.api.v1.Memo.PropertyB\x03\xe0A\x03R\bproperty\x12 \n" + @@ -1733,14 +1733,14 @@ const file_api_v1_memo_service_proto_rawDesc = "" + "\x14DeleteMemoTagRequest\x12\x16\n" + "\x06parent\x18\x01 \x01(\tR\x06parent\x12\x10\n" + "\x03tag\x18\x02 \x01(\tR\x03tag\x120\n" + - "\x14delete_related_memos\x18\x03 \x01(\bR\x12deleteRelatedMemos\"c\n" + - "\x17SetMemoResourcesRequest\x12\x12\n" + - "\x04name\x18\x01 \x01(\tR\x04name\x124\n" + - "\tresources\x18\x02 \x03(\v2\x16.memos.api.v1.ResourceR\tresources\".\n" + - "\x18ListMemoResourcesRequest\x12\x12\n" + - "\x04name\x18\x01 \x01(\tR\x04name\"Q\n" + - "\x19ListMemoResourcesResponse\x124\n" + - "\tresources\x18\x01 \x03(\v2\x16.memos.api.v1.ResourceR\tresources\"\xc3\x02\n" + + "\x14delete_related_memos\x18\x03 \x01(\bR\x12deleteRelatedMemos\"k\n" + + "\x19SetMemoAttachmentsRequest\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12:\n" + + "\vattachments\x18\x02 \x03(\v2\x18.memos.api.v1.AttachmentR\vattachments\"0\n" + + "\x1aListMemoAttachmentsRequest\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\"Y\n" + + "\x1bListMemoAttachmentsResponse\x12:\n" + + "\vattachments\x18\x01 \x03(\v2\x18.memos.api.v1.AttachmentR\vattachments\"\xc3\x02\n" + "\fMemoRelation\x123\n" + "\x04memo\x18\x01 \x01(\v2\x1f.memos.api.v1.MemoRelation.MemoR\x04memo\x12B\n" + "\frelated_memo\x18\x02 \x01(\v2\x1f.memos.api.v1.MemoRelation.MemoR\vrelatedMemo\x123\n" + @@ -1782,7 +1782,7 @@ const file_api_v1_memo_service_proto_rawDesc = "" + "\aPRIVATE\x10\x01\x12\r\n" + "\tPROTECTED\x10\x02\x12\n" + "\n" + - "\x06PUBLIC\x10\x032\xbf\x10\n" + + "\x06PUBLIC\x10\x032\xcd\x10\n" + "\vMemoService\x12^\n" + "\n" + "CreateMemo\x12\x1f.memos.api.v1.CreateMemoRequest\x1a\x12.memos.api.v1.Memo\"\x1b\x82\xd3\xe4\x93\x02\x15:\x04memo\"\r/api/v1/memos\x12\x85\x01\n" + @@ -1793,9 +1793,9 @@ const file_api_v1_memo_service_proto_rawDesc = "" + "\n" + "DeleteMemo\x12\x1f.memos.api.v1.DeleteMemoRequest\x1a\x16.google.protobuf.Empty\"%\xdaA\x04name\x82\xd3\xe4\x93\x02\x18*\x16/api/v1/{name=memos/*}\x12|\n" + "\rRenameMemoTag\x12\".memos.api.v1.RenameMemoTagRequest\x1a\x16.google.protobuf.Empty\"/\x82\xd3\xe4\x93\x02):\x01*2$/api/v1/{parent=memos/*}/tags:rename\x12x\n" + - "\rDeleteMemoTag\x12\".memos.api.v1.DeleteMemoTagRequest\x1a\x16.google.protobuf.Empty\"+\x82\xd3\xe4\x93\x02%*#/api/v1/{parent=memos/*}/tags/{tag}\x12\x85\x01\n" + - "\x10SetMemoResources\x12%.memos.api.v1.SetMemoResourcesRequest\x1a\x16.google.protobuf.Empty\"2\xdaA\x04name\x82\xd3\xe4\x93\x02%:\x01*2 /api/v1/{name=memos/*}/resources\x12\x95\x01\n" + - "\x11ListMemoResources\x12&.memos.api.v1.ListMemoResourcesRequest\x1a'.memos.api.v1.ListMemoResourcesResponse\"/\xdaA\x04name\x82\xd3\xe4\x93\x02\"\x12 /api/v1/{name=memos/*}/resources\x12\x85\x01\n" + + "\rDeleteMemoTag\x12\".memos.api.v1.DeleteMemoTagRequest\x1a\x16.google.protobuf.Empty\"+\x82\xd3\xe4\x93\x02%*#/api/v1/{parent=memos/*}/tags/{tag}\x12\x8b\x01\n" + + "\x12SetMemoAttachments\x12'.memos.api.v1.SetMemoAttachmentsRequest\x1a\x16.google.protobuf.Empty\"4\xdaA\x04name\x82\xd3\xe4\x93\x02':\x01*2\"/api/v1/{name=memos/*}/attachments\x12\x9d\x01\n" + + "\x13ListMemoAttachments\x12(.memos.api.v1.ListMemoAttachmentsRequest\x1a).memos.api.v1.ListMemoAttachmentsResponse\"1\xdaA\x04name\x82\xd3\xe4\x93\x02$\x12\"/api/v1/{name=memos/*}/attachments\x12\x85\x01\n" + "\x10SetMemoRelations\x12%.memos.api.v1.SetMemoRelationsRequest\x1a\x16.google.protobuf.Empty\"2\xdaA\x04name\x82\xd3\xe4\x93\x02%:\x01*2 /api/v1/{name=memos/*}/relations\x12\x95\x01\n" + "\x11ListMemoRelations\x12&.memos.api.v1.ListMemoRelationsRequest\x1a'.memos.api.v1.ListMemoRelationsResponse\"/\xdaA\x04name\x82\xd3\xe4\x93\x02\"\x12 /api/v1/{name=memos/*}/relations\x12\x88\x01\n" + "\x11CreateMemoComment\x12&.memos.api.v1.CreateMemoCommentRequest\x1a\x12.memos.api.v1.Memo\"7\xdaA\x04name\x82\xd3\xe4\x93\x02*:\acomment\"\x1f/api/v1/{name=memos/*}/comments\x12\x91\x01\n" + @@ -1820,42 +1820,42 @@ func file_api_v1_memo_service_proto_rawDescGZIP() []byte { var file_api_v1_memo_service_proto_enumTypes = make([]protoimpl.EnumInfo, 2) var file_api_v1_memo_service_proto_msgTypes = make([]protoimpl.MessageInfo, 26) var file_api_v1_memo_service_proto_goTypes = []any{ - (Visibility)(0), // 0: memos.api.v1.Visibility - (MemoRelation_Type)(0), // 1: memos.api.v1.MemoRelation.Type - (*Memo)(nil), // 2: memos.api.v1.Memo - (*Location)(nil), // 3: memos.api.v1.Location - (*CreateMemoRequest)(nil), // 4: memos.api.v1.CreateMemoRequest - (*ListMemosRequest)(nil), // 5: memos.api.v1.ListMemosRequest - (*ListMemosResponse)(nil), // 6: memos.api.v1.ListMemosResponse - (*GetMemoRequest)(nil), // 7: memos.api.v1.GetMemoRequest - (*UpdateMemoRequest)(nil), // 8: memos.api.v1.UpdateMemoRequest - (*DeleteMemoRequest)(nil), // 9: memos.api.v1.DeleteMemoRequest - (*RenameMemoTagRequest)(nil), // 10: memos.api.v1.RenameMemoTagRequest - (*DeleteMemoTagRequest)(nil), // 11: memos.api.v1.DeleteMemoTagRequest - (*SetMemoResourcesRequest)(nil), // 12: memos.api.v1.SetMemoResourcesRequest - (*ListMemoResourcesRequest)(nil), // 13: memos.api.v1.ListMemoResourcesRequest - (*ListMemoResourcesResponse)(nil), // 14: memos.api.v1.ListMemoResourcesResponse - (*MemoRelation)(nil), // 15: memos.api.v1.MemoRelation - (*SetMemoRelationsRequest)(nil), // 16: memos.api.v1.SetMemoRelationsRequest - (*ListMemoRelationsRequest)(nil), // 17: memos.api.v1.ListMemoRelationsRequest - (*ListMemoRelationsResponse)(nil), // 18: memos.api.v1.ListMemoRelationsResponse - (*CreateMemoCommentRequest)(nil), // 19: memos.api.v1.CreateMemoCommentRequest - (*ListMemoCommentsRequest)(nil), // 20: memos.api.v1.ListMemoCommentsRequest - (*ListMemoCommentsResponse)(nil), // 21: memos.api.v1.ListMemoCommentsResponse - (*ListMemoReactionsRequest)(nil), // 22: memos.api.v1.ListMemoReactionsRequest - (*ListMemoReactionsResponse)(nil), // 23: memos.api.v1.ListMemoReactionsResponse - (*UpsertMemoReactionRequest)(nil), // 24: memos.api.v1.UpsertMemoReactionRequest - (*DeleteMemoReactionRequest)(nil), // 25: memos.api.v1.DeleteMemoReactionRequest - (*Memo_Property)(nil), // 26: memos.api.v1.Memo.Property - (*MemoRelation_Memo)(nil), // 27: memos.api.v1.MemoRelation.Memo - (State)(0), // 28: memos.api.v1.State - (*timestamppb.Timestamp)(nil), // 29: google.protobuf.Timestamp - (*Node)(nil), // 30: memos.api.v1.Node - (*Resource)(nil), // 31: memos.api.v1.Resource - (*Reaction)(nil), // 32: memos.api.v1.Reaction - (Direction)(0), // 33: memos.api.v1.Direction - (*fieldmaskpb.FieldMask)(nil), // 34: google.protobuf.FieldMask - (*emptypb.Empty)(nil), // 35: google.protobuf.Empty + (Visibility)(0), // 0: memos.api.v1.Visibility + (MemoRelation_Type)(0), // 1: memos.api.v1.MemoRelation.Type + (*Memo)(nil), // 2: memos.api.v1.Memo + (*Location)(nil), // 3: memos.api.v1.Location + (*CreateMemoRequest)(nil), // 4: memos.api.v1.CreateMemoRequest + (*ListMemosRequest)(nil), // 5: memos.api.v1.ListMemosRequest + (*ListMemosResponse)(nil), // 6: memos.api.v1.ListMemosResponse + (*GetMemoRequest)(nil), // 7: memos.api.v1.GetMemoRequest + (*UpdateMemoRequest)(nil), // 8: memos.api.v1.UpdateMemoRequest + (*DeleteMemoRequest)(nil), // 9: memos.api.v1.DeleteMemoRequest + (*RenameMemoTagRequest)(nil), // 10: memos.api.v1.RenameMemoTagRequest + (*DeleteMemoTagRequest)(nil), // 11: memos.api.v1.DeleteMemoTagRequest + (*SetMemoAttachmentsRequest)(nil), // 12: memos.api.v1.SetMemoAttachmentsRequest + (*ListMemoAttachmentsRequest)(nil), // 13: memos.api.v1.ListMemoAttachmentsRequest + (*ListMemoAttachmentsResponse)(nil), // 14: memos.api.v1.ListMemoAttachmentsResponse + (*MemoRelation)(nil), // 15: memos.api.v1.MemoRelation + (*SetMemoRelationsRequest)(nil), // 16: memos.api.v1.SetMemoRelationsRequest + (*ListMemoRelationsRequest)(nil), // 17: memos.api.v1.ListMemoRelationsRequest + (*ListMemoRelationsResponse)(nil), // 18: memos.api.v1.ListMemoRelationsResponse + (*CreateMemoCommentRequest)(nil), // 19: memos.api.v1.CreateMemoCommentRequest + (*ListMemoCommentsRequest)(nil), // 20: memos.api.v1.ListMemoCommentsRequest + (*ListMemoCommentsResponse)(nil), // 21: memos.api.v1.ListMemoCommentsResponse + (*ListMemoReactionsRequest)(nil), // 22: memos.api.v1.ListMemoReactionsRequest + (*ListMemoReactionsResponse)(nil), // 23: memos.api.v1.ListMemoReactionsResponse + (*UpsertMemoReactionRequest)(nil), // 24: memos.api.v1.UpsertMemoReactionRequest + (*DeleteMemoReactionRequest)(nil), // 25: memos.api.v1.DeleteMemoReactionRequest + (*Memo_Property)(nil), // 26: memos.api.v1.Memo.Property + (*MemoRelation_Memo)(nil), // 27: memos.api.v1.MemoRelation.Memo + (State)(0), // 28: memos.api.v1.State + (*timestamppb.Timestamp)(nil), // 29: google.protobuf.Timestamp + (*Node)(nil), // 30: memos.api.v1.Node + (*Attachment)(nil), // 31: memos.api.v1.Attachment + (*Reaction)(nil), // 32: memos.api.v1.Reaction + (Direction)(0), // 33: memos.api.v1.Direction + (*fieldmaskpb.FieldMask)(nil), // 34: google.protobuf.FieldMask + (*emptypb.Empty)(nil), // 35: google.protobuf.Empty } var file_api_v1_memo_service_proto_depIdxs = []int32{ 28, // 0: memos.api.v1.Memo.state:type_name -> memos.api.v1.State @@ -1864,7 +1864,7 @@ var file_api_v1_memo_service_proto_depIdxs = []int32{ 29, // 3: memos.api.v1.Memo.display_time:type_name -> google.protobuf.Timestamp 30, // 4: memos.api.v1.Memo.nodes:type_name -> memos.api.v1.Node 0, // 5: memos.api.v1.Memo.visibility:type_name -> memos.api.v1.Visibility - 31, // 6: memos.api.v1.Memo.resources:type_name -> memos.api.v1.Resource + 31, // 6: memos.api.v1.Memo.attachments:type_name -> memos.api.v1.Attachment 15, // 7: memos.api.v1.Memo.relations:type_name -> memos.api.v1.MemoRelation 32, // 8: memos.api.v1.Memo.reactions:type_name -> memos.api.v1.Reaction 26, // 9: memos.api.v1.Memo.property:type_name -> memos.api.v1.Memo.Property @@ -1875,8 +1875,8 @@ var file_api_v1_memo_service_proto_depIdxs = []int32{ 2, // 14: memos.api.v1.ListMemosResponse.memos:type_name -> memos.api.v1.Memo 2, // 15: memos.api.v1.UpdateMemoRequest.memo:type_name -> memos.api.v1.Memo 34, // 16: memos.api.v1.UpdateMemoRequest.update_mask:type_name -> google.protobuf.FieldMask - 31, // 17: memos.api.v1.SetMemoResourcesRequest.resources:type_name -> memos.api.v1.Resource - 31, // 18: memos.api.v1.ListMemoResourcesResponse.resources:type_name -> memos.api.v1.Resource + 31, // 17: memos.api.v1.SetMemoAttachmentsRequest.attachments:type_name -> memos.api.v1.Attachment + 31, // 18: memos.api.v1.ListMemoAttachmentsResponse.attachments:type_name -> memos.api.v1.Attachment 27, // 19: memos.api.v1.MemoRelation.memo:type_name -> memos.api.v1.MemoRelation.Memo 27, // 20: memos.api.v1.MemoRelation.related_memo:type_name -> memos.api.v1.MemoRelation.Memo 1, // 21: memos.api.v1.MemoRelation.type:type_name -> memos.api.v1.MemoRelation.Type @@ -1893,8 +1893,8 @@ var file_api_v1_memo_service_proto_depIdxs = []int32{ 9, // 32: memos.api.v1.MemoService.DeleteMemo:input_type -> memos.api.v1.DeleteMemoRequest 10, // 33: memos.api.v1.MemoService.RenameMemoTag:input_type -> memos.api.v1.RenameMemoTagRequest 11, // 34: memos.api.v1.MemoService.DeleteMemoTag:input_type -> memos.api.v1.DeleteMemoTagRequest - 12, // 35: memos.api.v1.MemoService.SetMemoResources:input_type -> memos.api.v1.SetMemoResourcesRequest - 13, // 36: memos.api.v1.MemoService.ListMemoResources:input_type -> memos.api.v1.ListMemoResourcesRequest + 12, // 35: memos.api.v1.MemoService.SetMemoAttachments:input_type -> memos.api.v1.SetMemoAttachmentsRequest + 13, // 36: memos.api.v1.MemoService.ListMemoAttachments:input_type -> memos.api.v1.ListMemoAttachmentsRequest 16, // 37: memos.api.v1.MemoService.SetMemoRelations:input_type -> memos.api.v1.SetMemoRelationsRequest 17, // 38: memos.api.v1.MemoService.ListMemoRelations:input_type -> memos.api.v1.ListMemoRelationsRequest 19, // 39: memos.api.v1.MemoService.CreateMemoComment:input_type -> memos.api.v1.CreateMemoCommentRequest @@ -1909,8 +1909,8 @@ var file_api_v1_memo_service_proto_depIdxs = []int32{ 35, // 48: memos.api.v1.MemoService.DeleteMemo:output_type -> google.protobuf.Empty 35, // 49: memos.api.v1.MemoService.RenameMemoTag:output_type -> google.protobuf.Empty 35, // 50: memos.api.v1.MemoService.DeleteMemoTag:output_type -> google.protobuf.Empty - 35, // 51: memos.api.v1.MemoService.SetMemoResources:output_type -> google.protobuf.Empty - 14, // 52: memos.api.v1.MemoService.ListMemoResources:output_type -> memos.api.v1.ListMemoResourcesResponse + 35, // 51: memos.api.v1.MemoService.SetMemoAttachments:output_type -> google.protobuf.Empty + 14, // 52: memos.api.v1.MemoService.ListMemoAttachments:output_type -> memos.api.v1.ListMemoAttachmentsResponse 35, // 53: memos.api.v1.MemoService.SetMemoRelations:output_type -> google.protobuf.Empty 18, // 54: memos.api.v1.MemoService.ListMemoRelations:output_type -> memos.api.v1.ListMemoRelationsResponse 2, // 55: memos.api.v1.MemoService.CreateMemoComment:output_type -> memos.api.v1.Memo @@ -1930,10 +1930,10 @@ func file_api_v1_memo_service_proto_init() { if File_api_v1_memo_service_proto != nil { return } + file_api_v1_attachment_service_proto_init() file_api_v1_common_proto_init() file_api_v1_markdown_service_proto_init() file_api_v1_reaction_service_proto_init() - file_api_v1_resource_service_proto_init() file_api_v1_memo_service_proto_msgTypes[0].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ diff --git a/proto/gen/api/v1/memo_service.pb.gw.go b/proto/gen/api/v1/memo_service.pb.gw.go index 58c5cd2ca..55d8aac0c 100644 --- a/proto/gen/api/v1/memo_service.pb.gw.go +++ b/proto/gen/api/v1/memo_service.pb.gw.go @@ -404,9 +404,9 @@ func local_request_MemoService_DeleteMemoTag_0(ctx context.Context, marshaler ru return msg, metadata, err } -func request_MemoService_SetMemoResources_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_MemoService_SetMemoAttachments_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq SetMemoResourcesRequest + protoReq SetMemoAttachmentsRequest metadata runtime.ServerMetadata err error ) @@ -421,13 +421,13 @@ func request_MemoService_SetMemoResources_0(ctx context.Context, marshaler runti if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) } - msg, err := client.SetMemoResources(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.SetMemoAttachments(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_MemoService_SetMemoResources_0(ctx context.Context, marshaler runtime.Marshaler, server MemoServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_MemoService_SetMemoAttachments_0(ctx context.Context, marshaler runtime.Marshaler, server MemoServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq SetMemoResourcesRequest + protoReq SetMemoAttachmentsRequest metadata runtime.ServerMetadata err error ) @@ -442,13 +442,13 @@ func local_request_MemoService_SetMemoResources_0(ctx context.Context, marshaler if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) } - msg, err := server.SetMemoResources(ctx, &protoReq) + msg, err := server.SetMemoAttachments(ctx, &protoReq) return msg, metadata, err } -func request_MemoService_ListMemoResources_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_MemoService_ListMemoAttachments_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq ListMemoResourcesRequest + protoReq ListMemoAttachmentsRequest metadata runtime.ServerMetadata err error ) @@ -461,13 +461,13 @@ func request_MemoService_ListMemoResources_0(ctx context.Context, marshaler runt if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) } - msg, err := client.ListMemoResources(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.ListMemoAttachments(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_MemoService_ListMemoResources_0(ctx context.Context, marshaler runtime.Marshaler, server MemoServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func local_request_MemoService_ListMemoAttachments_0(ctx context.Context, marshaler runtime.Marshaler, server MemoServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var ( - protoReq ListMemoResourcesRequest + protoReq ListMemoAttachmentsRequest metadata runtime.ServerMetadata err error ) @@ -479,7 +479,7 @@ func local_request_MemoService_ListMemoResources_0(ctx context.Context, marshale if err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) } - msg, err := server.ListMemoResources(ctx, &protoReq) + msg, err := server.ListMemoAttachments(ctx, &protoReq) return msg, metadata, err } @@ -923,45 +923,45 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux } forward_MemoService_DeleteMemoTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle(http.MethodPatch, pattern_MemoService_SetMemoResources_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodPatch, pattern_MemoService_SetMemoAttachments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/SetMemoResources", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/resources")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/SetMemoAttachments", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/attachments")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_MemoService_SetMemoResources_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_MemoService_SetMemoAttachments_0(annotatedContext, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_MemoService_SetMemoResources_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_MemoService_SetMemoAttachments_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle(http.MethodGet, pattern_MemoService_ListMemoResources_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodGet, pattern_MemoService_ListMemoAttachments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/ListMemoResources", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/resources")) + annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/ListMemoAttachments", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/attachments")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_MemoService_ListMemoResources_0(annotatedContext, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_MemoService_ListMemoAttachments_0(annotatedContext, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_MemoService_ListMemoResources_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_MemoService_ListMemoAttachments_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) mux.Handle(http.MethodPatch, pattern_MemoService_SetMemoRelations_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) @@ -1279,39 +1279,39 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux } forward_MemoService_DeleteMemoTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle(http.MethodPatch, pattern_MemoService_SetMemoResources_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodPatch, pattern_MemoService_SetMemoAttachments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/SetMemoResources", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/resources")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/SetMemoAttachments", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/attachments")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_MemoService_SetMemoResources_0(annotatedContext, inboundMarshaler, client, req, pathParams) + resp, md, err := request_MemoService_SetMemoAttachments_0(annotatedContext, inboundMarshaler, client, req, pathParams) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_MemoService_SetMemoResources_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_MemoService_SetMemoAttachments_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle(http.MethodGet, pattern_MemoService_ListMemoResources_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle(http.MethodGet, pattern_MemoService_ListMemoAttachments_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/ListMemoResources", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/resources")) + annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/ListMemoAttachments", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/attachments")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_MemoService_ListMemoResources_0(annotatedContext, inboundMarshaler, client, req, pathParams) + resp, md, err := request_MemoService_ListMemoAttachments_0(annotatedContext, inboundMarshaler, client, req, pathParams) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) if err != nil { runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) return } - forward_MemoService_ListMemoResources_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_MemoService_ListMemoAttachments_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) mux.Handle(http.MethodPatch, pattern_MemoService_SetMemoRelations_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) @@ -1436,41 +1436,41 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux } var ( - pattern_MemoService_CreateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, "")) - pattern_MemoService_ListMemos_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, "")) - pattern_MemoService_ListMemos_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "users", "parent", "memos"}, "")) - pattern_MemoService_GetMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, "")) - pattern_MemoService_UpdateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "memo.name"}, "")) - pattern_MemoService_DeleteMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, "")) - pattern_MemoService_RenameMemoTag_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "parent", "tags"}, "rename")) - pattern_MemoService_DeleteMemoTag_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"api", "v1", "memos", "parent", "tags", "tag"}, "")) - pattern_MemoService_SetMemoResources_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "resources"}, "")) - pattern_MemoService_ListMemoResources_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "resources"}, "")) - pattern_MemoService_SetMemoRelations_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "relations"}, "")) - pattern_MemoService_ListMemoRelations_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "relations"}, "")) - pattern_MemoService_CreateMemoComment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "comments"}, "")) - pattern_MemoService_ListMemoComments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "comments"}, "")) - pattern_MemoService_ListMemoReactions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, "")) - pattern_MemoService_UpsertMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, "")) - pattern_MemoService_DeleteMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "reactions", "id"}, "")) + pattern_MemoService_CreateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, "")) + pattern_MemoService_ListMemos_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, "")) + pattern_MemoService_ListMemos_1 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "users", "parent", "memos"}, "")) + pattern_MemoService_GetMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, "")) + pattern_MemoService_UpdateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "memo.name"}, "")) + pattern_MemoService_DeleteMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, "")) + pattern_MemoService_RenameMemoTag_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "parent", "tags"}, "rename")) + pattern_MemoService_DeleteMemoTag_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"api", "v1", "memos", "parent", "tags", "tag"}, "")) + pattern_MemoService_SetMemoAttachments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "attachments"}, "")) + pattern_MemoService_ListMemoAttachments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "attachments"}, "")) + pattern_MemoService_SetMemoRelations_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "relations"}, "")) + pattern_MemoService_ListMemoRelations_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "relations"}, "")) + pattern_MemoService_CreateMemoComment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "comments"}, "")) + pattern_MemoService_ListMemoComments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "comments"}, "")) + pattern_MemoService_ListMemoReactions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, "")) + pattern_MemoService_UpsertMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, "")) + pattern_MemoService_DeleteMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "reactions", "id"}, "")) ) var ( - forward_MemoService_CreateMemo_0 = runtime.ForwardResponseMessage - forward_MemoService_ListMemos_0 = runtime.ForwardResponseMessage - forward_MemoService_ListMemos_1 = runtime.ForwardResponseMessage - forward_MemoService_GetMemo_0 = runtime.ForwardResponseMessage - forward_MemoService_UpdateMemo_0 = runtime.ForwardResponseMessage - forward_MemoService_DeleteMemo_0 = runtime.ForwardResponseMessage - forward_MemoService_RenameMemoTag_0 = runtime.ForwardResponseMessage - forward_MemoService_DeleteMemoTag_0 = runtime.ForwardResponseMessage - forward_MemoService_SetMemoResources_0 = runtime.ForwardResponseMessage - forward_MemoService_ListMemoResources_0 = runtime.ForwardResponseMessage - forward_MemoService_SetMemoRelations_0 = runtime.ForwardResponseMessage - forward_MemoService_ListMemoRelations_0 = runtime.ForwardResponseMessage - forward_MemoService_CreateMemoComment_0 = runtime.ForwardResponseMessage - forward_MemoService_ListMemoComments_0 = runtime.ForwardResponseMessage - forward_MemoService_ListMemoReactions_0 = runtime.ForwardResponseMessage - forward_MemoService_UpsertMemoReaction_0 = runtime.ForwardResponseMessage - forward_MemoService_DeleteMemoReaction_0 = runtime.ForwardResponseMessage + forward_MemoService_CreateMemo_0 = runtime.ForwardResponseMessage + forward_MemoService_ListMemos_0 = runtime.ForwardResponseMessage + forward_MemoService_ListMemos_1 = runtime.ForwardResponseMessage + forward_MemoService_GetMemo_0 = runtime.ForwardResponseMessage + forward_MemoService_UpdateMemo_0 = runtime.ForwardResponseMessage + forward_MemoService_DeleteMemo_0 = runtime.ForwardResponseMessage + forward_MemoService_RenameMemoTag_0 = runtime.ForwardResponseMessage + forward_MemoService_DeleteMemoTag_0 = runtime.ForwardResponseMessage + forward_MemoService_SetMemoAttachments_0 = runtime.ForwardResponseMessage + forward_MemoService_ListMemoAttachments_0 = runtime.ForwardResponseMessage + forward_MemoService_SetMemoRelations_0 = runtime.ForwardResponseMessage + forward_MemoService_ListMemoRelations_0 = runtime.ForwardResponseMessage + forward_MemoService_CreateMemoComment_0 = runtime.ForwardResponseMessage + forward_MemoService_ListMemoComments_0 = runtime.ForwardResponseMessage + forward_MemoService_ListMemoReactions_0 = runtime.ForwardResponseMessage + forward_MemoService_UpsertMemoReaction_0 = runtime.ForwardResponseMessage + forward_MemoService_DeleteMemoReaction_0 = runtime.ForwardResponseMessage ) diff --git a/proto/gen/api/v1/memo_service_grpc.pb.go b/proto/gen/api/v1/memo_service_grpc.pb.go index 082a26676..83e8a2fc6 100644 --- a/proto/gen/api/v1/memo_service_grpc.pb.go +++ b/proto/gen/api/v1/memo_service_grpc.pb.go @@ -20,22 +20,22 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - MemoService_CreateMemo_FullMethodName = "/memos.api.v1.MemoService/CreateMemo" - MemoService_ListMemos_FullMethodName = "/memos.api.v1.MemoService/ListMemos" - MemoService_GetMemo_FullMethodName = "/memos.api.v1.MemoService/GetMemo" - MemoService_UpdateMemo_FullMethodName = "/memos.api.v1.MemoService/UpdateMemo" - MemoService_DeleteMemo_FullMethodName = "/memos.api.v1.MemoService/DeleteMemo" - MemoService_RenameMemoTag_FullMethodName = "/memos.api.v1.MemoService/RenameMemoTag" - MemoService_DeleteMemoTag_FullMethodName = "/memos.api.v1.MemoService/DeleteMemoTag" - MemoService_SetMemoResources_FullMethodName = "/memos.api.v1.MemoService/SetMemoResources" - MemoService_ListMemoResources_FullMethodName = "/memos.api.v1.MemoService/ListMemoResources" - MemoService_SetMemoRelations_FullMethodName = "/memos.api.v1.MemoService/SetMemoRelations" - MemoService_ListMemoRelations_FullMethodName = "/memos.api.v1.MemoService/ListMemoRelations" - MemoService_CreateMemoComment_FullMethodName = "/memos.api.v1.MemoService/CreateMemoComment" - MemoService_ListMemoComments_FullMethodName = "/memos.api.v1.MemoService/ListMemoComments" - MemoService_ListMemoReactions_FullMethodName = "/memos.api.v1.MemoService/ListMemoReactions" - MemoService_UpsertMemoReaction_FullMethodName = "/memos.api.v1.MemoService/UpsertMemoReaction" - MemoService_DeleteMemoReaction_FullMethodName = "/memos.api.v1.MemoService/DeleteMemoReaction" + MemoService_CreateMemo_FullMethodName = "/memos.api.v1.MemoService/CreateMemo" + MemoService_ListMemos_FullMethodName = "/memos.api.v1.MemoService/ListMemos" + MemoService_GetMemo_FullMethodName = "/memos.api.v1.MemoService/GetMemo" + MemoService_UpdateMemo_FullMethodName = "/memos.api.v1.MemoService/UpdateMemo" + MemoService_DeleteMemo_FullMethodName = "/memos.api.v1.MemoService/DeleteMemo" + MemoService_RenameMemoTag_FullMethodName = "/memos.api.v1.MemoService/RenameMemoTag" + MemoService_DeleteMemoTag_FullMethodName = "/memos.api.v1.MemoService/DeleteMemoTag" + MemoService_SetMemoAttachments_FullMethodName = "/memos.api.v1.MemoService/SetMemoAttachments" + MemoService_ListMemoAttachments_FullMethodName = "/memos.api.v1.MemoService/ListMemoAttachments" + MemoService_SetMemoRelations_FullMethodName = "/memos.api.v1.MemoService/SetMemoRelations" + MemoService_ListMemoRelations_FullMethodName = "/memos.api.v1.MemoService/ListMemoRelations" + MemoService_CreateMemoComment_FullMethodName = "/memos.api.v1.MemoService/CreateMemoComment" + MemoService_ListMemoComments_FullMethodName = "/memos.api.v1.MemoService/ListMemoComments" + MemoService_ListMemoReactions_FullMethodName = "/memos.api.v1.MemoService/ListMemoReactions" + MemoService_UpsertMemoReaction_FullMethodName = "/memos.api.v1.MemoService/UpsertMemoReaction" + MemoService_DeleteMemoReaction_FullMethodName = "/memos.api.v1.MemoService/DeleteMemoReaction" ) // MemoServiceClient is the client API for MemoService service. @@ -56,10 +56,10 @@ type MemoServiceClient interface { RenameMemoTag(ctx context.Context, in *RenameMemoTagRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) // DeleteMemoTag deletes a tag for a memo. DeleteMemoTag(ctx context.Context, in *DeleteMemoTagRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) - // SetMemoResources sets resources for a memo. - SetMemoResources(ctx context.Context, in *SetMemoResourcesRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) - // ListMemoResources lists resources for a memo. - ListMemoResources(ctx context.Context, in *ListMemoResourcesRequest, opts ...grpc.CallOption) (*ListMemoResourcesResponse, error) + // SetMemoAttachments sets attachments for a memo. + SetMemoAttachments(ctx context.Context, in *SetMemoAttachmentsRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) + // ListMemoAttachments lists attachments for a memo. + ListMemoAttachments(ctx context.Context, in *ListMemoAttachmentsRequest, opts ...grpc.CallOption) (*ListMemoAttachmentsResponse, error) // SetMemoRelations sets relations for a memo. SetMemoRelations(ctx context.Context, in *SetMemoRelationsRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) // ListMemoRelations lists relations for a memo. @@ -154,20 +154,20 @@ func (c *memoServiceClient) DeleteMemoTag(ctx context.Context, in *DeleteMemoTag return out, nil } -func (c *memoServiceClient) SetMemoResources(ctx context.Context, in *SetMemoResourcesRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { +func (c *memoServiceClient) SetMemoAttachments(ctx context.Context, in *SetMemoAttachmentsRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(emptypb.Empty) - err := c.cc.Invoke(ctx, MemoService_SetMemoResources_FullMethodName, in, out, cOpts...) + err := c.cc.Invoke(ctx, MemoService_SetMemoAttachments_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } return out, nil } -func (c *memoServiceClient) ListMemoResources(ctx context.Context, in *ListMemoResourcesRequest, opts ...grpc.CallOption) (*ListMemoResourcesResponse, error) { +func (c *memoServiceClient) ListMemoAttachments(ctx context.Context, in *ListMemoAttachmentsRequest, opts ...grpc.CallOption) (*ListMemoAttachmentsResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(ListMemoResourcesResponse) - err := c.cc.Invoke(ctx, MemoService_ListMemoResources_FullMethodName, in, out, cOpts...) + out := new(ListMemoAttachmentsResponse) + err := c.cc.Invoke(ctx, MemoService_ListMemoAttachments_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -262,10 +262,10 @@ type MemoServiceServer interface { RenameMemoTag(context.Context, *RenameMemoTagRequest) (*emptypb.Empty, error) // DeleteMemoTag deletes a tag for a memo. DeleteMemoTag(context.Context, *DeleteMemoTagRequest) (*emptypb.Empty, error) - // SetMemoResources sets resources for a memo. - SetMemoResources(context.Context, *SetMemoResourcesRequest) (*emptypb.Empty, error) - // ListMemoResources lists resources for a memo. - ListMemoResources(context.Context, *ListMemoResourcesRequest) (*ListMemoResourcesResponse, error) + // SetMemoAttachments sets attachments for a memo. + SetMemoAttachments(context.Context, *SetMemoAttachmentsRequest) (*emptypb.Empty, error) + // ListMemoAttachments lists attachments for a memo. + ListMemoAttachments(context.Context, *ListMemoAttachmentsRequest) (*ListMemoAttachmentsResponse, error) // SetMemoRelations sets relations for a memo. SetMemoRelations(context.Context, *SetMemoRelationsRequest) (*emptypb.Empty, error) // ListMemoRelations lists relations for a memo. @@ -311,11 +311,11 @@ func (UnimplementedMemoServiceServer) RenameMemoTag(context.Context, *RenameMemo func (UnimplementedMemoServiceServer) DeleteMemoTag(context.Context, *DeleteMemoTagRequest) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteMemoTag not implemented") } -func (UnimplementedMemoServiceServer) SetMemoResources(context.Context, *SetMemoResourcesRequest) (*emptypb.Empty, error) { - return nil, status.Errorf(codes.Unimplemented, "method SetMemoResources not implemented") +func (UnimplementedMemoServiceServer) SetMemoAttachments(context.Context, *SetMemoAttachmentsRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetMemoAttachments not implemented") } -func (UnimplementedMemoServiceServer) ListMemoResources(context.Context, *ListMemoResourcesRequest) (*ListMemoResourcesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListMemoResources not implemented") +func (UnimplementedMemoServiceServer) ListMemoAttachments(context.Context, *ListMemoAttachmentsRequest) (*ListMemoAttachmentsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListMemoAttachments not implemented") } func (UnimplementedMemoServiceServer) SetMemoRelations(context.Context, *SetMemoRelationsRequest) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method SetMemoRelations not implemented") @@ -485,38 +485,38 @@ func _MemoService_DeleteMemoTag_Handler(srv interface{}, ctx context.Context, de return interceptor(ctx, in, info, handler) } -func _MemoService_SetMemoResources_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(SetMemoResourcesRequest) +func _MemoService_SetMemoAttachments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SetMemoAttachmentsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MemoServiceServer).SetMemoResources(ctx, in) + return srv.(MemoServiceServer).SetMemoAttachments(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: MemoService_SetMemoResources_FullMethodName, + FullMethod: MemoService_SetMemoAttachments_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MemoServiceServer).SetMemoResources(ctx, req.(*SetMemoResourcesRequest)) + return srv.(MemoServiceServer).SetMemoAttachments(ctx, req.(*SetMemoAttachmentsRequest)) } return interceptor(ctx, in, info, handler) } -func _MemoService_ListMemoResources_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListMemoResourcesRequest) +func _MemoService_ListMemoAttachments_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListMemoAttachmentsRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(MemoServiceServer).ListMemoResources(ctx, in) + return srv.(MemoServiceServer).ListMemoAttachments(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: MemoService_ListMemoResources_FullMethodName, + FullMethod: MemoService_ListMemoAttachments_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MemoServiceServer).ListMemoResources(ctx, req.(*ListMemoResourcesRequest)) + return srv.(MemoServiceServer).ListMemoAttachments(ctx, req.(*ListMemoAttachmentsRequest)) } return interceptor(ctx, in, info, handler) } @@ -683,12 +683,12 @@ var MemoService_ServiceDesc = grpc.ServiceDesc{ Handler: _MemoService_DeleteMemoTag_Handler, }, { - MethodName: "SetMemoResources", - Handler: _MemoService_SetMemoResources_Handler, + MethodName: "SetMemoAttachments", + Handler: _MemoService_SetMemoAttachments_Handler, }, { - MethodName: "ListMemoResources", - Handler: _MemoService_ListMemoResources_Handler, + MethodName: "ListMemoAttachments", + Handler: _MemoService_ListMemoAttachments_Handler, }, { MethodName: "SetMemoRelations", diff --git a/proto/gen/api/v1/resource_service.pb.go b/proto/gen/api/v1/resource_service.pb.go deleted file mode 100644 index 354755965..000000000 --- a/proto/gen/api/v1/resource_service.pb.go +++ /dev/null @@ -1,578 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.36.6 -// protoc (unknown) -// source: api/v1/resource_service.proto - -package apiv1 - -import ( - _ "google.golang.org/genproto/googleapis/api/annotations" - httpbody "google.golang.org/genproto/googleapis/api/httpbody" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - emptypb "google.golang.org/protobuf/types/known/emptypb" - fieldmaskpb "google.golang.org/protobuf/types/known/fieldmaskpb" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - reflect "reflect" - sync "sync" - unsafe "unsafe" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Resource struct { - state protoimpl.MessageState `protogen:"open.v1"` - // The name of the resource. - // Format: resources/{resource}, resource is the user defined if or uuid. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - CreateTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` - Filename string `protobuf:"bytes,4,opt,name=filename,proto3" json:"filename,omitempty"` - Content []byte `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"` - ExternalLink string `protobuf:"bytes,6,opt,name=external_link,json=externalLink,proto3" json:"external_link,omitempty"` - Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"` - Size int64 `protobuf:"varint,8,opt,name=size,proto3" json:"size,omitempty"` - // The related memo. Refer to `Memo.name`. - Memo *string `protobuf:"bytes,9,opt,name=memo,proto3,oneof" json:"memo,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *Resource) Reset() { - *x = Resource{} - mi := &file_api_v1_resource_service_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *Resource) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Resource) ProtoMessage() {} - -func (x *Resource) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[0] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Resource.ProtoReflect.Descriptor instead. -func (*Resource) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{0} -} - -func (x *Resource) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Resource) GetCreateTime() *timestamppb.Timestamp { - if x != nil { - return x.CreateTime - } - return nil -} - -func (x *Resource) GetFilename() string { - if x != nil { - return x.Filename - } - return "" -} - -func (x *Resource) GetContent() []byte { - if x != nil { - return x.Content - } - return nil -} - -func (x *Resource) GetExternalLink() string { - if x != nil { - return x.ExternalLink - } - return "" -} - -func (x *Resource) GetType() string { - if x != nil { - return x.Type - } - return "" -} - -func (x *Resource) GetSize() int64 { - if x != nil { - return x.Size - } - return 0 -} - -func (x *Resource) GetMemo() string { - if x != nil && x.Memo != nil { - return *x.Memo - } - return "" -} - -type CreateResourceRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - Resource *Resource `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *CreateResourceRequest) Reset() { - *x = CreateResourceRequest{} - mi := &file_api_v1_resource_service_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *CreateResourceRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CreateResourceRequest) ProtoMessage() {} - -func (x *CreateResourceRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[1] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use CreateResourceRequest.ProtoReflect.Descriptor instead. -func (*CreateResourceRequest) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{1} -} - -func (x *CreateResourceRequest) GetResource() *Resource { - if x != nil { - return x.Resource - } - return nil -} - -type ListResourcesRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *ListResourcesRequest) Reset() { - *x = ListResourcesRequest{} - mi := &file_api_v1_resource_service_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *ListResourcesRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ListResourcesRequest) ProtoMessage() {} - -func (x *ListResourcesRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[2] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ListResourcesRequest.ProtoReflect.Descriptor instead. -func (*ListResourcesRequest) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{2} -} - -type ListResourcesResponse struct { - state protoimpl.MessageState `protogen:"open.v1"` - Resources []*Resource `protobuf:"bytes,1,rep,name=resources,proto3" json:"resources,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *ListResourcesResponse) Reset() { - *x = ListResourcesResponse{} - mi := &file_api_v1_resource_service_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *ListResourcesResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ListResourcesResponse) ProtoMessage() {} - -func (x *ListResourcesResponse) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[3] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ListResourcesResponse.ProtoReflect.Descriptor instead. -func (*ListResourcesResponse) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{3} -} - -func (x *ListResourcesResponse) GetResources() []*Resource { - if x != nil { - return x.Resources - } - return nil -} - -type GetResourceRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - // The name of the resource. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *GetResourceRequest) Reset() { - *x = GetResourceRequest{} - mi := &file_api_v1_resource_service_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *GetResourceRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetResourceRequest) ProtoMessage() {} - -func (x *GetResourceRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[4] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetResourceRequest.ProtoReflect.Descriptor instead. -func (*GetResourceRequest) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{4} -} - -func (x *GetResourceRequest) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -type GetResourceBinaryRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - // The name of the resource. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - // The filename of the resource. Mainly used for downloading. - Filename string `protobuf:"bytes,2,opt,name=filename,proto3" json:"filename,omitempty"` - // A flag indicating if the thumbnail version of the resource should be returned - Thumbnail bool `protobuf:"varint,3,opt,name=thumbnail,proto3" json:"thumbnail,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *GetResourceBinaryRequest) Reset() { - *x = GetResourceBinaryRequest{} - mi := &file_api_v1_resource_service_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *GetResourceBinaryRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*GetResourceBinaryRequest) ProtoMessage() {} - -func (x *GetResourceBinaryRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[5] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use GetResourceBinaryRequest.ProtoReflect.Descriptor instead. -func (*GetResourceBinaryRequest) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{5} -} - -func (x *GetResourceBinaryRequest) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *GetResourceBinaryRequest) GetFilename() string { - if x != nil { - return x.Filename - } - return "" -} - -func (x *GetResourceBinaryRequest) GetThumbnail() bool { - if x != nil { - return x.Thumbnail - } - return false -} - -type UpdateResourceRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - Resource *Resource `protobuf:"bytes,1,opt,name=resource,proto3" json:"resource,omitempty"` - UpdateMask *fieldmaskpb.FieldMask `protobuf:"bytes,2,opt,name=update_mask,json=updateMask,proto3" json:"update_mask,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *UpdateResourceRequest) Reset() { - *x = UpdateResourceRequest{} - mi := &file_api_v1_resource_service_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *UpdateResourceRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*UpdateResourceRequest) ProtoMessage() {} - -func (x *UpdateResourceRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[6] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use UpdateResourceRequest.ProtoReflect.Descriptor instead. -func (*UpdateResourceRequest) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{6} -} - -func (x *UpdateResourceRequest) GetResource() *Resource { - if x != nil { - return x.Resource - } - return nil -} - -func (x *UpdateResourceRequest) GetUpdateMask() *fieldmaskpb.FieldMask { - if x != nil { - return x.UpdateMask - } - return nil -} - -type DeleteResourceRequest struct { - state protoimpl.MessageState `protogen:"open.v1"` - // The name of the resource. - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - unknownFields protoimpl.UnknownFields - sizeCache protoimpl.SizeCache -} - -func (x *DeleteResourceRequest) Reset() { - *x = DeleteResourceRequest{} - mi := &file_api_v1_resource_service_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) -} - -func (x *DeleteResourceRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*DeleteResourceRequest) ProtoMessage() {} - -func (x *DeleteResourceRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v1_resource_service_proto_msgTypes[7] - if x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use DeleteResourceRequest.ProtoReflect.Descriptor instead. -func (*DeleteResourceRequest) Descriptor() ([]byte, []int) { - return file_api_v1_resource_service_proto_rawDescGZIP(), []int{7} -} - -func (x *DeleteResourceRequest) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -var File_api_v1_resource_service_proto protoreflect.FileDescriptor - -const file_api_v1_resource_service_proto_rawDesc = "" + - "\n" + - "\x1dapi/v1/resource_service.proto\x12\fmemos.api.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/httpbody.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\x1a\x1fgoogle/protobuf/timestamp.proto\"\x98\x02\n" + - "\bResource\x12\x1a\n" + - "\x04name\x18\x01 \x01(\tB\x06\xe0A\x03\xe0A\bR\x04name\x12@\n" + - "\vcreate_time\x18\x03 \x01(\v2\x1a.google.protobuf.TimestampB\x03\xe0A\x03R\n" + - "createTime\x12\x1a\n" + - "\bfilename\x18\x04 \x01(\tR\bfilename\x12\x1d\n" + - "\acontent\x18\x05 \x01(\fB\x03\xe0A\x04R\acontent\x12#\n" + - "\rexternal_link\x18\x06 \x01(\tR\fexternalLink\x12\x12\n" + - "\x04type\x18\a \x01(\tR\x04type\x12\x12\n" + - "\x04size\x18\b \x01(\x03R\x04size\x12\x17\n" + - "\x04memo\x18\t \x01(\tH\x00R\x04memo\x88\x01\x01B\a\n" + - "\x05_memoJ\x04\b\x02\x10\x03\"K\n" + - "\x15CreateResourceRequest\x122\n" + - "\bresource\x18\x01 \x01(\v2\x16.memos.api.v1.ResourceR\bresource\"\x16\n" + - "\x14ListResourcesRequest\"M\n" + - "\x15ListResourcesResponse\x124\n" + - "\tresources\x18\x01 \x03(\v2\x16.memos.api.v1.ResourceR\tresources\"(\n" + - "\x12GetResourceRequest\x12\x12\n" + - "\x04name\x18\x01 \x01(\tR\x04name\"h\n" + - "\x18GetResourceBinaryRequest\x12\x12\n" + - "\x04name\x18\x01 \x01(\tR\x04name\x12\x1a\n" + - "\bfilename\x18\x02 \x01(\tR\bfilename\x12\x1c\n" + - "\tthumbnail\x18\x03 \x01(\bR\tthumbnail\"\x88\x01\n" + - "\x15UpdateResourceRequest\x122\n" + - "\bresource\x18\x01 \x01(\v2\x16.memos.api.v1.ResourceR\bresource\x12;\n" + - "\vupdate_mask\x18\x02 \x01(\v2\x1a.google.protobuf.FieldMaskR\n" + - "updateMask\"+\n" + - "\x15DeleteResourceRequest\x12\x12\n" + - "\x04name\x18\x01 \x01(\tR\x04name2\x97\x06\n" + - "\x0fResourceService\x12r\n" + - "\x0eCreateResource\x12#.memos.api.v1.CreateResourceRequest\x1a\x16.memos.api.v1.Resource\"#\x82\xd3\xe4\x93\x02\x1d:\bresource\"\x11/api/v1/resources\x12s\n" + - "\rListResources\x12\".memos.api.v1.ListResourcesRequest\x1a#.memos.api.v1.ListResourcesResponse\"\x19\x82\xd3\xe4\x93\x02\x13\x12\x11/api/v1/resources\x12r\n" + - "\vGetResource\x12 .memos.api.v1.GetResourceRequest\x1a\x16.memos.api.v1.Resource\")\xdaA\x04name\x82\xd3\xe4\x93\x02\x1c\x12\x1a/api/v1/{name=resources/*}\x12\x8e\x01\n" + - "\x11GetResourceBinary\x12&.memos.api.v1.GetResourceBinaryRequest\x1a\x14.google.api.HttpBody\";\xdaA\rname,filename\x82\xd3\xe4\x93\x02%\x12#/file/{name=resources/*}/{filename}\x12\x9b\x01\n" + - "\x0eUpdateResource\x12#.memos.api.v1.UpdateResourceRequest\x1a\x16.memos.api.v1.Resource\"L\xdaA\x14resource,update_mask\x82\xd3\xe4\x93\x02/:\bresource2#/api/v1/{resource.name=resources/*}\x12x\n" + - "\x0eDeleteResource\x12#.memos.api.v1.DeleteResourceRequest\x1a\x16.google.protobuf.Empty\")\xdaA\x04name\x82\xd3\xe4\x93\x02\x1c*\x1a/api/v1/{name=resources/*}B\xac\x01\n" + - "\x10com.memos.api.v1B\x14ResourceServiceProtoP\x01Z0github.com/usememos/memos/proto/gen/api/v1;apiv1\xa2\x02\x03MAX\xaa\x02\fMemos.Api.V1\xca\x02\fMemos\\Api\\V1\xe2\x02\x18Memos\\Api\\V1\\GPBMetadata\xea\x02\x0eMemos::Api::V1b\x06proto3" - -var ( - file_api_v1_resource_service_proto_rawDescOnce sync.Once - file_api_v1_resource_service_proto_rawDescData []byte -) - -func file_api_v1_resource_service_proto_rawDescGZIP() []byte { - file_api_v1_resource_service_proto_rawDescOnce.Do(func() { - file_api_v1_resource_service_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_api_v1_resource_service_proto_rawDesc), len(file_api_v1_resource_service_proto_rawDesc))) - }) - return file_api_v1_resource_service_proto_rawDescData -} - -var file_api_v1_resource_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8) -var file_api_v1_resource_service_proto_goTypes = []any{ - (*Resource)(nil), // 0: memos.api.v1.Resource - (*CreateResourceRequest)(nil), // 1: memos.api.v1.CreateResourceRequest - (*ListResourcesRequest)(nil), // 2: memos.api.v1.ListResourcesRequest - (*ListResourcesResponse)(nil), // 3: memos.api.v1.ListResourcesResponse - (*GetResourceRequest)(nil), // 4: memos.api.v1.GetResourceRequest - (*GetResourceBinaryRequest)(nil), // 5: memos.api.v1.GetResourceBinaryRequest - (*UpdateResourceRequest)(nil), // 6: memos.api.v1.UpdateResourceRequest - (*DeleteResourceRequest)(nil), // 7: memos.api.v1.DeleteResourceRequest - (*timestamppb.Timestamp)(nil), // 8: google.protobuf.Timestamp - (*fieldmaskpb.FieldMask)(nil), // 9: google.protobuf.FieldMask - (*httpbody.HttpBody)(nil), // 10: google.api.HttpBody - (*emptypb.Empty)(nil), // 11: google.protobuf.Empty -} -var file_api_v1_resource_service_proto_depIdxs = []int32{ - 8, // 0: memos.api.v1.Resource.create_time:type_name -> google.protobuf.Timestamp - 0, // 1: memos.api.v1.CreateResourceRequest.resource:type_name -> memos.api.v1.Resource - 0, // 2: memos.api.v1.ListResourcesResponse.resources:type_name -> memos.api.v1.Resource - 0, // 3: memos.api.v1.UpdateResourceRequest.resource:type_name -> memos.api.v1.Resource - 9, // 4: memos.api.v1.UpdateResourceRequest.update_mask:type_name -> google.protobuf.FieldMask - 1, // 5: memos.api.v1.ResourceService.CreateResource:input_type -> memos.api.v1.CreateResourceRequest - 2, // 6: memos.api.v1.ResourceService.ListResources:input_type -> memos.api.v1.ListResourcesRequest - 4, // 7: memos.api.v1.ResourceService.GetResource:input_type -> memos.api.v1.GetResourceRequest - 5, // 8: memos.api.v1.ResourceService.GetResourceBinary:input_type -> memos.api.v1.GetResourceBinaryRequest - 6, // 9: memos.api.v1.ResourceService.UpdateResource:input_type -> memos.api.v1.UpdateResourceRequest - 7, // 10: memos.api.v1.ResourceService.DeleteResource:input_type -> memos.api.v1.DeleteResourceRequest - 0, // 11: memos.api.v1.ResourceService.CreateResource:output_type -> memos.api.v1.Resource - 3, // 12: memos.api.v1.ResourceService.ListResources:output_type -> memos.api.v1.ListResourcesResponse - 0, // 13: memos.api.v1.ResourceService.GetResource:output_type -> memos.api.v1.Resource - 10, // 14: memos.api.v1.ResourceService.GetResourceBinary:output_type -> google.api.HttpBody - 0, // 15: memos.api.v1.ResourceService.UpdateResource:output_type -> memos.api.v1.Resource - 11, // 16: memos.api.v1.ResourceService.DeleteResource:output_type -> google.protobuf.Empty - 11, // [11:17] is the sub-list for method output_type - 5, // [5:11] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name -} - -func init() { file_api_v1_resource_service_proto_init() } -func file_api_v1_resource_service_proto_init() { - if File_api_v1_resource_service_proto != nil { - return - } - file_api_v1_resource_service_proto_msgTypes[0].OneofWrappers = []any{} - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: unsafe.Slice(unsafe.StringData(file_api_v1_resource_service_proto_rawDesc), len(file_api_v1_resource_service_proto_rawDesc)), - NumEnums: 0, - NumMessages: 8, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_api_v1_resource_service_proto_goTypes, - DependencyIndexes: file_api_v1_resource_service_proto_depIdxs, - MessageInfos: file_api_v1_resource_service_proto_msgTypes, - }.Build() - File_api_v1_resource_service_proto = out.File - file_api_v1_resource_service_proto_goTypes = nil - file_api_v1_resource_service_proto_depIdxs = nil -} diff --git a/proto/gen/api/v1/resource_service.pb.gw.go b/proto/gen/api/v1/resource_service.pb.gw.go deleted file mode 100644 index 484db26da..000000000 --- a/proto/gen/api/v1/resource_service.pb.gw.go +++ /dev/null @@ -1,587 +0,0 @@ -// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: api/v1/resource_service.proto - -/* -Package apiv1 is a reverse proxy. - -It translates gRPC into RESTful JSON APIs. -*/ -package apiv1 - -import ( - "context" - "errors" - "io" - "net/http" - - "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" - "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/grpclog" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" - "google.golang.org/protobuf/proto" -) - -// Suppress "imported and not used" errors -var ( - _ codes.Code - _ io.Reader - _ status.Status - _ = errors.New - _ = runtime.String - _ = utilities.NewDoubleArray - _ = metadata.Join -) - -func request_ResourceService_CreateResource_0(ctx context.Context, marshaler runtime.Marshaler, client ResourceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq CreateResourceRequest - metadata runtime.ServerMetadata - ) - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Resource); err != nil && !errors.Is(err, io.EOF) { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - msg, err := client.CreateResource(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_ResourceService_CreateResource_0(ctx context.Context, marshaler runtime.Marshaler, server ResourceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq CreateResourceRequest - metadata runtime.ServerMetadata - ) - if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Resource); err != nil && !errors.Is(err, io.EOF) { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - msg, err := server.CreateResource(ctx, &protoReq) - return msg, metadata, err -} - -func request_ResourceService_ListResources_0(ctx context.Context, marshaler runtime.Marshaler, client ResourceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq ListResourcesRequest - metadata runtime.ServerMetadata - ) - io.Copy(io.Discard, req.Body) - msg, err := client.ListResources(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_ResourceService_ListResources_0(ctx context.Context, marshaler runtime.Marshaler, server ResourceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq ListResourcesRequest - metadata runtime.ServerMetadata - ) - msg, err := server.ListResources(ctx, &protoReq) - return msg, metadata, err -} - -func request_ResourceService_GetResource_0(ctx context.Context, marshaler runtime.Marshaler, client ResourceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq GetResourceRequest - metadata runtime.ServerMetadata - err error - ) - io.Copy(io.Discard, req.Body) - val, ok := pathParams["name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") - } - protoReq.Name, err = runtime.String(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) - } - msg, err := client.GetResource(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_ResourceService_GetResource_0(ctx context.Context, marshaler runtime.Marshaler, server ResourceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq GetResourceRequest - metadata runtime.ServerMetadata - err error - ) - val, ok := pathParams["name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") - } - protoReq.Name, err = runtime.String(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) - } - msg, err := server.GetResource(ctx, &protoReq) - return msg, metadata, err -} - -var filter_ResourceService_GetResourceBinary_0 = &utilities.DoubleArray{Encoding: map[string]int{"name": 0, "filename": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} - -func request_ResourceService_GetResourceBinary_0(ctx context.Context, marshaler runtime.Marshaler, client ResourceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq GetResourceBinaryRequest - metadata runtime.ServerMetadata - err error - ) - io.Copy(io.Discard, req.Body) - val, ok := pathParams["name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") - } - protoReq.Name, err = runtime.String(val) - if err != nil { - 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) - } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ResourceService_GetResourceBinary_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - msg, err := client.GetResourceBinary(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_ResourceService_GetResourceBinary_0(ctx context.Context, marshaler runtime.Marshaler, server ResourceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq GetResourceBinaryRequest - metadata runtime.ServerMetadata - err error - ) - val, ok := pathParams["name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") - } - protoReq.Name, err = runtime.String(val) - if err != nil { - 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) - } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ResourceService_GetResourceBinary_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - msg, err := server.GetResourceBinary(ctx, &protoReq) - return msg, metadata, err -} - -var filter_ResourceService_UpdateResource_0 = &utilities.DoubleArray{Encoding: map[string]int{"resource": 0, "name": 1}, Base: []int{1, 2, 1, 0, 0}, Check: []int{0, 1, 2, 3, 2}} - -func request_ResourceService_UpdateResource_0(ctx context.Context, marshaler runtime.Marshaler, client ResourceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq UpdateResourceRequest - metadata runtime.ServerMetadata - err error - ) - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Resource); err != nil && !errors.Is(err, io.EOF) { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 { - if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Resource); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } else { - protoReq.UpdateMask = fieldMask - } - } - val, ok := pathParams["resource.name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "resource.name") - } - err = runtime.PopulateFieldFromPath(&protoReq, "resource.name", val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "resource.name", err) - } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ResourceService_UpdateResource_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - msg, err := client.UpdateResource(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_ResourceService_UpdateResource_0(ctx context.Context, marshaler runtime.Marshaler, server ResourceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq UpdateResourceRequest - metadata runtime.ServerMetadata - err error - ) - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq.Resource); err != nil && !errors.Is(err, io.EOF) { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if protoReq.UpdateMask == nil || len(protoReq.UpdateMask.GetPaths()) == 0 { - if fieldMask, err := runtime.FieldMaskFromRequestBody(newReader(), protoReq.Resource); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } else { - protoReq.UpdateMask = fieldMask - } - } - val, ok := pathParams["resource.name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "resource.name") - } - err = runtime.PopulateFieldFromPath(&protoReq, "resource.name", val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "resource.name", err) - } - if err := req.ParseForm(); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_ResourceService_UpdateResource_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - msg, err := server.UpdateResource(ctx, &protoReq) - return msg, metadata, err -} - -func request_ResourceService_DeleteResource_0(ctx context.Context, marshaler runtime.Marshaler, client ResourceServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq DeleteResourceRequest - metadata runtime.ServerMetadata - err error - ) - io.Copy(io.Discard, req.Body) - val, ok := pathParams["name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") - } - protoReq.Name, err = runtime.String(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) - } - msg, err := client.DeleteResource(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err -} - -func local_request_ResourceService_DeleteResource_0(ctx context.Context, marshaler runtime.Marshaler, server ResourceServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var ( - protoReq DeleteResourceRequest - metadata runtime.ServerMetadata - err error - ) - val, ok := pathParams["name"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name") - } - protoReq.Name, err = runtime.String(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err) - } - msg, err := server.DeleteResource(ctx, &protoReq) - return msg, metadata, err -} - -// RegisterResourceServiceHandlerServer registers the http handlers for service ResourceService to "mux". -// UnaryRPC :call ResourceServiceServer directly. -// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. -// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterResourceServiceHandlerFromEndpoint instead. -// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. -func RegisterResourceServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ResourceServiceServer) error { - mux.Handle(http.MethodPost, pattern_ResourceService_CreateResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/CreateResource", runtime.WithHTTPPathPattern("/api/v1/resources")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_ResourceService_CreateResource_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_CreateResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodGet, pattern_ResourceService_ListResources_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/ListResources", runtime.WithHTTPPathPattern("/api/v1/resources")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_ResourceService_ListResources_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_ListResources_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodGet, pattern_ResourceService_GetResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResource", runtime.WithHTTPPathPattern("/api/v1/{name=resources/*}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_ResourceService_GetResource_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_GetResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodGet, pattern_ResourceService_GetResourceBinary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResourceBinary", runtime.WithHTTPPathPattern("/file/{name=resources/*}/{filename}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_ResourceService_GetResourceBinary_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_GetResourceBinary_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodPatch, pattern_ResourceService_UpdateResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/UpdateResource", runtime.WithHTTPPathPattern("/api/v1/{resource.name=resources/*}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_ResourceService_UpdateResource_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_UpdateResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodDelete, pattern_ResourceService_DeleteResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.ResourceService/DeleteResource", runtime.WithHTTPPathPattern("/api/v1/{name=resources/*}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_ResourceService_DeleteResource_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_DeleteResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - - return nil -} - -// RegisterResourceServiceHandlerFromEndpoint is same as RegisterResourceServiceHandler but -// automatically dials to "endpoint" and closes the connection when "ctx" gets done. -func RegisterResourceServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { - conn, err := grpc.NewClient(endpoint, opts...) - if err != nil { - return err - } - defer func() { - if err != nil { - if cerr := conn.Close(); cerr != nil { - grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) - } - return - } - go func() { - <-ctx.Done() - if cerr := conn.Close(); cerr != nil { - grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) - } - }() - }() - return RegisterResourceServiceHandler(ctx, mux, conn) -} - -// RegisterResourceServiceHandler registers the http handlers for service ResourceService to "mux". -// The handlers forward requests to the grpc endpoint over "conn". -func RegisterResourceServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { - return RegisterResourceServiceHandlerClient(ctx, mux, NewResourceServiceClient(conn)) -} - -// RegisterResourceServiceHandlerClient registers the http handlers for service ResourceService -// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "ResourceServiceClient". -// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "ResourceServiceClient" -// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in -// "ResourceServiceClient" to call the correct interceptors. This client ignores the HTTP middlewares. -func RegisterResourceServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ResourceServiceClient) error { - mux.Handle(http.MethodPost, pattern_ResourceService_CreateResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/CreateResource", runtime.WithHTTPPathPattern("/api/v1/resources")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_ResourceService_CreateResource_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_CreateResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodGet, pattern_ResourceService_ListResources_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/ListResources", runtime.WithHTTPPathPattern("/api/v1/resources")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_ResourceService_ListResources_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_ListResources_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodGet, pattern_ResourceService_GetResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResource", runtime.WithHTTPPathPattern("/api/v1/{name=resources/*}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_ResourceService_GetResource_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_GetResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodGet, pattern_ResourceService_GetResourceBinary_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/GetResourceBinary", runtime.WithHTTPPathPattern("/file/{name=resources/*}/{filename}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_ResourceService_GetResourceBinary_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_GetResourceBinary_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodPatch, pattern_ResourceService_UpdateResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/UpdateResource", runtime.WithHTTPPathPattern("/api/v1/{resource.name=resources/*}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_ResourceService_UpdateResource_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_UpdateResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - mux.Handle(http.MethodDelete, pattern_ResourceService_DeleteResource_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.ResourceService/DeleteResource", runtime.WithHTTPPathPattern("/api/v1/{name=resources/*}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_ResourceService_DeleteResource_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - forward_ResourceService_DeleteResource_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - }) - return nil -} - -var ( - pattern_ResourceService_CreateResource_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "resources"}, "")) - pattern_ResourceService_ListResources_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "resources"}, "")) - 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, 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_DeleteResource_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "resources", "name"}, "")) -) - -var ( - forward_ResourceService_CreateResource_0 = runtime.ForwardResponseMessage - forward_ResourceService_ListResources_0 = runtime.ForwardResponseMessage - forward_ResourceService_GetResource_0 = runtime.ForwardResponseMessage - forward_ResourceService_GetResourceBinary_0 = runtime.ForwardResponseMessage - forward_ResourceService_UpdateResource_0 = runtime.ForwardResponseMessage - forward_ResourceService_DeleteResource_0 = runtime.ForwardResponseMessage -) diff --git a/proto/gen/api/v1/resource_service_grpc.pb.go b/proto/gen/api/v1/resource_service_grpc.pb.go deleted file mode 100644 index 2a51415fd..000000000 --- a/proto/gen/api/v1/resource_service_grpc.pb.go +++ /dev/null @@ -1,325 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.5.1 -// - protoc (unknown) -// source: api/v1/resource_service.proto - -package apiv1 - -import ( - context "context" - httpbody "google.golang.org/genproto/googleapis/api/httpbody" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - emptypb "google.golang.org/protobuf/types/known/emptypb" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.64.0 or later. -const _ = grpc.SupportPackageIsVersion9 - -const ( - ResourceService_CreateResource_FullMethodName = "/memos.api.v1.ResourceService/CreateResource" - ResourceService_ListResources_FullMethodName = "/memos.api.v1.ResourceService/ListResources" - ResourceService_GetResource_FullMethodName = "/memos.api.v1.ResourceService/GetResource" - ResourceService_GetResourceBinary_FullMethodName = "/memos.api.v1.ResourceService/GetResourceBinary" - ResourceService_UpdateResource_FullMethodName = "/memos.api.v1.ResourceService/UpdateResource" - ResourceService_DeleteResource_FullMethodName = "/memos.api.v1.ResourceService/DeleteResource" -) - -// ResourceServiceClient is the client API for ResourceService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type ResourceServiceClient interface { - // CreateResource creates a new resource. - CreateResource(ctx context.Context, in *CreateResourceRequest, opts ...grpc.CallOption) (*Resource, error) - // ListResources lists all resources. - ListResources(ctx context.Context, in *ListResourcesRequest, opts ...grpc.CallOption) (*ListResourcesResponse, error) - // GetResource returns a resource by name. - GetResource(ctx context.Context, in *GetResourceRequest, opts ...grpc.CallOption) (*Resource, error) - // GetResourceBinary returns a resource binary by name. - GetResourceBinary(ctx context.Context, in *GetResourceBinaryRequest, opts ...grpc.CallOption) (*httpbody.HttpBody, error) - // UpdateResource updates a resource. - UpdateResource(ctx context.Context, in *UpdateResourceRequest, opts ...grpc.CallOption) (*Resource, error) - // DeleteResource deletes a resource by name. - DeleteResource(ctx context.Context, in *DeleteResourceRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) -} - -type resourceServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewResourceServiceClient(cc grpc.ClientConnInterface) ResourceServiceClient { - return &resourceServiceClient{cc} -} - -func (c *resourceServiceClient) CreateResource(ctx context.Context, in *CreateResourceRequest, opts ...grpc.CallOption) (*Resource, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(Resource) - err := c.cc.Invoke(ctx, ResourceService_CreateResource_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *resourceServiceClient) ListResources(ctx context.Context, in *ListResourcesRequest, opts ...grpc.CallOption) (*ListResourcesResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(ListResourcesResponse) - err := c.cc.Invoke(ctx, ResourceService_ListResources_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *resourceServiceClient) GetResource(ctx context.Context, in *GetResourceRequest, opts ...grpc.CallOption) (*Resource, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(Resource) - err := c.cc.Invoke(ctx, ResourceService_GetResource_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *resourceServiceClient) GetResourceBinary(ctx context.Context, in *GetResourceBinaryRequest, opts ...grpc.CallOption) (*httpbody.HttpBody, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(httpbody.HttpBody) - err := c.cc.Invoke(ctx, ResourceService_GetResourceBinary_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *resourceServiceClient) UpdateResource(ctx context.Context, in *UpdateResourceRequest, opts ...grpc.CallOption) (*Resource, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(Resource) - err := c.cc.Invoke(ctx, ResourceService_UpdateResource_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *resourceServiceClient) DeleteResource(ctx context.Context, in *DeleteResourceRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(emptypb.Empty) - err := c.cc.Invoke(ctx, ResourceService_DeleteResource_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ResourceServiceServer is the server API for ResourceService service. -// All implementations must embed UnimplementedResourceServiceServer -// for forward compatibility. -type ResourceServiceServer interface { - // CreateResource creates a new resource. - CreateResource(context.Context, *CreateResourceRequest) (*Resource, error) - // ListResources lists all resources. - ListResources(context.Context, *ListResourcesRequest) (*ListResourcesResponse, error) - // GetResource returns a resource by name. - GetResource(context.Context, *GetResourceRequest) (*Resource, error) - // GetResourceBinary returns a resource binary by name. - GetResourceBinary(context.Context, *GetResourceBinaryRequest) (*httpbody.HttpBody, error) - // UpdateResource updates a resource. - UpdateResource(context.Context, *UpdateResourceRequest) (*Resource, error) - // DeleteResource deletes a resource by name. - DeleteResource(context.Context, *DeleteResourceRequest) (*emptypb.Empty, error) - mustEmbedUnimplementedResourceServiceServer() -} - -// UnimplementedResourceServiceServer must be embedded to have -// forward compatible implementations. -// -// NOTE: this should be embedded by value instead of pointer to avoid a nil -// pointer dereference when methods are called. -type UnimplementedResourceServiceServer struct{} - -func (UnimplementedResourceServiceServer) CreateResource(context.Context, *CreateResourceRequest) (*Resource, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateResource not implemented") -} -func (UnimplementedResourceServiceServer) ListResources(context.Context, *ListResourcesRequest) (*ListResourcesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ListResources not implemented") -} -func (UnimplementedResourceServiceServer) GetResource(context.Context, *GetResourceRequest) (*Resource, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetResource not implemented") -} -func (UnimplementedResourceServiceServer) GetResourceBinary(context.Context, *GetResourceBinaryRequest) (*httpbody.HttpBody, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetResourceBinary not implemented") -} -func (UnimplementedResourceServiceServer) UpdateResource(context.Context, *UpdateResourceRequest) (*Resource, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateResource not implemented") -} -func (UnimplementedResourceServiceServer) DeleteResource(context.Context, *DeleteResourceRequest) (*emptypb.Empty, error) { - return nil, status.Errorf(codes.Unimplemented, "method DeleteResource not implemented") -} -func (UnimplementedResourceServiceServer) mustEmbedUnimplementedResourceServiceServer() {} -func (UnimplementedResourceServiceServer) testEmbeddedByValue() {} - -// UnsafeResourceServiceServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to ResourceServiceServer will -// result in compilation errors. -type UnsafeResourceServiceServer interface { - mustEmbedUnimplementedResourceServiceServer() -} - -func RegisterResourceServiceServer(s grpc.ServiceRegistrar, srv ResourceServiceServer) { - // If the following call pancis, it indicates UnimplementedResourceServiceServer was - // embedded by pointer and is nil. This will cause panics if an - // unimplemented method is ever invoked, so we test this at initialization - // time to prevent it from happening at runtime later due to I/O. - if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { - t.testEmbeddedByValue() - } - s.RegisterService(&ResourceService_ServiceDesc, srv) -} - -func _ResourceService_CreateResource_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(CreateResourceRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ResourceServiceServer).CreateResource(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: ResourceService_CreateResource_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ResourceServiceServer).CreateResource(ctx, req.(*CreateResourceRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _ResourceService_ListResources_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ListResourcesRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ResourceServiceServer).ListResources(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: ResourceService_ListResources_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ResourceServiceServer).ListResources(ctx, req.(*ListResourcesRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _ResourceService_GetResource_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetResourceRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ResourceServiceServer).GetResource(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: ResourceService_GetResource_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ResourceServiceServer).GetResource(ctx, req.(*GetResourceRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _ResourceService_GetResourceBinary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetResourceBinaryRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ResourceServiceServer).GetResourceBinary(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: ResourceService_GetResourceBinary_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ResourceServiceServer).GetResourceBinary(ctx, req.(*GetResourceBinaryRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _ResourceService_UpdateResource_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateResourceRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ResourceServiceServer).UpdateResource(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: ResourceService_UpdateResource_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ResourceServiceServer).UpdateResource(ctx, req.(*UpdateResourceRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _ResourceService_DeleteResource_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(DeleteResourceRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ResourceServiceServer).DeleteResource(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: ResourceService_DeleteResource_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ResourceServiceServer).DeleteResource(ctx, req.(*DeleteResourceRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// ResourceService_ServiceDesc is the grpc.ServiceDesc for ResourceService service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var ResourceService_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "memos.api.v1.ResourceService", - HandlerType: (*ResourceServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "CreateResource", - Handler: _ResourceService_CreateResource_Handler, - }, - { - MethodName: "ListResources", - Handler: _ResourceService_ListResources_Handler, - }, - { - MethodName: "GetResource", - Handler: _ResourceService_GetResource_Handler, - }, - { - MethodName: "GetResourceBinary", - Handler: _ResourceService_GetResourceBinary_Handler, - }, - { - MethodName: "UpdateResource", - Handler: _ResourceService_UpdateResource_Handler, - }, - { - MethodName: "DeleteResource", - Handler: _ResourceService_DeleteResource_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "api/v1/resource_service.proto", -} diff --git a/proto/gen/apidocs.swagger.yaml b/proto/gen/apidocs.swagger.yaml index 1bede9dce..988a7e81b 100644 --- a/proto/gen/apidocs.swagger.yaml +++ b/proto/gen/apidocs.swagger.yaml @@ -4,12 +4,12 @@ info: version: version not set tags: - name: ActivityService + - name: AttachmentService - name: UserService - name: AuthService - name: IdentityProviderService - name: InboxService - name: MarkdownService - - name: ResourceService - name: MemoService - name: ShortcutService - name: WebhookService @@ -52,6 +52,85 @@ paths: type: string tags: - ActivityService + /api/v1/attachments: + get: + summary: ListAttachments lists all attachments. + operationId: AttachmentService_ListAttachments + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ListAttachmentsResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: pageSize + description: |- + Optional. The maximum number of attachments to return. + The service may return fewer than this value. + If unspecified, at most 50 attachments will be returned. + The maximum value is 1000; values above 1000 will be coerced to 1000. + in: query + required: false + type: integer + format: int32 + - name: pageToken + description: |- + Optional. A page token, received from a previous `ListAttachments` call. + Provide this to retrieve the subsequent page. + in: query + required: false + type: string + - name: filter + description: |- + Optional. Filter to apply to the list results. + Example: "type=image/png" or "filename:*.jpg" + Supported operators: =, !=, <, <=, >, >=, : + Supported fields: filename, type, size, create_time, memo + in: query + required: false + type: string + - name: orderBy + description: |- + Optional. The order to sort results by. + Example: "create_time desc" or "filename asc" + in: query + required: false + type: string + tags: + - AttachmentService + post: + summary: CreateAttachment creates a new attachment. + operationId: AttachmentService_CreateAttachment + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1Attachment' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: attachment + description: Required. The attachment to create. + in: body + required: true + schema: + $ref: '#/definitions/v1Attachment' + required: + - attachment + - name: attachmentId + description: |- + Optional. The attachment ID to use for this attachment. + If empty, a unique ID will be generated. + in: query + required: false + type: string + tags: + - AttachmentService /api/v1/auth/signin: post: summary: SignIn signs in the user. @@ -457,41 +536,6 @@ paths: format: int32 tags: - MemoService - /api/v1/resources: - get: - summary: ListResources lists all resources. - operationId: ResourceService_ListResources - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/v1ListResourcesResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - tags: - - ResourceService - post: - summary: CreateResource creates a new resource. - operationId: ResourceService_CreateResource - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/v1Resource' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: resource - in: body - required: true - schema: - $ref: '#/definitions/v1Resource' - tags: - - ResourceService /api/v1/users: get: summary: ListUsers returns a list of users. @@ -760,6 +804,70 @@ paths: $ref: '#/definitions/googlerpcStatus' tags: - WorkspaceService + /api/v1/{attachment.name}: + patch: + summary: UpdateAttachment updates a attachment. + operationId: AttachmentService_UpdateAttachment + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1Attachment' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: attachment.name + description: |- + The name of the attachment. + Format: attachments/{attachment} + in: path + required: true + type: string + pattern: attachments/[^/]+ + - name: attachment + description: Required. The attachment which replaces the attachment on the server. + in: body + required: true + schema: + type: object + properties: + createTime: + type: string + format: date-time + description: Output only. The creation timestamp. + readOnly: true + filename: + type: string + description: The filename of the attachment. + content: + type: string + format: byte + description: Input only. The content of the attachment. + externalLink: + type: string + description: Optional. The external link of the attachment. + type: + type: string + description: The MIME type of the attachment. + size: + type: string + format: int64 + description: Output only. The size of the attachment in bytes. + readOnly: true + memo: + type: string + title: |- + Optional. The related memo. Refer to `Memo.name`. + Format: memos/{memo} + title: Required. The attachment which replaces the attachment on the server. + required: + - filename + - type + - attachment + tags: + - AttachmentService /api/v1/{identityProvider.name}: patch: summary: UpdateIdentityProvider updates an identity provider. @@ -923,11 +1031,11 @@ paths: readOnly: true pinned: type: boolean - resources: + attachments: type: array items: type: object - $ref: '#/definitions/v1Resource' + $ref: '#/definitions/v1Attachment' relations: type: array items: @@ -964,13 +1072,13 @@ paths: - MemoService /api/v1/{name_1}: get: - summary: GetUser gets a user by name. - operationId: UserService_GetUser + summary: GetAttachment returns a attachment by name. + operationId: AttachmentService_GetAttachment responses: "200": description: A successful response. schema: - $ref: '#/definitions/v1User' + $ref: '#/definitions/v1Attachment' default: description: An unexpected error response. schema: @@ -978,24 +1086,17 @@ paths: parameters: - name: name_1 description: |- - Required. The resource name of the user. - Format: users/{user} + Required. The attachment name of the attachment to retrieve. + Format: attachments/{attachment} in: path required: true type: string - pattern: users/[^/]+ - - name: readMask - description: |- - Optional. The fields to return in the response. - If not specified, all fields are returned. - in: query - required: false - type: string + pattern: attachments/[^/]+ tags: - - UserService + - AttachmentService delete: - summary: DeleteUserAccessToken deletes an access token. - operationId: UserService_DeleteUserAccessToken + summary: DeleteUser deletes a user. + operationId: UserService_DeleteUser responses: "200": description: A successful response. @@ -1009,23 +1110,28 @@ paths: parameters: - name: name_1 description: |- - Required. The resource name of the access token to delete. - Format: users/{user}/accessTokens/{access_token} + Required. The resource name of the user to delete. + Format: users/{user} in: path required: true type: string - pattern: users/[^/]+/accessTokens/[^/]+ + pattern: users/[^/]+ + - name: force + description: Optional. If set to true, the user will be deleted even if they have associated data. + in: query + required: false + type: boolean tags: - UserService /api/v1/{name_2}: get: - summary: GetIdentityProvider gets an identity provider. - operationId: IdentityProviderService_GetIdentityProvider + summary: GetUser gets a user by name. + operationId: UserService_GetUser responses: "200": description: A successful response. schema: - $ref: '#/definitions/apiv1IdentityProvider' + $ref: '#/definitions/v1User' default: description: An unexpected error response. schema: @@ -1033,17 +1139,24 @@ paths: parameters: - name: name_2 description: |- - Required. The resource name of the identity provider to get. - Format: identityProviders/{idp} + Required. The resource name of the user. + Format: users/{user} in: path required: true type: string - pattern: identityProviders/[^/]+ + pattern: users/[^/]+ + - name: readMask + description: |- + Optional. The fields to return in the response. + If not specified, all fields are returned. + in: query + required: false + type: string tags: - - IdentityProviderService + - UserService delete: - summary: DeleteIdentityProvider deletes an identity provider. - operationId: IdentityProviderService_DeleteIdentityProvider + summary: DeleteUserAccessToken deletes an access token. + operationId: UserService_DeleteUserAccessToken responses: "200": description: A successful response. @@ -1057,39 +1170,41 @@ paths: parameters: - name: name_2 description: |- - Required. The resource name of the identity provider to delete. - Format: identityProviders/{idp} + Required. The resource name of the access token to delete. + Format: users/{user}/accessTokens/{access_token} in: path required: true type: string - pattern: identityProviders/[^/]+ + pattern: users/[^/]+/accessTokens/[^/]+ tags: - - IdentityProviderService + - UserService /api/v1/{name_3}: get: - summary: GetResource returns a resource by name. - operationId: ResourceService_GetResource + summary: GetIdentityProvider gets an identity provider. + operationId: IdentityProviderService_GetIdentityProvider responses: "200": description: A successful response. schema: - $ref: '#/definitions/v1Resource' + $ref: '#/definitions/apiv1IdentityProvider' default: description: An unexpected error response. schema: $ref: '#/definitions/googlerpcStatus' parameters: - name: name_3 - description: The name of the resource. + description: |- + Required. The resource name of the identity provider to get. + Format: identityProviders/{idp} in: path required: true type: string - pattern: resources/[^/]+ + pattern: identityProviders/[^/]+ tags: - - ResourceService + - IdentityProviderService delete: - summary: DeleteInbox deletes an inbox. - operationId: InboxService_DeleteInbox + summary: DeleteIdentityProvider deletes an identity provider. + operationId: IdentityProviderService_DeleteIdentityProvider responses: "200": description: A successful response. @@ -1102,13 +1217,15 @@ paths: $ref: '#/definitions/googlerpcStatus' parameters: - name: name_3 - description: The name of the inbox to delete. + description: |- + Required. The resource name of the identity provider to delete. + Format: identityProviders/{idp} in: path required: true type: string - pattern: inboxes/[^/]+ + pattern: identityProviders/[^/]+ tags: - - InboxService + - IdentityProviderService /api/v1/{name_4}: get: summary: GetMemo gets a memo. @@ -1132,8 +1249,8 @@ paths: tags: - MemoService delete: - summary: DeleteResource deletes a resource by name. - operationId: ResourceService_DeleteResource + summary: DeleteInbox deletes an inbox. + operationId: InboxService_DeleteInbox responses: "200": description: A successful response. @@ -1146,13 +1263,13 @@ paths: $ref: '#/definitions/googlerpcStatus' parameters: - name: name_4 - description: The name of the resource. + description: The name of the inbox to delete. in: path required: true type: string - pattern: resources/[^/]+ + pattern: inboxes/[^/]+ tags: - - ResourceService + - InboxService /api/v1/{name_5}: get: summary: GetShortcut gets a shortcut by name. @@ -1332,8 +1449,8 @@ paths: tags: - ActivityService delete: - summary: DeleteUser deletes a user. - operationId: UserService_DeleteUser + summary: DeleteAttachment deletes a attachment by name. + operationId: AttachmentService_DeleteAttachment responses: "200": description: A successful response. @@ -1347,19 +1464,63 @@ paths: parameters: - name: name description: |- - Required. The resource name of the user to delete. - Format: users/{user} + Required. The attachment name of the attachment to delete. + Format: attachments/{attachment} in: path required: true type: string - pattern: users/[^/]+ - - name: force - description: Optional. If set to true, the user will be deleted even if they have associated data. - in: query - required: false - type: boolean + pattern: attachments/[^/]+ tags: - - UserService + - AttachmentService + /api/v1/{name}/attachments: + get: + summary: ListMemoAttachments lists attachments for a memo. + operationId: MemoService_ListMemoAttachments + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ListMemoAttachmentsResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: name + description: The name of the memo. + in: path + required: true + type: string + pattern: memos/[^/]+ + tags: + - MemoService + patch: + summary: SetMemoAttachments sets attachments for a memo. + operationId: MemoService_SetMemoAttachments + responses: + "200": + description: A successful response. + schema: + type: object + properties: {} + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/googlerpcStatus' + parameters: + - name: name + description: The name of the memo. + in: path + required: true + type: string + pattern: memos/[^/]+ + - name: body + in: body + required: true + schema: + $ref: '#/definitions/MemoServiceSetMemoAttachmentsBody' + tags: + - MemoService /api/v1/{name}/avatar: get: summary: GetUserAvatar gets the avatar of a user. @@ -1530,55 +1691,6 @@ paths: $ref: '#/definitions/MemoServiceSetMemoRelationsBody' tags: - MemoService - /api/v1/{name}/resources: - get: - summary: ListMemoResources lists resources for a memo. - operationId: MemoService_ListMemoResources - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/v1ListMemoResourcesResponse' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: name - description: The name of the memo. - in: path - required: true - type: string - pattern: memos/[^/]+ - tags: - - MemoService - patch: - summary: SetMemoResources sets resources for a memo. - operationId: MemoService_SetMemoResources - responses: - "200": - description: A successful response. - schema: - type: object - properties: {} - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: name - description: The name of the memo. - in: path - required: true - type: string - pattern: memos/[^/]+ - - name: body - in: body - required: true - schema: - $ref: '#/definitions/MemoServiceSetMemoResourcesBody' - tags: - - MemoService /api/v1/{name}:getSetting: get: summary: GetUserSetting returns the user setting. @@ -1914,55 +2026,6 @@ paths: $ref: '#/definitions/MemoServiceRenameMemoTagBody' tags: - MemoService - /api/v1/{resource.name}: - patch: - summary: UpdateResource updates a resource. - operationId: ResourceService_UpdateResource - responses: - "200": - description: A successful response. - schema: - $ref: '#/definitions/v1Resource' - default: - description: An unexpected error response. - schema: - $ref: '#/definitions/googlerpcStatus' - parameters: - - name: resource.name - description: |- - The name of the resource. - Format: resources/{resource}, resource is the user defined if or uuid. - in: path - required: true - type: string - pattern: resources/[^/]+ - - name: resource - in: body - required: true - schema: - type: object - properties: - createTime: - type: string - format: date-time - readOnly: true - filename: - type: string - content: - type: string - format: byte - externalLink: - type: string - type: - type: string - size: - type: string - format: int64 - memo: - type: string - description: The related memo. Refer to `Memo.name`. - tags: - - ResourceService /api/v1/{setting.name}: patch: summary: Updates a workspace setting. @@ -2248,8 +2311,8 @@ paths: - WebhookService /file/{name}/{filename}: get: - summary: GetResourceBinary returns a resource binary by name. - operationId: ResourceService_GetResourceBinary + summary: GetAttachmentBinary returns a attachment binary by name. + operationId: AttachmentService_GetAttachmentBinary responses: "200": description: A successful response. @@ -2261,23 +2324,25 @@ paths: $ref: '#/definitions/googlerpcStatus' parameters: - name: name - description: The name of the resource. + description: |- + Required. The attachment name of the attachment. + Format: attachments/{attachment} in: path required: true type: string - pattern: resources/[^/]+ + pattern: attachments/[^/]+ - name: filename - description: The filename of the resource. Mainly used for downloading. + description: The filename of the attachment. Mainly used for downloading. in: path required: true type: string - name: thumbnail - description: A flag indicating if the thumbnail version of the resource should be returned + description: Optional. A flag indicating if the thumbnail version of the attachment should be returned. in: query required: false type: boolean tags: - - ResourceService + - AttachmentService definitions: ActivityLevel: type: string @@ -2309,22 +2374,22 @@ definitions: type: string newTag: type: string - MemoServiceSetMemoRelationsBody: + MemoServiceSetMemoAttachmentsBody: type: object properties: - relations: + attachments: type: array items: type: object - $ref: '#/definitions/v1MemoRelation' - MemoServiceSetMemoResourcesBody: + $ref: '#/definitions/v1Attachment' + MemoServiceSetMemoRelationsBody: type: object properties: - resources: + relations: type: array items: type: object - $ref: '#/definitions/v1Resource' + $ref: '#/definitions/v1MemoRelation' MemoServiceUpsertMemoReactionBody: type: object properties: @@ -2570,11 +2635,11 @@ definitions: readOnly: true pinned: type: boolean - resources: + attachments: type: array items: type: object - $ref: '#/definitions/v1Resource' + $ref: '#/definitions/v1Attachment' relations: type: array items: @@ -2961,6 +3026,45 @@ definitions: - TYPE_UNSPECIFIED: Unspecified type. - TYPE_MEMO_COMMENT: Memo comment activity. - TYPE_VERSION_UPDATE: Version update activity. + v1Attachment: + type: object + properties: + name: + type: string + title: |- + The name of the attachment. + Format: attachments/{attachment} + createTime: + type: string + format: date-time + description: Output only. The creation timestamp. + readOnly: true + filename: + type: string + description: The filename of the attachment. + content: + type: string + format: byte + description: Input only. The content of the attachment. + externalLink: + type: string + description: Optional. The external link of the attachment. + type: + type: string + description: The MIME type of the attachment. + size: + type: string + format: int64 + description: Output only. The size of the attachment in bytes. + readOnly: true + memo: + type: string + title: |- + Optional. The related memo. Refer to `Memo.name`. + Format: memos/{memo} + required: + - filename + - type v1AutoLinkNode: type: object properties: @@ -3161,6 +3265,24 @@ definitions: type: integer format: int32 description: The total count of user statistics. + v1ListAttachmentsResponse: + type: object + properties: + attachments: + type: array + items: + type: object + $ref: '#/definitions/v1Attachment' + description: The list of attachments. + nextPageToken: + type: string + description: |- + A token that can be sent as `page_token` to retrieve the next page. + If this field is omitted, there are no subsequent pages. + totalSize: + type: integer + format: int32 + description: The total count of attachments (may be approximate). v1ListIdentityProvidersResponse: type: object properties: @@ -3186,6 +3308,14 @@ definitions: description: |- A token, which can be sent as `page_token` to retrieve the next page. If this field is omitted, there are no subsequent pages. + v1ListMemoAttachmentsResponse: + type: object + properties: + attachments: + type: array + items: + type: object + $ref: '#/definitions/v1Attachment' v1ListMemoCommentsResponse: type: object properties: @@ -3210,14 +3340,6 @@ definitions: items: type: object $ref: '#/definitions/v1MemoRelation' - v1ListMemoResourcesResponse: - type: object - properties: - resources: - type: array - items: - type: object - $ref: '#/definitions/v1Resource' v1ListMemosResponse: type: object properties: @@ -3244,14 +3366,6 @@ definitions: items: type: object $ref: '#/definitions/v1Node' - v1ListResourcesResponse: - type: object - properties: - resources: - type: array - items: - type: object - $ref: '#/definitions/v1Resource' v1ListShortcutsResponse: type: object properties: @@ -3547,34 +3661,6 @@ definitions: type: string params: type: string - v1Resource: - type: object - properties: - name: - type: string - description: |- - The name of the resource. - Format: resources/{resource}, resource is the user defined if or uuid. - readOnly: true - createTime: - type: string - format: date-time - readOnly: true - filename: - type: string - content: - type: string - format: byte - externalLink: - type: string - type: - type: string - size: - type: string - format: int64 - memo: - type: string - description: The related memo. Refer to `Memo.name`. v1RestoreMarkdownNodesRequest: type: object properties: diff --git a/server/router/api/v1/resource_service.go b/server/router/api/v1/attachment_service.go similarity index 71% rename from server/router/api/v1/resource_service.go rename to server/router/api/v1/attachment_service.go index dac251120..d11b7e9ca 100644 --- a/server/router/api/v1/resource_service.go +++ b/server/router/api/v1/attachment_service.go @@ -45,24 +45,41 @@ var SupportedThumbnailMimeTypes = []string{ "image/jpeg", } -func (s *APIV1Service) CreateResource(ctx context.Context, request *v1pb.CreateResourceRequest) (*v1pb.Resource, error) { +func (s *APIV1Service) CreateAttachment(ctx context.Context, request *v1pb.CreateAttachmentRequest) (*v1pb.Attachment, error) { user, err := s.GetCurrentUser(ctx) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err) } + // Validate required fields + if request.Attachment == nil { + return nil, status.Errorf(codes.InvalidArgument, "attachment is required") + } + if request.Attachment.Filename == "" { + return nil, status.Errorf(codes.InvalidArgument, "filename is required") + } + if request.Attachment.Type == "" { + return nil, status.Errorf(codes.InvalidArgument, "type is required") + } + + // Use provided attachment_id or generate a new one + attachmentUID := request.AttachmentId + if attachmentUID == "" { + attachmentUID = shortuuid.New() + } + create := &store.Resource{ - UID: shortuuid.New(), + UID: attachmentUID, CreatorID: user.ID, - Filename: request.Resource.Filename, - Type: request.Resource.Type, + Filename: request.Attachment.Filename, + Type: request.Attachment.Type, } workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get workspace storage setting: %v", err) } - size := binary.Size(request.Resource.Content) + size := binary.Size(request.Attachment.Content) uploadSizeLimit := int(workspaceStorageSetting.UploadSizeLimitMb) * MebiByte if uploadSizeLimit == 0 { uploadSizeLimit = MaxUploadBufferSizeBytes @@ -71,13 +88,14 @@ func (s *APIV1Service) CreateResource(ctx context.Context, request *v1pb.CreateR return nil, status.Errorf(codes.InvalidArgument, "file size exceeds the limit") } create.Size = int64(size) - create.Blob = request.Resource.Content + create.Blob = request.Attachment.Content + if err := SaveResourceBlob(ctx, s.Profile, s.Store, create); err != nil { return nil, status.Errorf(codes.Internal, "failed to save resource blob: %v", err) } - if request.Resource.Memo != nil { - memoUID, err := ExtractMemoUIDFromName(*request.Resource.Memo) + if request.Attachment.Memo != nil { + memoUID, err := ExtractMemoUIDFromName(*request.Attachment.Memo) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) } @@ -85,6 +103,9 @@ func (s *APIV1Service) CreateResource(ctx context.Context, request *v1pb.CreateR if err != nil { return nil, status.Errorf(codes.Internal, "failed to find memo: %v", err) } + if memo == nil { + return nil, status.Errorf(codes.NotFound, "memo not found: %s", *request.Attachment.Memo) + } create.MemoID = &memo.ID } resource, err := s.Store.CreateResource(ctx, create) @@ -92,57 +113,116 @@ func (s *APIV1Service) CreateResource(ctx context.Context, request *v1pb.CreateR return nil, status.Errorf(codes.Internal, "failed to create resource: %v", err) } - return s.convertResourceFromStore(ctx, resource), nil + return s.convertAttachmentFromStore(ctx, resource), nil } -func (s *APIV1Service) ListResources(ctx context.Context, _ *v1pb.ListResourcesRequest) (*v1pb.ListResourcesResponse, error) { +func (s *APIV1Service) ListAttachments(ctx context.Context, request *v1pb.ListAttachmentsRequest) (*v1pb.ListAttachmentsResponse, error) { user, err := s.GetCurrentUser(ctx) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err) } - resources, err := s.Store.ListResources(ctx, &store.FindResource{ + + // Set default page size + pageSize := int(request.PageSize) + if pageSize <= 0 { + pageSize = 50 + } + if pageSize > 1000 { + pageSize = 1000 + } + + // Parse page token for offset + offset := 0 + if request.PageToken != "" { + // Simple implementation: page token is the offset as string + // In production, you might want to use encrypted tokens + if parsed, err := fmt.Sscanf(request.PageToken, "%d", &offset); err != nil || parsed != 1 { + return nil, status.Errorf(codes.InvalidArgument, "invalid page token") + } + } + + findResource := &store.FindResource{ CreatorID: &user.ID, - }) + Limit: &pageSize, + Offset: &offset, + } + + // Basic filter support for common cases + if request.Filter != "" { + // Simple filter parsing - can be enhanced later + // For now, support basic type filtering: "type=image/png" + if strings.HasPrefix(request.Filter, "type=") { + filterType := strings.TrimPrefix(request.Filter, "type=") + // Create a temporary struct to hold type filter + // Since FindResource doesn't have Type field, we'll apply this post-query + _ = filterType // We'll filter after getting results + } + } + + resources, err := s.Store.ListResources(ctx, findResource) if err != nil { return nil, status.Errorf(codes.Internal, "failed to list resources: %v", err) } - response := &v1pb.ListResourcesResponse{} + // Apply type filter if specified + if request.Filter != "" && strings.HasPrefix(request.Filter, "type=") { + filterType := strings.TrimPrefix(request.Filter, "type=") + filteredResources := make([]*store.Resource, 0) + for _, resource := range resources { + if resource.Type == filterType { + filteredResources = append(filteredResources, resource) + } + } + resources = filteredResources + } + + response := &v1pb.ListAttachmentsResponse{} + for _, resource := range resources { - response.Resources = append(response.Resources, s.convertResourceFromStore(ctx, resource)) + response.Attachments = append(response.Attachments, s.convertAttachmentFromStore(ctx, resource)) } + + // For simplicity, set total size to the number of returned resources + // In a full implementation, you'd want a separate count query + response.TotalSize = int32(len(response.Attachments)) + + // Set next page token if we got the full page size (indicating there might be more) + if len(resources) == pageSize { + response.NextPageToken = fmt.Sprintf("%d", offset+pageSize) + } + return response, nil } -func (s *APIV1Service) GetResource(ctx context.Context, request *v1pb.GetResourceRequest) (*v1pb.Resource, error) { - resourceUID, err := ExtractResourceUIDFromName(request.Name) +func (s *APIV1Service) GetAttachment(ctx context.Context, request *v1pb.GetAttachmentRequest) (*v1pb.Attachment, error) { + attachmentUID, err := ExtractAttachmentUIDFromName(request.Name) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid resource id: %v", err) + return nil, status.Errorf(codes.InvalidArgument, "invalid attachment id: %v", err) } - resource, err := s.Store.GetResource(ctx, &store.FindResource{UID: &resourceUID}) + resource, err := s.Store.GetResource(ctx, &store.FindResource{UID: &attachmentUID}) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get resource: %v", err) } if resource == nil { - return nil, status.Errorf(codes.NotFound, "resource not found") + return nil, status.Errorf(codes.NotFound, "attachment not found") } - return s.convertResourceFromStore(ctx, resource), nil + return s.convertAttachmentFromStore(ctx, resource), nil } -func (s *APIV1Service) GetResourceBinary(ctx context.Context, request *v1pb.GetResourceBinaryRequest) (*httpbody.HttpBody, error) { - resourceUID, err := ExtractResourceUIDFromName(request.Name) +func (s *APIV1Service) GetAttachmentBinary(ctx context.Context, request *v1pb.GetAttachmentBinaryRequest) (*httpbody.HttpBody, error) { + attachmentUID, err := ExtractAttachmentUIDFromName(request.Name) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid resource id: %v", err) + return nil, status.Errorf(codes.InvalidArgument, "invalid attachment id: %v", err) } resource, err := s.Store.GetResource(ctx, &store.FindResource{ GetBlob: true, - UID: &resourceUID, + UID: &attachmentUID, }) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get resource: %v", err) } if resource == nil { - return nil, status.Errorf(codes.NotFound, "resource not found") + return nil, status.Errorf(codes.NotFound, "attachment not found") } // Check the related memo visibility. if resource.MemoID != nil { @@ -202,15 +282,15 @@ func (s *APIV1Service) GetResourceBinary(ctx context.Context, request *v1pb.GetR }, nil } -func (s *APIV1Service) UpdateResource(ctx context.Context, request *v1pb.UpdateResourceRequest) (*v1pb.Resource, error) { - resourceUID, err := ExtractResourceUIDFromName(request.Resource.Name) +func (s *APIV1Service) UpdateAttachment(ctx context.Context, request *v1pb.UpdateAttachmentRequest) (*v1pb.Attachment, error) { + attachmentUID, err := ExtractAttachmentUIDFromName(request.Attachment.Name) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid resource id: %v", err) + return nil, status.Errorf(codes.InvalidArgument, "invalid attachment id: %v", err) } if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 { return nil, status.Errorf(codes.InvalidArgument, "update mask is required") } - resource, err := s.Store.GetResource(ctx, &store.FindResource{UID: &resourceUID}) + resource, err := s.Store.GetResource(ctx, &store.FindResource{UID: &attachmentUID}) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get resource: %v", err) } @@ -222,36 +302,36 @@ func (s *APIV1Service) UpdateResource(ctx context.Context, request *v1pb.UpdateR } for _, field := range request.UpdateMask.Paths { if field == "filename" { - update.Filename = &request.Resource.Filename + update.Filename = &request.Attachment.Filename } } if err := s.Store.UpdateResource(ctx, update); err != nil { return nil, status.Errorf(codes.Internal, "failed to update resource: %v", err) } - return s.GetResource(ctx, &v1pb.GetResourceRequest{ - Name: request.Resource.Name, + return s.GetAttachment(ctx, &v1pb.GetAttachmentRequest{ + Name: request.Attachment.Name, }) } -func (s *APIV1Service) DeleteResource(ctx context.Context, request *v1pb.DeleteResourceRequest) (*emptypb.Empty, error) { - resourceUID, err := ExtractResourceUIDFromName(request.Name) +func (s *APIV1Service) DeleteAttachment(ctx context.Context, request *v1pb.DeleteAttachmentRequest) (*emptypb.Empty, error) { + attachmentUID, err := ExtractAttachmentUIDFromName(request.Name) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid resource id: %v", err) + return nil, status.Errorf(codes.InvalidArgument, "invalid attachment id: %v", err) } user, err := s.GetCurrentUser(ctx) if err != nil { return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err) } resource, err := s.Store.GetResource(ctx, &store.FindResource{ - UID: &resourceUID, + UID: &attachmentUID, CreatorID: &user.ID, }) if err != nil { return nil, status.Errorf(codes.Internal, "failed to find resource: %v", err) } if resource == nil { - return nil, status.Errorf(codes.NotFound, "resource not found") + return nil, status.Errorf(codes.NotFound, "attachment not found") } // Delete the resource from the database. if err := s.Store.DeleteResource(ctx, &store.DeleteResource{ @@ -262,16 +342,16 @@ func (s *APIV1Service) DeleteResource(ctx context.Context, request *v1pb.DeleteR return &emptypb.Empty{}, nil } -func (s *APIV1Service) convertResourceFromStore(ctx context.Context, resource *store.Resource) *v1pb.Resource { - resourceMessage := &v1pb.Resource{ - Name: fmt.Sprintf("%s%s", ResourceNamePrefix, resource.UID), +func (s *APIV1Service) convertAttachmentFromStore(ctx context.Context, resource *store.Resource) *v1pb.Attachment { + attachmentMessage := &v1pb.Attachment{ + Name: fmt.Sprintf("%s%s", AttachmentNamePrefix, resource.UID), CreateTime: timestamppb.New(time.Unix(resource.CreatedTs, 0)), Filename: resource.Filename, Type: resource.Type, Size: resource.Size, } if resource.StorageType == storepb.ResourceStorageType_EXTERNAL || resource.StorageType == storepb.ResourceStorageType_S3 { - resourceMessage.ExternalLink = resource.Reference + attachmentMessage.ExternalLink = resource.Reference } if resource.MemoID != nil { memo, _ := s.Store.GetMemo(ctx, &store.FindMemo{ @@ -279,11 +359,11 @@ func (s *APIV1Service) convertResourceFromStore(ctx context.Context, resource *s }) if memo != nil { memoName := fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID) - resourceMessage.Memo = &memoName + attachmentMessage.Memo = &memoName } } - return resourceMessage + return attachmentMessage } // SaveResourceBlob save the blob of resource based on the storage config. diff --git a/server/router/api/v1/memo_resource_service.go b/server/router/api/v1/memo_attachment_service.go similarity index 71% rename from server/router/api/v1/memo_resource_service.go rename to server/router/api/v1/memo_attachment_service.go index c2e0166ef..1be68d688 100644 --- a/server/router/api/v1/memo_resource_service.go +++ b/server/router/api/v1/memo_attachment_service.go @@ -13,7 +13,7 @@ import ( "github.com/usememos/memos/store" ) -func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMemoResourcesRequest) (*emptypb.Empty, error) { +func (s *APIV1Service) SetMemoAttachments(ctx context.Context, request *v1pb.SetMemoAttachmentsRequest) (*emptypb.Empty, error) { memoUID, err := ExtractMemoUIDFromName(request.Name) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) @@ -32,10 +32,10 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe // Delete resources that are not in the request. for _, resource := range resources { found := false - for _, requestResource := range request.Resources { - requestResourceUID, err := ExtractResourceUIDFromName(requestResource.Name) + for _, requestResource := range request.Attachments { + requestResourceUID, err := ExtractAttachmentUIDFromName(requestResource.Name) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid resource name: %v", err) + return nil, status.Errorf(codes.InvalidArgument, "invalid attachment name: %v", err) } if resource.UID == requestResourceUID { found = true @@ -52,12 +52,12 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe } } - slices.Reverse(request.Resources) + slices.Reverse(request.Attachments) // Update resources' memo_id in the request. - for index, resource := range request.Resources { - resourceUID, err := ExtractResourceUIDFromName(resource.Name) + for index, resource := range request.Attachments { + resourceUID, err := ExtractAttachmentUIDFromName(resource.Name) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, "invalid resource name: %v", err) + return nil, status.Errorf(codes.InvalidArgument, "invalid attachment name: %v", err) } tempResource, err := s.Store.GetResource(ctx, &store.FindResource{UID: &resourceUID}) if err != nil { @@ -76,7 +76,7 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe return &emptypb.Empty{}, nil } -func (s *APIV1Service) ListMemoResources(ctx context.Context, request *v1pb.ListMemoResourcesRequest) (*v1pb.ListMemoResourcesResponse, error) { +func (s *APIV1Service) ListMemoAttachments(ctx context.Context, request *v1pb.ListMemoAttachmentsRequest) (*v1pb.ListMemoAttachmentsResponse, error) { memoUID, err := ExtractMemoUIDFromName(request.Name) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) @@ -92,11 +92,11 @@ func (s *APIV1Service) ListMemoResources(ctx context.Context, request *v1pb.List return nil, status.Errorf(codes.Internal, "failed to list resources: %v", err) } - response := &v1pb.ListMemoResourcesResponse{ - Resources: []*v1pb.Resource{}, + response := &v1pb.ListMemoAttachmentsResponse{ + Attachments: []*v1pb.Attachment{}, } for _, resource := range resources { - response.Resources = append(response.Resources, s.convertResourceFromStore(ctx, resource)) + response.Attachments = append(response.Attachments, s.convertAttachmentFromStore(ctx, resource)) } return response, nil } diff --git a/server/router/api/v1/memo_service.go b/server/router/api/v1/memo_service.go index 399ea7197..571bef8d4 100644 --- a/server/router/api/v1/memo_service.go +++ b/server/router/api/v1/memo_service.go @@ -63,13 +63,13 @@ func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoR if err != nil { return nil, err } - if len(request.Memo.Resources) > 0 { - _, err := s.SetMemoResources(ctx, &v1pb.SetMemoResourcesRequest{ - Name: fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID), - Resources: request.Memo.Resources, + if len(request.Memo.Attachments) > 0 { + _, err := s.SetMemoAttachments(ctx, &v1pb.SetMemoAttachmentsRequest{ + Name: fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID), + Attachments: request.Memo.Attachments, }) if err != nil { - return nil, errors.Wrap(err, "failed to set memo resources") + return nil, errors.Wrap(err, "failed to set memo attachments") } } if len(request.Memo.Relations) > 0 { @@ -318,13 +318,13 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR payload := memo.Payload payload.Location = convertLocationToStore(request.Memo.Location) update.Payload = payload - } else if path == "resources" { - _, err := s.SetMemoResources(ctx, &v1pb.SetMemoResourcesRequest{ - Name: request.Memo.Name, - Resources: request.Memo.Resources, + } else if path == "attachments" { + _, err := s.SetMemoAttachments(ctx, &v1pb.SetMemoAttachmentsRequest{ + Name: request.Memo.Name, + Attachments: request.Memo.Attachments, }) if err != nil { - return nil, errors.Wrap(err, "failed to set memo resources") + return nil, errors.Wrap(err, "failed to set memo attachments") } } else if path == "relations" { _, err := s.SetMemoRelations(ctx, &v1pb.SetMemoRelationsRequest{ diff --git a/server/router/api/v1/memo_service_converter.go b/server/router/api/v1/memo_service_converter.go index 9a722e0a5..c8433c3a2 100644 --- a/server/router/api/v1/memo_service_converter.go +++ b/server/router/api/v1/memo_service_converter.go @@ -61,11 +61,11 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem } memoMessage.Relations = listMemoRelationsResponse.Relations - listMemoResourcesResponse, err := s.ListMemoResources(ctx, &v1pb.ListMemoResourcesRequest{Name: name}) + listMemoAttachmentsResponse, err := s.ListMemoAttachments(ctx, &v1pb.ListMemoAttachmentsRequest{Name: name}) if err != nil { - return nil, errors.Wrap(err, "failed to list memo resources") + return nil, errors.Wrap(err, "failed to list memo attachments") } - memoMessage.Resources = listMemoResourcesResponse.Resources + memoMessage.Attachments = listMemoAttachmentsResponse.Attachments listMemoReactionsResponse, err := s.ListMemoReactions(ctx, &v1pb.ListMemoReactionsRequest{Name: name}) if err != nil { diff --git a/server/router/api/v1/resource_name.go b/server/router/api/v1/resource_name.go index d2708a3d0..cf421a257 100644 --- a/server/router/api/v1/resource_name.go +++ b/server/router/api/v1/resource_name.go @@ -13,7 +13,7 @@ const ( WorkspaceSettingNamePrefix = "workspace/settings/" UserNamePrefix = "users/" MemoNamePrefix = "memos/" - ResourceNamePrefix = "resources/" + AttachmentNamePrefix = "attachments/" InboxNamePrefix = "inboxes/" IdentityProviderNamePrefix = "identityProviders/" ActivityNamePrefix = "activities/" @@ -83,9 +83,9 @@ func ExtractMemoUIDFromName(name string) (string, error) { return id, nil } -// ExtractResourceUIDFromName returns the resource UID from a resource name. -func ExtractResourceUIDFromName(name string) (string, error) { - tokens, err := GetNameParentTokens(name, ResourceNamePrefix) +// ExtractAttachmentUIDFromName returns the attachment UID from a resource name. +func ExtractAttachmentUIDFromName(name string) (string, error) { + tokens, err := GetNameParentTokens(name, AttachmentNamePrefix) if err != nil { return "", err } diff --git a/server/router/api/v1/v1.go b/server/router/api/v1/v1.go index 393dc63c3..2cdfe49d2 100644 --- a/server/router/api/v1/v1.go +++ b/server/router/api/v1/v1.go @@ -26,7 +26,7 @@ type APIV1Service struct { v1pb.UnimplementedAuthServiceServer v1pb.UnimplementedUserServiceServer v1pb.UnimplementedMemoServiceServer - v1pb.UnimplementedResourceServiceServer + v1pb.UnimplementedAttachmentServiceServer v1pb.UnimplementedShortcutServiceServer v1pb.UnimplementedInboxServiceServer v1pb.UnimplementedActivityServiceServer @@ -54,7 +54,7 @@ func NewAPIV1Service(secret string, profile *profile.Profile, store *store.Store v1pb.RegisterAuthServiceServer(grpcServer, apiv1Service) v1pb.RegisterUserServiceServer(grpcServer, apiv1Service) v1pb.RegisterMemoServiceServer(grpcServer, apiv1Service) - v1pb.RegisterResourceServiceServer(grpcServer, apiv1Service) + v1pb.RegisterAttachmentServiceServer(grpcServer, apiv1Service) v1pb.RegisterShortcutServiceServer(grpcServer, apiv1Service) v1pb.RegisterInboxServiceServer(grpcServer, apiv1Service) v1pb.RegisterActivityServiceServer(grpcServer, apiv1Service) @@ -95,7 +95,7 @@ func (s *APIV1Service) RegisterGateway(ctx context.Context, echoServer *echo.Ech if err := v1pb.RegisterMemoServiceHandler(ctx, gwMux, conn); err != nil { return err } - if err := v1pb.RegisterResourceServiceHandler(ctx, gwMux, conn); err != nil { + if err := v1pb.RegisterAttachmentServiceHandler(ctx, gwMux, conn); err != nil { return err } if err := v1pb.RegisterShortcutServiceHandler(ctx, gwMux, conn); err != nil { diff --git a/server/router/rss/rss.go b/server/router/rss/rss.go index 64b232040..1d3281cd4 100644 --- a/server/router/rss/rss.go +++ b/server/router/rss/rss.go @@ -136,7 +136,7 @@ func (s *RSSService) generateRSSFromMemoList(ctx context.Context, memoList []*st if resource.StorageType == storepb.ResourceStorageType_EXTERNAL || resource.StorageType == storepb.ResourceStorageType_S3 { enclosure.Url = resource.Reference } else { - enclosure.Url = fmt.Sprintf("%s/file/resources/%s/%s", baseURL, resource.UID, resource.Filename) + enclosure.Url = fmt.Sprintf("%s/file/attachments/%s/%s", baseURL, resource.UID, resource.Filename) } enclosure.Length = strconv.Itoa(int(resource.Size)) enclosure.Type = resource.Type diff --git a/server/server.go b/server/server.go index 8430b87ba..f5e7e83b0 100644 --- a/server/server.go +++ b/server/server.go @@ -73,7 +73,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store return c.String(http.StatusOK, "Service ready.") }) - // Serve frontend resources. + // Serve frontend static files. frontend.NewFrontendService(profile, store).Serve(ctx, echoServer) rootGroup := echoServer.Group("") @@ -82,7 +82,7 @@ func NewServer(ctx context.Context, profile *profile.Profile, store *store.Store rss.NewRSSService(s.Profile, s.Store).RegisterRoutes(rootGroup) grpcServer := grpc.NewServer( - // Override the maximum receiving message size to math.MaxInt32 for uploading large resources. + // Override the maximum receiving message size to math.MaxInt32 for uploading large attachments. grpc.MaxRecvMsgSize(math.MaxInt32), grpc.ChainUnaryInterceptor( apiv1.NewLoggerInterceptor().LoggerInterceptor, diff --git a/web/src/components/MemoAttachmentListView.tsx b/web/src/components/MemoAttachmentListView.tsx new file mode 100644 index 000000000..f8b4e51c2 --- /dev/null +++ b/web/src/components/MemoAttachmentListView.tsx @@ -0,0 +1,95 @@ +import { memo } from "react"; +import { Attachment } from "@/types/proto/api/v1/attachment_service"; +import { cn } from "@/utils"; +import { getAttachmentType, getAttachmentUrl } from "@/utils/attachment"; +import MemoResource from "./MemoResource"; +import showPreviewImageDialog from "./PreviewImageDialog"; + +const MemoAttachmentListView = ({ attachments = [] }: { attachments: Attachment[] }) => { + const mediaAttachments: Attachment[] = []; + const otherAttachments: Attachment[] = []; + + attachments.forEach((attachment) => { + const type = getAttachmentType(attachment); + if (type === "image/*" || type === "video/*") { + mediaAttachments.push(attachment); + return; + } + + otherAttachments.push(attachment); + }); + + const handleImageClick = (imgUrl: string) => { + const imgUrls = mediaAttachments + .filter((attachment) => getAttachmentType(attachment) === "image/*") + .map((attachment) => getAttachmentUrl(attachment)); + const index = imgUrls.findIndex((url) => url === imgUrl); + showPreviewImageDialog(imgUrls, index); + }; + + const MediaCard = ({ attachment, className }: { attachment: Attachment; className?: string }) => { + const type = getAttachmentType(attachment); + const attachmentUrl = getAttachmentUrl(attachment); + + if (type === "image/*") { + return ( + handleImageClick(attachmentUrl)} + decoding="async" + loading="lazy" + /> + ); + } else if (type === "video/*") { + return ( +