Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 3bae7d22e4c57950e0a55f9ca71b0caf43899c91
parent 81db840129e6023cd3be1fbdbe6fb482564cfc0a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 19:21:11 -0500

review 1 M1: the Add-channel form's "Fetch details" asks X nothing

The gallery-dl X fetcher's probe started gallery-dl against X for one item, as a guest, from a server
action outside any job: no queue, no gap, no alert, no cooldown. It now reads the handle and the
canonical address off the URL, as the Playwright fallback's and Nitter's probes and the form's X-search
branch already did. The other probes were swept: Nitter, Playwright and Instagram make no request;
Bluesky's and a forum thread's are their own platforms'. The gallery-dl fetcher claims every x.com URL,
so the form's yt-dlp probe is never reached for one.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/fetchPosts.test.ts | 41+++++++++++++++++++++++++++++++++++++++++
Mcommon/social/xGalleryDlFetcher.ts | 62+++++++++++++++++++-------------------------------------------
2 files changed, 60 insertions(+), 43 deletions(-)

diff --git a/common/controller/fetchPosts.test.ts b/common/controller/fetchPosts.test.ts @@ -661,3 +661,44 @@ test("a sync still stops at known posts, and a full re-walk still reads through assert.equal(full.result.complete, true); assert.equal((await readPostFetchState(root))?.backfill, undefined); }); + +// ── review 1 M1: the Add-channel form's "Fetch details" asks X nothing ───── + +test("M1: no fetcher of the twitter platform probes X — the answer is read off the URL, no binary is started and no request made", async () => { + const { detectSocialFetcher } = await import("../social/fetchers"); + await import("../social/xGalleryDlFetcher"); + await import("../social/xPlaywrightFetcher"); + await import("../social/xNitterFetcher"); + const { xGalleryDlFetcher } = await import("../social/xGalleryDlFetcher"); + const { xPlaywrightFetcher } = await import("../social/xPlaywrightFetcher"); + const { xNitterFetcher } = await import("../social/xNitterFetcher"); + const spawned = async () => (await readFile(ARGS_LOG, "utf8")).trim().split("\n").length; + const before = await spawned(); + // Any request would throw here too: the suite runs with the network refused (lib/noNetwork.mjs). + const realFetch = globalThis.fetch; + let fetched = 0; + globalThis.fetch = (async () => { + fetched++; + throw new Error("a probe made a request"); + }) as typeof fetch; + try { + // The form's own choice for an x.com URL is the gallery-dl fetcher. + assert.equal(detectSocialFetcher("https://x.com/faketester")?.id, "x-gallery-dl"); + for (const fetcher of [xGalleryDlFetcher, xPlaywrightFetcher, xNitterFetcher]) { + assert.equal(fetcher.platform, "twitter"); + for (const url of ["https://x.com/faketester", "https://twitter.com/faketester/", "https://x.com/faketester/with_replies"]) { + assert.deepEqual(await fetcher.probe(url), { ok: true, name: "faketester", handle: "faketester", url: "https://x.com/faketester" }, `${fetcher.id} ${url}`); + } + } + // Not an account: refused from the URL alone. + for (const url of ["https://x.com/", "https://x.com/home", "https://x.com/i/trending/1900000000000000001"]) { + const r = await xGalleryDlFetcher.probe(url); + assert.equal(r.ok, false, url); + assert.match(r.error ?? "", /handle/); + } + } finally { + globalThis.fetch = realFetch; + } + assert.equal(fetched, 0); + assert.equal(await spawned(), before, "gallery-dl was not started"); +}); diff --git a/common/social/xGalleryDlFetcher.ts b/common/social/xGalleryDlFetcher.ts @@ -65,6 +65,7 @@ import { type PostMediaDownloadArgs, type PostFetchInput, type PostFetchResult, + handleFromAccountUrl, type SocialFetcher, type SocialFetcherProbe, type SearchPostFetchInput, @@ -1337,6 +1338,13 @@ async function walkSearchWindows( } } +// The account an X address names (x.com/<handle>[/…]), or null: X's handle +// alphabet only, and none of the paths that are not accounts. +export function xAccountHandleOf(url: string): string | null { + const handle = handleFromAccountUrl(url); + return handle && /^[A-Za-z0-9_]{1,50}$/.test(handle) ? handle : null; +} + export const xGalleryDlFetcher: SocialFetcher = { id: "x-gallery-dl", label: "X / Twitter (gallery-dl)", @@ -1357,50 +1365,18 @@ export const xGalleryDlFetcher: SocialFetcher = { } }, - // A cheap liveness probe: read a single item. There is no free unauthenticated - // X metadata endpoint, so unlike Bluesky this genuinely spawns the binary. + // NO REQUEST (review 1 of lane x-followups, M1). The Add-channel form's + // "Fetch details" calls this from a server action, outside any job: it used + // to start gallery-dl against X for one item, as a guest, with no queue, no + // gap, no alert and no cooldown. X is asked only by the editor's jobs + // (controller/fetchPosts.ts X_ONLY_AS_A_JOB), so the handle and the + // canonical address are read off the URL — what the Playwright fallback's + // and Nitter's probes, and the form's X-search branch, already do. Whether + // the account exists is learned by the channel's first fetch, which is a job. async probe(url: string): Promise<SocialFetcherProbe> { - const bin = getPaths().galleryDlBin; - try { - const res = await execa( - bin, - buildGalleryDlArgs({ accountUrl: url, limit: 1 }), - { reject: false, timeout: 60_000 }, - ); - if (res.exitCode !== 0) { - const err = `${res.stderr ?? ""}`.trim().split("\n").slice(-3).join(" "); - return { - ok: false, - error: looksLikeAuthFailure(err) - ? `gallery-dl needs X credentials (configure cookies-from-browser): ${err}` - : err || `gallery-dl exited ${res.exitCode}`, - }; - } - const records = parseGalleryDlOutput(res.stdout ?? ""); - const first = records[0]; - const author = - first && typeof first === "object" - ? ((first.author as Record<string, unknown> | undefined) ?? undefined) - : undefined; - const handle = - (typeof author?.name === "string" ? author.name : undefined) ?? - (typeof first?.screen_name === "string" ? first.screen_name : undefined); - const nick = typeof author?.nick === "string" ? author.nick : undefined; - return { - ok: true, - name: nick ?? handle, - handle, - url: handle ? `https://x.com/${handle}` : url, - }; - } catch (err) { - const message = (err as Error).message; - return { - ok: false, - error: /ENOENT/.test(message) - ? `gallery-dl not found (looked for "${bin}"; set GALLERY_DL_BIN)` - : message, - }; - } + const handle = xAccountHandleOf(url); + if (!handle) return { ok: false, error: "Could not read an X handle from that URL" }; + return { ok: true, name: handle, handle, url: `https://x.com/${handle}` }; }, async fetch(input: PostFetchInput): Promise<PostFetchResult> {