From cbbb585b2e9a631f48d84ed6db740ed4103ae623 Mon Sep 17 00:00:00 2001 From: lif <1835304752@qq.com> Date: Sun, 4 Jan 2026 19:17:14 +0800 Subject: [PATCH] fix(frontend): ensure attachments are properly linked when creating memos (#5428) Co-authored-by: Claude Opus 4.5 --- .../components/MemoEditor/services/memoService.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/src/components/MemoEditor/services/memoService.ts b/web/src/components/MemoEditor/services/memoService.ts index 204852ff0..53b553293 100644 --- a/web/src/components/MemoEditor/services/memoService.ts +++ b/web/src/components/MemoEditor/services/memoService.ts @@ -2,11 +2,21 @@ import { create } from "@bufbuild/protobuf"; import { FieldMaskSchema, timestampDate, timestampFromDate } from "@bufbuild/protobuf/wkt"; import { isEqual } from "lodash-es"; import { memoServiceClient } from "@/connect"; +import type { Attachment } from "@/types/proto/api/v1/attachment_service_pb"; +import { AttachmentSchema } from "@/types/proto/api/v1/attachment_service_pb"; import type { Memo } from "@/types/proto/api/v1/memo_service_pb"; import { MemoSchema } from "@/types/proto/api/v1/memo_service_pb"; import type { EditorState } from "../state"; import { uploadService } from "./uploadService"; +/** + * Converts attachments to reference format for API requests. + * The backend only needs the attachment name to link it to a memo. + */ +function toAttachmentReferences(attachments: Attachment[]): Attachment[] { + return attachments.map((a) => create(AttachmentSchema, { name: a.name })); +} + function buildUpdateMask( prevMemo: Memo, state: EditorState, @@ -28,7 +38,7 @@ function buildUpdateMask( } if (!isEqual(allAttachments, prevMemo.attachments)) { mask.add("attachments"); - patch.attachments = allAttachments; + patch.attachments = toAttachmentReferences(allAttachments); } if (!isEqual(state.metadata.relations, prevMemo.relations)) { mask.add("relations"); @@ -95,7 +105,7 @@ export const memoService = { const memoData = create(MemoSchema, { content: state.content, visibility: state.metadata.visibility, - attachments: allAttachments, + attachments: toAttachmentReferences(allAttachments), relations: state.metadata.relations, location: state.metadata.location, createTime: state.timestamps.createTime ? timestampFromDate(state.timestamps.createTime) : undefined,