Something went wrong. Try again.
add or update alt text on your media forked from psingletary.com/verifier
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160/** * Post scanner utility — enumerates app.bsky.feed.post records directly * from the user's PDS (com.atproto.repo.listRecords), extracting embed * metadata and flagging any media that lacks alt text. * * Detection covers three embed shapes: * - app.bsky.embed.images (any images[i].alt empty/missing) * - app.bsky.embed.recordWithMedia (its media is an images embed w/ empty alt) * - app.bsky.embed.video (embed.alt empty/missing) * * The scan is resumable: each page is surfaced via onPage() with the * current cursor and hit count so the caller can persist progress and * resume later. */
const COLLECTION = 'app.bsky.feed.post';
function cdnUrl(did, cid) { return cid ? `https://cdn.bsky.app/img/feed_fullsize/plain/${did}/${cid}@jpeg` : null;}
function hasAlt(value) { return !!(value && String(value).trim().length > 0);}
/** * Parses an embed into a normalized list of alt-able media entries. * Returns null when the embed carries no editable alt (not images / * recordWithMedia / video). * * @param {Object} embed - Raw embed value from a post record * @param {string} did - The user's DID (for CDN URLs) * @returns {{embedType:string, images:Array, missing:number}|null} */export function parseEmbed(embed, did) { if (!embed) return null; const type = embed.$type;
const toImageEntry = (img, idx) => { const blobRef = img?.image?.ref?.$link || null;
return { index: idx, kind: 'image', blobRef, mimeType: img?.image?.mimeType || 'image/jpeg', currentAlt: img?.alt || '', hasAlt: hasAlt(img?.alt), cdnUrl: cdnUrl(did, blobRef), aspectRatio: img?.aspectRatio || null, }; };
if (type === 'app.bsky.embed.images') { const images = (embed.images || []).map(toImageEntry); const missing = images.filter((i) => !i.hasAlt);
return { embedType: type, images, missing: missing.length }; }
if (type === 'app.bsky.embed.recordWithMedia') { const media = embed.media;
if (media?.$type !== 'app.bsky.embed.images') return null; const images = (media.images || []).map(toImageEntry); const missing = images.filter((i) => !i.hasAlt);
return { embedType: type, images, missing: missing.length }; }
if (type === 'app.bsky.embed.video') { const alt = embed.alt || '';
// Single textarea for the video alt; no thumbnail (may be omitted). const images = [ { index: 0, kind: 'video', blobRef: null, mimeType: null, currentAlt: alt, hasAlt: hasAlt(alt), cdnUrl: null, aspectRatio: null, }, ];
const missing = images[0].hasAlt ? 0 : 1;
return { embedType: type, images, missing }; }
return null;}
/** * Scans the user's posts (and replies) on their own PDS for media lacking * alt text. Loops over listRecords pages until the cursor is absent. * * @param {import('@atproto/api').Agent} agent - Authenticated ATProto agent * @param {string} did - The user's DID * @param {Object} [opts] * @param {string} [opts.startCursor] - Resume scanning from this cursor * @param {(state:{cursor:string|null,hits:number})=>void} [opts.onPage] - Called after each page * @returns {Promise<{posts:Array, cursor:string|null}>} - Posts and final cursor (null when complete) */export async function scanImagePosts(agent, did, { startCursor, onPage } = {}) { const posts = []; let cursor = startCursor;
do { const params = { repo: did, collection: COLLECTION, limit: 100, };
if (cursor) params.cursor = cursor; const res = await agent.api.com.atproto.repo.listRecords(params);
for (const record of res.data.records || []) { const value = record.value; const parsed = parseEmbed(value?.embed, did);
if (!parsed) continue;
posts.push({ uri: record.uri, cid: record.cid, rkey: record.uri.split('/').pop(), text: value.text || '', createdAt: value.createdAt, isReply: !!value.reply, // Full original value — exactly the object P1 writes back (minus alt edits). originalValue: value, embedType: parsed.embedType, images: parsed.images, missingAltCount: parsed.missing, allHaveAlt: parsed.missing === 0, }); }
cursor = res.data.cursor;
if (onPage) onPage({ cursor, hits: posts.length }); } while (cursor);
return { posts, cursor: null };}
/** * Builds a CDN URL for displaying an image blob. * @param {string} did * @param {string} cid * @returns {string} */export function blobCdnUrl(did, cid) { return cdnUrl(did, cid);}