From 21b0c4d4e0d8cfa4795384d1749e36970aa780d8 Mon Sep 17 00:00:00 2001 From: tangsongdayo Date: Sun, 19 Jul 2026 04:55:25 +0800 Subject: [PATCH] fix: backfill legacy source identities during sync --- worker/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/worker/index.ts b/worker/index.ts index 8e4178b..2eb0612 100644 --- a/worker/index.ts +++ b/worker/index.ts @@ -48,8 +48,9 @@ async function upsertRemote(source: Source, memo: any) { } async function pull(source: Source) { - const token = decrypt(source.token_encrypted); const rules = { creator: source.remote_user, tags: JSON.parse(source.sync_tags_json || "[]") as string[], from: source.sync_from, to: source.sync_to, attachmentMode: source.sync_attachment_mode }; - const [memos, identity] = await Promise.all([listMemos(source.base_url, token, rules), getMemosIdentity(source.base_url, token)]); + const token = decrypt(source.token_encrypted); const identity = await getMemosIdentity(source.base_url, token); const creator = source.remote_user || identity.name; + const rules = { creator, tags: JSON.parse(source.sync_tags_json || "[]") as string[], from: source.sync_from, to: source.sync_to, attachmentMode: source.sync_attachment_mode }; + const memos = await listMemos(source.base_url, token, rules); for (const memo of memos) await upsertRemote(source, memo); const names = memos.map((memo) => memo.name); if (names.length) { const placeholders = names.map(() => "?").join(","); db.prepare(`UPDATE posts SET hidden=1,updated_at=CURRENT_TIMESTAMP WHERE source_id=? AND remote_memo_name IS NOT NULL AND remote_memo_name NOT IN (${placeholders})`).run(source.id, ...names); } @@ -57,7 +58,7 @@ async function pull(source: Source) { await cleanupCache(source); const avatar = identity.avatarUrl || identity.avatar || null; const avatarUrl = avatar?.startsWith("/") ? `${source.base_url.replace(/\/$/, "")}${avatar}` : avatar; const name = identity.nickname || identity.username || identity.name; - db.prepare("UPDATE sources SET name=?,sync_status='synced',last_synced_at=CURRENT_TIMESTAMP,last_error=NULL,last_connection_at=CURRENT_TIMESTAMP,last_connection_error=NULL,remote_display_name=?,remote_avatar_url=? WHERE id=?").run(name, name, avatarUrl, source.id); + db.prepare("UPDATE sources SET name=?,remote_user=?,sync_status='synced',last_synced_at=CURRENT_TIMESTAMP,last_error=NULL,last_connection_at=CURRENT_TIMESTAMP,last_connection_error=NULL,remote_display_name=?,remote_avatar_url=? WHERE id=?").run(name, creator, name, avatarUrl, source.id); } async function push(source: Source, payload: any) {