mirror of
https://github.com/usememos/memos.git
synced 2025-12-17 14:19:17 +08:00
Remove previous variable from attachment API message
This commit is contained in:
parent
9666fb17a7
commit
55025e1382
7 changed files with 13 additions and 73 deletions
|
|
@ -84,9 +84,6 @@ message Attachment {
|
|||
// Optional. The related memo. Refer to `Memo.name`.
|
||||
// Format: memos/{memo}
|
||||
optional string memo = 8 [(google.api.field_behavior) = OPTIONAL];
|
||||
|
||||
// Optional. Output only. Whether to use thumbnails for this attachment when stored in S3.
|
||||
optional bool use_thumbnail_for_s3_image = 9 [(google.api.field_behavior) = OUTPUT_ONLY];
|
||||
}
|
||||
|
||||
message CreateAttachmentRequest {
|
||||
|
|
|
|||
|
|
@ -45,11 +45,9 @@ type Attachment struct {
|
|||
Size int64 `protobuf:"varint,7,opt,name=size,proto3" json:"size,omitempty"`
|
||||
// Optional. The related memo. Refer to `Memo.name`.
|
||||
// Format: memos/{memo}
|
||||
Memo *string `protobuf:"bytes,8,opt,name=memo,proto3,oneof" json:"memo,omitempty"`
|
||||
// Optional. Output only. Whether to use thumbnails for this attachment when stored in S3.
|
||||
UseThumbnailForS3Image *bool `protobuf:"varint,9,opt,name=use_thumbnail_for_s3_image,json=useThumbnailForS3Image,proto3,oneof" json:"use_thumbnail_for_s3_image,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
Memo *string `protobuf:"bytes,8,opt,name=memo,proto3,oneof" json:"memo,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *Attachment) Reset() {
|
||||
|
|
@ -138,13 +136,6 @@ func (x *Attachment) GetMemo() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (x *Attachment) GetUseThumbnailForS3Image() bool {
|
||||
if x != nil && x.UseThumbnailForS3Image != nil {
|
||||
return *x.UseThumbnailForS3Image
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type CreateAttachmentRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
// Required. The attachment to create.
|
||||
|
|
@ -558,7 +549,7 @@ 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\"\xe0\x03\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\"\xfb\x02\n" +
|
||||
"\n" +
|
||||
"Attachment\x12\x17\n" +
|
||||
"\x04name\x18\x01 \x01(\tB\x03\xe0A\bR\x04name\x12@\n" +
|
||||
|
|
@ -569,12 +560,10 @@ const file_api_v1_attachment_service_proto_rawDesc = "" +
|
|||
"\rexternal_link\x18\x05 \x01(\tB\x03\xe0A\x01R\fexternalLink\x12\x17\n" +
|
||||
"\x04type\x18\x06 \x01(\tB\x03\xe0A\x02R\x04type\x12\x17\n" +
|
||||
"\x04size\x18\a \x01(\x03B\x03\xe0A\x03R\x04size\x12\x1c\n" +
|
||||
"\x04memo\x18\b \x01(\tB\x03\xe0A\x01H\x00R\x04memo\x88\x01\x01\x12D\n" +
|
||||
"\x1ause_thumbnail_for_s3_image\x18\t \x01(\bB\x03\xe0A\x03H\x01R\x16useThumbnailForS3Image\x88\x01\x01:O\xeaAL\n" +
|
||||
"\x04memo\x18\b \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_memoB\x1d\n" +
|
||||
"\x1b_use_thumbnail_for_s3_image\"\x82\x01\n" +
|
||||
"\x05_memo\"\x82\x01\n" +
|
||||
"\x17CreateAttachmentRequest\x12=\n" +
|
||||
"\n" +
|
||||
"attachment\x18\x01 \x01(\v2\x18.memos.api.v1.AttachmentB\x03\xe0A\x02R\n" +
|
||||
|
|
|
|||
|
|
@ -2166,10 +2166,6 @@ components:
|
|||
memo:
|
||||
type: string
|
||||
description: "Optional. The related memo. Refer to `Memo.name`.\r\n Format: memos/{memo}"
|
||||
useThumbnailForS3Image:
|
||||
readOnly: true
|
||||
type: boolean
|
||||
description: Optional. Output only. Whether to use thumbnails for this attachment when stored in S3.
|
||||
CreateSessionRequest:
|
||||
type: object
|
||||
properties:
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ func (s *APIV1Service) CreateAttachment(ctx context.Context, request *v1pb.Creat
|
|||
return nil, status.Errorf(codes.Internal, "failed to create attachment: %v", err)
|
||||
}
|
||||
|
||||
return convertAttachmentFromStore(attachment, workspaceStorageSetting), nil
|
||||
return convertAttachmentFromStore(attachment), nil
|
||||
}
|
||||
|
||||
func (s *APIV1Service) ListAttachments(ctx context.Context, request *v1pb.ListAttachmentsRequest) (*v1pb.ListAttachmentsResponse, error) {
|
||||
|
|
@ -161,15 +161,10 @@ func (s *APIV1Service) ListAttachments(ctx context.Context, request *v1pb.ListAt
|
|||
return nil, status.Errorf(codes.Internal, "failed to list attachments: %v", err)
|
||||
}
|
||||
|
||||
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get workspace storage setting: %v", err)
|
||||
}
|
||||
|
||||
response := &v1pb.ListAttachmentsResponse{}
|
||||
|
||||
for _, attachment := range attachments {
|
||||
response.Attachments = append(response.Attachments, convertAttachmentFromStore(attachment, workspaceStorageSetting))
|
||||
response.Attachments = append(response.Attachments, convertAttachmentFromStore(attachment))
|
||||
}
|
||||
|
||||
// For simplicity, set total size to the number of returned attachments.
|
||||
|
|
@ -196,11 +191,7 @@ func (s *APIV1Service) GetAttachment(ctx context.Context, request *v1pb.GetAttac
|
|||
if attachment == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "attachment not found")
|
||||
}
|
||||
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get workspace storage setting: %v", err)
|
||||
}
|
||||
return convertAttachmentFromStore(attachment, workspaceStorageSetting), nil
|
||||
return convertAttachmentFromStore(attachment), nil
|
||||
}
|
||||
|
||||
func (s *APIV1Service) GetAttachmentBinary(ctx context.Context, request *v1pb.GetAttachmentBinaryRequest) (*httpbody.HttpBody, error) {
|
||||
|
|
@ -390,7 +381,7 @@ func (s *APIV1Service) DeleteAttachment(ctx context.Context, request *v1pb.Delet
|
|||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func convertAttachmentFromStore(attachment *store.Attachment, workspaceStorageSetting *storepb.WorkspaceStorageSetting) *v1pb.Attachment {
|
||||
func convertAttachmentFromStore(attachment *store.Attachment) *v1pb.Attachment {
|
||||
attachmentMessage := &v1pb.Attachment{
|
||||
Name: fmt.Sprintf("%s%s", AttachmentNamePrefix, attachment.UID),
|
||||
CreateTime: timestamppb.New(time.Unix(attachment.CreatedTs, 0)),
|
||||
|
|
@ -406,12 +397,6 @@ func convertAttachmentFromStore(attachment *store.Attachment, workspaceStorageSe
|
|||
attachmentMessage.ExternalLink = attachment.Reference
|
||||
}
|
||||
|
||||
// Populate use_thumbnail_for_s3_image based on workspace setting and storage type
|
||||
if attachment.StorageType == storepb.AttachmentStorageType_S3 && workspaceStorageSetting != nil {
|
||||
useThumbnail := workspaceStorageSetting.EnableS3ImageThumbnails
|
||||
attachmentMessage.UseThumbnailForS3Image = &useThumbnail
|
||||
}
|
||||
|
||||
return attachmentMessage
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,16 +92,11 @@ func (s *APIV1Service) ListMemoAttachments(ctx context.Context, request *v1pb.Li
|
|||
return nil, status.Errorf(codes.Internal, "failed to list attachments: %v", err)
|
||||
}
|
||||
|
||||
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to get workspace storage setting: %v", err)
|
||||
}
|
||||
|
||||
response := &v1pb.ListMemoAttachmentsResponse{
|
||||
Attachments: []*v1pb.Attachment{},
|
||||
}
|
||||
for _, attachment := range attachments {
|
||||
response.Attachments = append(response.Attachments, convertAttachmentFromStore(attachment, workspaceStorageSetting))
|
||||
response.Attachments = append(response.Attachments, convertAttachmentFromStore(attachment))
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,11 +23,6 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
|
|||
displayTs = memo.UpdatedTs
|
||||
}
|
||||
|
||||
workspaceStorageSetting, err := s.Store.GetWorkspaceStorageSetting(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to get workspace storage setting")
|
||||
}
|
||||
|
||||
name := fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID)
|
||||
memoMessage := &v1pb.Memo{
|
||||
Name: name,
|
||||
|
|
@ -67,7 +62,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
|
|||
memoMessage.Attachments = []*v1pb.Attachment{}
|
||||
|
||||
for _, attachment := range attachments {
|
||||
attachmentResponse := convertAttachmentFromStore(attachment, workspaceStorageSetting)
|
||||
attachmentResponse := convertAttachmentFromStore(attachment)
|
||||
memoMessage.Attachments = append(memoMessage.Attachments, attachmentResponse)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,11 +37,7 @@ export interface Attachment {
|
|||
* Optional. The related memo. Refer to `Memo.name`.
|
||||
* Format: memos/{memo}
|
||||
*/
|
||||
memo?:
|
||||
| string
|
||||
| undefined;
|
||||
/** Optional. Output only. Whether to use thumbnails for this attachment when stored in S3. */
|
||||
useThumbnailForS3Image?: boolean | undefined;
|
||||
memo?: string | undefined;
|
||||
}
|
||||
|
||||
export interface CreateAttachmentRequest {
|
||||
|
|
@ -142,7 +138,6 @@ function createBaseAttachment(): Attachment {
|
|||
type: "",
|
||||
size: 0,
|
||||
memo: undefined,
|
||||
useThumbnailForS3Image: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -172,9 +167,6 @@ export const Attachment: MessageFns<Attachment> = {
|
|||
if (message.memo !== undefined) {
|
||||
writer.uint32(66).string(message.memo);
|
||||
}
|
||||
if (message.useThumbnailForS3Image !== undefined) {
|
||||
writer.uint32(72).bool(message.useThumbnailForS3Image);
|
||||
}
|
||||
return writer;
|
||||
},
|
||||
|
||||
|
|
@ -249,14 +241,6 @@ export const Attachment: MessageFns<Attachment> = {
|
|||
message.memo = reader.string();
|
||||
continue;
|
||||
}
|
||||
case 9: {
|
||||
if (tag !== 72) {
|
||||
break;
|
||||
}
|
||||
|
||||
message.useThumbnailForS3Image = reader.bool();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ((tag & 7) === 4 || tag === 0) {
|
||||
break;
|
||||
|
|
@ -279,7 +263,6 @@ export const Attachment: MessageFns<Attachment> = {
|
|||
message.type = object.type ?? "";
|
||||
message.size = object.size ?? 0;
|
||||
message.memo = object.memo ?? undefined;
|
||||
message.useThumbnailForS3Image = object.useThumbnailForS3Image ?? undefined;
|
||||
return message;
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue