From 7021036a5ceb5fc80e10ccc40dc358112dd10b8a Mon Sep 17 00:00:00 2001 From: syui Date: Thu, 22 Jan 2026 20:52:07 +0900 Subject: [PATCH] fix post edit --- src/web/lib/auth.ts | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/web/lib/auth.ts b/src/web/lib/auth.ts index e4f5ac3..9bf2cf0 100644 --- a/src/web/lib/auth.ts +++ b/src/web/lib/auth.ts @@ -253,16 +253,42 @@ export async function updatePost( if (!agent) return null try { + // Fetch existing record to preserve translations + let existingTranslations = undefined + let existingCreatedAt = new Date().toISOString() + try { + const existing = await agent.com.atproto.repo.getRecord({ + repo: agent.assertDid, + collection, + rkey, + }) + if (existing.data.value) { + const value = existing.data.value as Record + existingTranslations = value.translations + if (value.createdAt) { + existingCreatedAt = value.createdAt as string + } + } + } catch { + // Record doesn't exist, that's ok + } + + const record: Record = { + $type: collection, + title, + content, + createdAt: existingCreatedAt, + } + + if (existingTranslations) { + record.translations = existingTranslations + } + const result = await agent.com.atproto.repo.putRecord({ repo: agent.assertDid, collection, rkey, - record: { - $type: collection, - title, - content, - createdAt: new Date().toISOString(), - }, + record, }) return { uri: result.data.uri, cid: result.data.cid }