commit 5018ce06fc24ffd231e4ce39826144bf5e240c11
parent a869a2a4a1d1d18c69fdcfc9a8264b1d05317fb2
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 15 Oct 2026 08:15:48 -0400
common: Bluesky capture looks each post up under its own author, and finds it on a self-thread page by what is its own (review 2, 5) — a repost is archived under the original's author and rkey, so capturePosts hands each id's archived author over and the capture resolves each author's DID once, asks getPosts under it, and reads an absence as a deletion only from a batch asked under the post's own author (no author known, or one that does not resolve: nothing learned); a 1–2 s gap before every AppView request after the first; the deleted-post sweep leaves another account's posts (reposts) as they were; the shot is the item linking to its own permalink, else the one holding an element whose whole text is the post's, else the only item — two matches are an error, never the wrong shot
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
6 files changed, 210 insertions(+), 59 deletions(-)
diff --git a/common/controller/capturePosts.ts b/common/controller/capturePosts.ts
@@ -145,10 +145,12 @@ export async function capturePosts(
links: string[];
url?: string;
media?: { kind: string; url: string; name?: string }[];
+ author?: string;
};
let archived: Map<string, Archived> | undefined;
const forum = fetcher.platform === "xenforo";
- if ((opts.articles !== false && fetcher.platform === "twitter") || forum) {
+ const bluesky = fetcher.platform === "bluesky";
+ if ((opts.articles !== false && fetcher.platform === "twitter") || forum || bluesky) {
const wanted = new Set(ids);
archived = new Map();
for (const p of await readAllPosts(channelRoot)) {
@@ -157,6 +159,8 @@ export async function capturePosts(
text: p.text,
links: p.links ?? [],
...(forum ? { url: p.url, ...(p.media ? { media: p.media } : {}) } : {}),
+ // Bluesky looks each post up under its own author (a repost's is the original's).
+ ...(bluesky ? { url: p.url, author: p.author } : {}),
});
}
}
diff --git a/common/controller/checkPostAvailability.ts b/common/controller/checkPostAvailability.ts
@@ -164,6 +164,7 @@ export async function checkPostAvailability(
observations = await fetcher.checkAvailability({
ids: batch,
handle,
+ authors: new Map(posts.map((p) => [p.id, p.author])),
signal: signal ?? controller.signal,
onLog: log,
});
diff --git a/common/social/blueskyFetcher.ts b/common/social/blueskyFetcher.ts
@@ -495,8 +495,16 @@ function handleFromUrl(url: string): string | null {
// Bluesky can afford to check an entire channel routinely.
const GET_POSTS_BATCH = 25;
-blueskyFetcher.checkAvailability = async ({ ids, handle, signal, onLog }) => {
+blueskyFetcher.checkAvailability = async ({ ids: asked, handle, authors, signal, onLog }) => {
const out = new Map<string, PostAvailability>();
+ // A repost is archived under the original's author and rkey: looked up
+ // under this account it would be absent and read as deleted. Such posts
+ // are left as they were (release 29 review).
+ const own = (a: string | undefined) => !a || a.replace(/^@/, "").toLowerCase() === handle.replace(/^@/, "").toLowerCase();
+ const ids = asked.filter((id) => own(authors?.get(id)));
+ if (ids.length < asked.length) {
+ onLog?.(`${asked.length - ids.length} post(s) by another account (reposts) left as they were.`);
+ }
if (ids.length === 0) return out;
// The AT-URI needs the account's DID, not its handle.
diff --git a/common/social/blueskyPostCapture.test.ts b/common/social/blueskyPostCapture.test.ts
@@ -11,7 +11,7 @@ import assert from "node:assert/strict";
import { mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
-import { PNG as FAKE_PNG, startFakeBluesky } from "../testing/social/fakeBluesky.mjs";
+import { ACCOUNTS, PNG as FAKE_PNG, startFakeBluesky } from "../testing/social/fakeBluesky.mjs";
import { blueskyEndpoints, onBlueskyEndpoints, BLUESKY_ENDPOINTS } from "./blueskyEndpoints";
import {
blueskyPageGapMs,
@@ -67,16 +67,20 @@ async function setup(opts: { busyTimes?: number } = {}) {
},
pageGapMs: () => 3_500,
imageGapMs: () => 1_200,
+ apiGapMs: () => 800,
pause: async (ms) => {
pauses.push(ms);
},
now: () => new Date("2026-10-15T12:00:00.000Z"),
};
+ // What capturePosts hands over for a Bluesky channel: each id's archived author.
+ const archived = (ids: string[], author = HANDLE) => new Map(ids.map((id) => [id, { text: "", author }]));
const input = (ids: string[], extra: Partial<PostCaptureInput> = {}): PostCaptureInput => ({
ids,
handle: HANDLE,
outDir,
signal: new AbortController().signal,
+ archived: archived(ids),
...extra,
});
return {
@@ -181,7 +185,7 @@ test("a capture: the image post (shot, 2 images, record), the text post, the del
`https://bsky.app/profile/${HANDLE}/post/${TEXT_POST}`,
]);
assert.equal(s.opened(), 1);
- assert.deepEqual(s.pauses, [1_200, 3_500], "an image gap, then the page gap");
+ assert.deepEqual(s.pauses, [800, 1_200, 3_500], "the AppView gap (handle → getPosts), an image gap, then the page gap");
// One handle lookup, ONE getPosts for all three.
const xrpc = s.bsky.requests.filter((r) => r.startsWith("/xrpc/"));
assert.equal(xrpc.length, 2);
@@ -212,6 +216,7 @@ test("a 429 from the AppView is waited out (its Retry-After) and asked again", a
const res = await captureBlueskyPosts(s.input([TEXT_POST], { media: false }), s.deps);
assert.deepEqual(res.outcomes.map((o) => o.state), ["captured"]);
assert.equal(s.pauses[0], 1_000, "Retry-After: 1");
+ assert.equal(s.pauses[1], 800, "then the gap before getPosts");
assert.equal(s.bsky.requests.filter((r) => r.includes("resolveHandle")).length, 2);
} finally {
await s.close();
@@ -223,7 +228,7 @@ test("a 429 that persists stops the run with nothing recorded about the posts",
try {
const res = await captureBlueskyPosts(s.input([TEXT_POST]), { ...s.deps, maxAttempts: 3 });
assert.deepEqual(res.outcomes, []);
- assert.match(res.stoppedEarly ?? "", /Could not resolve .*429/);
+ assert.match(res.stoppedEarly ?? "", /429/);
assert.equal(s.pauses.length, 2, "two waits between three attempts");
} finally {
await s.close();
@@ -238,7 +243,7 @@ test("a cancelled run stops between posts; the rest are left", async () => {
...s.deps,
pause: async (ms) => {
s.pauses.push(ms);
- ctl.abort();
+ if (ms === 3_500) ctl.abort(); // during the gap before the second page
},
};
const res = await captureBlueskyPosts(s.input([TEXT_POST, IMAGE_POST], { signal: ctl.signal, media: false }), deps);
@@ -267,6 +272,79 @@ test("a page that does not show the post is an error; the AppView's liveness sta
}
});
+test("a repost is looked up under its original author, never read as deleted under the channel's account", async () => {
+ const FAN = { handle: "synthfan.bsky.social", did: "did:plc:synthfan00000000000000000", displayName: "Synth Fan" };
+ const bsky = await startFakeBluesky({ accounts: [...ACCOUNTS, FAN] });
+ const s = await setup();
+ try {
+ const deps: BlueskyCaptureDeps = { ...s.deps, fetch: (url, init) => bsky.fetch(url, init) };
+ // The fan's channel archived the baker's post (a repost): its rkey, its author.
+ const res = await captureBlueskyPosts(
+ { ...s.input([TEXT_POST], { media: false }), handle: FAN.handle, archived: new Map([[TEXT_POST, { text: "", author: HANDLE }]]) },
+ deps,
+ );
+ assert.deepEqual(res.outcomes.map((o) => [o.state, o.availability]), [["captured", "available"]]);
+ assert.ok(bsky.requests.some((r) => r.includes(encodeURIComponent(`at://${ACCOUNTS[0].did}/app.bsky.feed.post/${TEXT_POST}`))));
+ assert.ok(!bsky.requests.some((r) => r.includes(encodeURIComponent(FAN.did))), "never asked under the channel's DID");
+ // An author the archive does not name: nothing learned, never `deleted`.
+ const unknown = await captureBlueskyPosts(
+ { ...s.input([DELETED_POST], { media: false, force: true }), archived: new Map() },
+ deps,
+ );
+ assert.deepEqual(unknown.outcomes.map((o) => [o.state, o.availability]), [["error", undefined]]);
+
+ // The deleted-post sweep leaves a repost as it was rather than read its
+ // absence under the channel's account as a deletion.
+ const before = bsky.requests.length;
+ const swept = await blueskyFetcher.checkAvailability!({
+ ids: [TEXT_POST],
+ handle: FAN.handle,
+ authors: new Map([[TEXT_POST, HANDLE]]),
+ signal: new AbortController().signal,
+ });
+ assert.equal(swept.size, 0);
+ assert.equal(bsky.requests.length, before, "nothing asked");
+ } finally {
+ await bsky.close();
+ await s.close();
+ }
+});
+
+test("the post on a self-thread page: its own link, else its whole text; ambiguous is an error, never the wrong shot", async (t) => {
+ let opened;
+ try {
+ opened = await openFreshBlueskyPage();
+ } catch (e) {
+ t.skip(`no headless Chromium on this host: ${(e as Error).message.split("\n")[0].slice(0, 120)}`);
+ return;
+ }
+ const dir = await mkdtemp(path.join(os.tmpdir(), "bsky-thread-"));
+ const item = (text: string, link?: string) =>
+ `<div data-testid="postThreadItem-by-${HANDLE}" style="padding:10px;border:1px solid #ccc;width:500px"><p>${text}</p>${link ? `<a href="${link}">2h</a>` : ""}</div>`;
+ const page = (body: string) => `data:text/html,${encodeURIComponent(`<!doctype html><body>${body}</body>`)}`;
+ const shoot = (html: string, text: string, rkey = "3lreply") =>
+ shootBlueskyPost(opened!.page, { url: page(html), canonicalUrl: "x", handle: HANDLE, rkey, text, dir, signal: new AbortController().signal, postTimeoutMs: 2_000 });
+ const marked = () => opened!.page.evaluate(`document.querySelector("[data-archilyzer-capture] p").innerText`);
+ try {
+ // A short reply under parents that contain its words: the exact text wins.
+ const thread = item("lol that is so true, lol", "https://bsky.app/profile/x/post/3lparent1") + item("lol") + item("lol no", "https://bsky.app/profile/x/post/3lchild");
+ assert.equal((await shoot(thread, "lol")).state, "captured");
+ assert.equal(await marked(), "lol");
+ // An item linking to the post's own permalink wins over text.
+ const linked = item("same words") + item("same words", `https://bsky.app/profile/${HANDLE}/post/3lreply`);
+ assert.equal((await shoot(linked, "same words")).state, "captured");
+ assert.equal(await opened.page.evaluate(`!!document.querySelector("[data-archilyzer-capture] a")`), true);
+ // Two items with the post's whole text and no link: ambiguous, no shot.
+ const twins = item("lol") + item("lol");
+ const r = await shoot(twins, "lol", "3lother");
+ assert.equal(r.state, "error");
+ assert.match(r.error ?? "", /match this one; none shot/);
+ } finally {
+ await opened.close();
+ await rm(dir, { recursive: true, force: true });
+ }
+});
+
// ─── A real browser over the fake's page ───
test("a real headless Chromium shoots the post, cropped to it, over the fake page on loopback", async (t) => {
@@ -284,6 +362,7 @@ test("a real headless Chromium shoots the post, cropped to it, over the fake pag
url: bsky.pageUrl(HANDLE, IMAGE_POST),
canonicalUrl: `https://bsky.app/profile/${HANDLE}/post/${IMAGE_POST}`,
handle: HANDLE,
+ rkey: IMAGE_POST,
text: "The second shop opens in the spring. Small place, big oven.",
dir,
signal: new AbortController().signal,
@@ -299,6 +378,7 @@ test("a real headless Chromium shoots the post, cropped to it, over the fake pag
url: bsky.pageUrl(HANDLE, DELETED_POST),
canonicalUrl: "x",
handle: HANDLE,
+ rkey: DELETED_POST,
text: "",
dir: path.join(dir, "gone"),
signal: new AbortController().signal,
diff --git a/common/social/blueskyPostCapture.ts b/common/social/blueskyPostCapture.ts
@@ -100,8 +100,10 @@ export type BlueskyCaptureDeps = {
// A page in a fresh browser context: opened on the first shot, closed at the
// end of the run.
openPage: () => Promise<{ page: PageLike; close: () => Promise<void> }>;
- // The gap before each page after the first, and between two images.
+ // The gap before each page after the first, before each AppView request
+ // after the first (a handle's DID, a getPosts batch), and between two images.
pageGapMs: () => number;
+ apiGapMs: () => number;
imageGapMs: () => number;
pause: (ms: number, signal: AbortSignal) => Promise<void>;
now?: () => Date;
@@ -161,6 +163,7 @@ export function liveBlueskyCaptureDeps(input: Pick<PostCaptureInput, "pagePauseM
openPage: openFreshBlueskyPage,
pageGapMs: () => blueskyPageGapMs(Math.random, input.pagePauseMs),
imageGapMs: () => 1_000 + Math.round(Math.random() * 1_000),
+ apiGapMs: () => 1_000 + Math.round(Math.random() * 1_000),
pause: sleepUnlessAborted,
};
}
@@ -209,21 +212,37 @@ async function politeGet(
// ─── One page's shot ───
-// The post on its page: the thread items by its author (a self-thread's
-// parents and replies share the test id), the one holding the post's text —
-// or the only one. Marked for the shot; its box in document coordinates.
-const SNAPSHOT_SCRIPT = (handle: string, text: string) => `(() => {
+// The post on its page. A self-thread's parents and replies by the same
+// author share the anchor's test id, and a short reply ("lol") is a substring
+// of many a parent, so the post is found by what is its own and nothing else's:
+// 1. the item holding a link to its own permalink (…/post/<rkey>);
+// 2. else the item holding an element whose whole text IS the post's text;
+// 3. else the only item by the author on the page.
+// Two items matching the same rule are ambiguous: no shot (an error), never a
+// shot of the wrong post. Marked for the shot; its box in document coordinates.
+export const SNAPSHOT_SCRIPT = (handle: string, text: string, rkey: string) => `(() => {
const sel = ${JSON.stringify(`[data-testid="postThreadItem-by-${handle}"]`)};
+ const rkey = ${JSON.stringify(rkey)};
const norm = (s) => (s || "").replace(/\\s+/g, " ").trim().toLowerCase();
- const want = norm(${JSON.stringify(text)}).slice(0, 80);
+ const want = norm(${JSON.stringify(text)});
const all = Array.from(document.querySelectorAll(sel));
- let own = all.length === 1 ? all[0] : null;
- if (!own && want) own = all.find((el) => norm(el.innerText).includes(want)) || null;
+ const ownLink = (el) => Array.from(el.querySelectorAll("a[href]")).some((a) => {
+ try { return new URL(a.getAttribute("href"), location.href).pathname.replace(/\\/+$/, "").endsWith("/post/" + rkey); } catch { return false; }
+ });
+ const exactText = (el) => want !== "" && Array.from(el.querySelectorAll("*")).some((d) => norm(d.innerText) === want);
+ let own = null;
+ let ambiguous = 0;
+ for (const rule of [ownLink, exactText]) {
+ const hits = all.filter(rule);
+ if (hits.length === 1) { own = hits[0]; break; }
+ if (hits.length > 1) { ambiguous = hits.length; break; }
+ }
+ if (!own && !ambiguous && all.length === 1) own = all[0];
for (const el of document.querySelectorAll("[data-archilyzer-capture]")) el.removeAttribute("data-archilyzer-capture");
- if (!own) return { count: all.length, rect: null, text: norm(document.body && document.body.innerText).slice(0, 2000) };
+ if (!own) return { count: all.length, ambiguous, rect: null, text: norm(document.body && document.body.innerText).slice(0, 2000) };
own.setAttribute("data-archilyzer-capture", "");
const r = own.getBoundingClientRect();
- return { count: all.length, rect: { x: r.left + window.scrollX, y: r.top + window.scrollY, width: r.width, height: r.height }, text: "" };
+ return { count: all.length, ambiguous: 0, rect: { x: r.left + window.scrollX, y: r.top + window.scrollY, width: r.width, height: r.height }, text: "" };
})()`;
// Let the post's images finish loading (each capped), so the shot is not of
@@ -238,7 +257,7 @@ const IMAGES_LOADED_SCRIPT = `(() => {
}))).then(() => imgs.length);
})()`;
-type Snapshot = { count: number; rect: { x: number; y: number; width: number; height: number } | null; text: string };
+type Snapshot = { count: number; ambiguous?: number; rect: { x: number; y: number; width: number; height: number } | null; text: string };
export type BlueskyShotResult = {
state: PostCaptureState;
@@ -275,6 +294,8 @@ export async function shootBlueskyPost(
url: string;
canonicalUrl: string;
handle: string;
+ // The post's rkey: an item holding a link to it is the post.
+ rkey: string;
text: string;
dir: string;
signal: AbortSignal;
@@ -303,7 +324,7 @@ export async function shootBlueskyPost(
).catch(() => false);
if (o.signal.aborted) return { state: "error", error: "cancelled" };
if (!appeared) {
- const snap = (await page.evaluate(SNAPSHOT_SCRIPT(o.handle, o.text)).catch(() => null)) as Snapshot | null;
+ const snap = (await page.evaluate(SNAPSHOT_SCRIPT(o.handle, o.text, o.rkey)).catch(() => null)) as Snapshot | null;
const body = snap?.text ?? "";
if (/sign in|log in/.test(body) && /(required|to view|logged-in|signed-in)/.test(body)) {
return { state: "error", error: "The author shows their posts only to signed-in users; the capture has no login." };
@@ -311,13 +332,18 @@ export async function shootBlueskyPost(
return { state: "error", error: `The post did not render (no ${sel} on the page).` };
}
await page.waitForTimeout(1_000);
- let snap = (await page.evaluate(SNAPSHOT_SCRIPT(o.handle, o.text))) as Snapshot;
+ let snap = (await page.evaluate(SNAPSHOT_SCRIPT(o.handle, o.text, o.rkey))) as Snapshot;
if (!snap.rect) {
- return { state: "error", error: `${snap.count} posts by @${o.handle} on the page, none of them this one's text.` };
+ return {
+ state: "error",
+ error: snap.ambiguous
+ ? `${snap.ambiguous} posts by @${o.handle} on the page match this one; none shot rather than the wrong one.`
+ : `${snap.count} posts by @${o.handle} on the page, none of them this one (by its link or its whole text).`,
+ };
}
await page.evaluate(IMAGES_LOADED_SCRIPT).catch(() => {});
// Re-read the box: images that loaded may have grown it.
- snap = (await page.evaluate(SNAPSHOT_SCRIPT(o.handle, o.text))) as Snapshot;
+ snap = (await page.evaluate(SNAPSHOT_SCRIPT(o.handle, o.text, o.rkey))) as Snapshot;
const rect = snap.rect;
if (!rect || rect.width < 1 || rect.height < 1) {
return { state: "error", error: "The post rendered with no size to shoot." };
@@ -397,48 +423,72 @@ export async function captureBlueskyPosts(
}
if (owed.length === 0) return { outcomes };
- // The account's DID: getPosts takes AT-URIs.
+ // EACH POST UNDER ITS OWN AUTHOR. A repost is archived under the original's
+ // rkey and author (normalizeBlueskyItem), so the channel's own DID would not
+ // find it, and its absence would read as a deletion. Each owed post is looked
+ // up as at://<its author's DID>/…/<rkey> (the author from the archive; a
+ // handle resolved once). An absence is a deletion only from a batch asked
+ // under the post's own author; a post whose author is not known, or whose
+ // author did not resolve, learns nothing (never `deleted`).
const appview = deps.endpoints.appview;
- let did = input.handle;
- if (!did.startsWith("did:")) {
- const got = await politeGet(
- deps,
- `${appview}/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(input.handle)}`,
- "application/json",
- signal,
- onLog,
- );
- if (signal.aborted) return stopped("Cancelled; the rest are left for a later run.");
- if (!got.ok) return stopped(`Could not resolve @${input.handle}: ${got.error}. Nothing was recorded.`);
- const body = (await got.res.json().catch(() => null)) as { did?: string } | null;
- if (!body?.did) return stopped(`Could not resolve @${input.handle}: no DID in the answer. Nothing was recorded.`);
- did = body.did;
- }
-
- // Liveness and images, 25 posts a request. A post absent from a batch that
- // answered is deleted; a batch that failed says nothing about its posts.
- const views = new Map<string, BlueskyPostView>();
+ let calls = 0;
+ const apiCall = async (url: string): Promise<Got> => {
+ if (calls++ > 0) await deps.pause(deps.apiGapMs(), signal);
+ if (signal.aborted) return { ok: false, error: "cancelled" };
+ return politeGet(deps, url, "application/json", signal, onLog);
+ };
+ const authorOf = (id: string): string | null => input.archived?.get(id)?.author?.trim().replace(/^@/, "") || null;
+ const byAuthor = new Map<string, typeof owed>();
const unanswered = new Map<string, string>();
- for (let i = 0; i < owed.length; i += GET_POSTS_BATCH) {
- if (signal.aborted) return stopped("Cancelled; the rest are left for a later run.");
- const batch = owed.slice(i, i + GET_POSTS_BATCH);
- const params = new URLSearchParams();
- for (const o of batch) params.append("uris", `at://${did}/app.bsky.feed.post/${o.id}`);
- const got = await politeGet(deps, `${appview}/xrpc/app.bsky.feed.getPosts?${params.toString()}`, "application/json", signal, onLog);
- if (signal.aborted) return stopped("Cancelled; the rest are left for a later run.");
- if (!got.ok) {
- if (got.rateLimited) return stopped(`${got.error}; stopping — the posts are left for a later run.`);
- for (const o of batch) unanswered.set(o.id, `getPosts failed: ${got.error}`);
+ for (const o of owed) {
+ const author = authorOf(o.id);
+ if (!author) {
+ unanswered.set(o.id, "the archive names no author for this post; nothing learned");
continue;
}
- const body = (await got.res.json().catch(() => null)) as { posts?: BlueskyPostView[] } | null;
- if (!body || !Array.isArray(body.posts)) {
- for (const o of batch) unanswered.set(o.id, "getPosts answered no post list");
- continue;
+ const list = byAuthor.get(author) ?? [];
+ list.push(o);
+ byAuthor.set(author, list);
+ }
+ const views = new Map<string, BlueskyPostView>();
+ for (const [author, posts] of byAuthor) {
+ let did = author;
+ if (!did.startsWith("did:")) {
+ const got = await apiCall(`${appview}/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(author)}`);
+ if (signal.aborted) return stopped("Cancelled; the rest are left for a later run.");
+ if (!got.ok && got.rateLimited) return stopped(`${got.error}; stopping — the posts are left for a later run.`);
+ const body = got.ok ? ((await got.res.json().catch(() => null)) as { did?: string } | null) : null;
+ if (!body?.did) {
+ // The account itself did not answer: no evidence about its posts.
+ const why = `could not resolve @${author}: ${got.ok ? "no DID in the answer" : got.error}`;
+ onLog?.(`${why} — ${posts.length} post(s) left as they were.`);
+ for (const o of posts) unanswered.set(o.id, why);
+ continue;
+ }
+ did = body.did;
}
- for (const v of body.posts) {
- const rkey = rkeyOf(v.uri);
- if (rkey) views.set(rkey, v);
+ // Liveness and images, 25 posts a request, a gap between requests.
+ for (let i = 0; i < posts.length; i += GET_POSTS_BATCH) {
+ const batch = posts.slice(i, i + GET_POSTS_BATCH);
+ const params = new URLSearchParams();
+ for (const o of batch) params.append("uris", `at://${did}/app.bsky.feed.post/${o.id}`);
+ const got = await apiCall(`${appview}/xrpc/app.bsky.feed.getPosts?${params.toString()}`);
+ if (signal.aborted) return stopped("Cancelled; the rest are left for a later run.");
+ if (!got.ok) {
+ if (got.rateLimited) return stopped(`${got.error}; stopping — the posts are left for a later run.`);
+ for (const o of batch) unanswered.set(o.id, `getPosts failed: ${got.error}`);
+ continue;
+ }
+ const body = (await got.res.json().catch(() => null)) as { posts?: BlueskyPostView[] } | null;
+ if (!body || !Array.isArray(body.posts)) {
+ for (const o of batch) unanswered.set(o.id, "getPosts answered no post list");
+ continue;
+ }
+ for (const v of body.posts) {
+ const rkey = rkeyOf(v.uri);
+ // Only the answer for the post asked: its own author's record.
+ if (rkey && v.uri === `at://${did}/app.bsky.feed.post/${rkey}`) views.set(rkey, v);
+ }
}
}
@@ -453,7 +503,7 @@ export async function captureBlueskyPosts(
onLog?.(`[${i + 1}/${owed.length}] ${id}`);
const view = views.get(id);
const failedLookup = unanswered.get(id);
- const author = view?.author?.handle || input.handle;
+ const author = view?.author?.handle || authorOf(id) || input.handle;
const canonicalUrl = postPermalink("bluesky", author, id);
let state: PostCaptureState;
@@ -484,6 +534,7 @@ export async function captureBlueskyPosts(
url: onBlueskyEndpoints(`https://bsky.app/profile/${author}/post/${id}`, deps.endpoints),
canonicalUrl,
handle: author,
+ rkey: id,
text: view.record?.text ?? "",
dir,
signal,
diff --git a/common/social/fetchers.ts b/common/social/fetchers.ts
@@ -176,6 +176,10 @@ export type SocialFetcherFields = {
export type PostAvailabilityInput = {
ids: ReadonlyArray<string>;
handle: string;
+ // Each id's author as archived, where it is not the channel's own account
+ // (a repost). A fetcher that looks posts up under the channel's account
+ // must not read such a post's absence as a deletion.
+ authors?: ReadonlyMap<string, string>;
signal: AbortSignal;
onLog?: (line: string) => void;
};
@@ -214,6 +218,9 @@ export type PostCaptureInput = Pick<
// posts: the capture opens the URL and downloads the media).
url?: string;
media?: ReadonlyArray<{ kind: string; url: string; name?: string }>;
+ // The post's author as archived (Bluesky: a repost is archived under the
+ // original's author, which its lookup must name).
+ author?: string;
}
>;
// A soft stop: no new post is started once it fires, and the one in hand