fix: backfill legacy source identities during sync
This commit is contained in:
+4
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user