@@ -2,11 +2,21 @@ import { create } from "@bufbuild/protobuf";
22import { FieldMaskSchema , timestampDate , timestampFromDate } from "@bufbuild/protobuf/wkt" ;
33import { isEqual } from "lodash-es" ;
44import { memoServiceClient } from "@/connect" ;
5+ import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb" ;
6+ import { AttachmentSchema } from "@/types/proto/api/v1/attachment_service_pb" ;
57import type { Memo } from "@/types/proto/api/v1/memo_service_pb" ;
68import { MemoSchema } from "@/types/proto/api/v1/memo_service_pb" ;
79import type { EditorState } from "../state" ;
810import { uploadService } from "./uploadService" ;
911
12+ /**
13+ * Converts attachments to reference format for API requests.
14+ * The backend only needs the attachment name to link it to a memo.
15+ */
16+ function toAttachmentReferences ( attachments : Attachment [ ] ) : Attachment [ ] {
17+ return attachments . map ( ( a ) => create ( AttachmentSchema , { name : a . name } ) ) ;
18+ }
19+
1020function buildUpdateMask (
1121 prevMemo : Memo ,
1222 state : EditorState ,
@@ -28,7 +38,7 @@ function buildUpdateMask(
2838 }
2939 if ( ! isEqual ( allAttachments , prevMemo . attachments ) ) {
3040 mask . add ( "attachments" ) ;
31- patch . attachments = allAttachments ;
41+ patch . attachments = toAttachmentReferences ( allAttachments ) ;
3242 }
3343 if ( ! isEqual ( state . metadata . relations , prevMemo . relations ) ) {
3444 mask . add ( "relations" ) ;
@@ -95,7 +105,7 @@ export const memoService = {
95105 const memoData = create ( MemoSchema , {
96106 content : state . content ,
97107 visibility : state . metadata . visibility ,
98- attachments : allAttachments ,
108+ attachments : toAttachmentReferences ( allAttachments ) ,
99109 relations : state . metadata . relations ,
100110 location : state . metadata . location ,
101111 createTime : state . timestamps . createTime ? timestampFromDate ( state . timestamps . createTime ) : undefined ,
0 commit comments