fix: deliver alt texts to providers at publish time

Intake stores alt texts positionally (aligned with mediaAssetIds) but the
Mastodon upload reads an asset-id-keyed providerMetadata.altText map, so
descriptions were silently dropped. postOf translates the array into the map.
This commit is contained in:
glass beadian 2026-10-16 01:52:35 +00:00
parent e7bf870de9
commit 2d881f5e41

View file

@ -23,7 +23,20 @@ function connectionOf(job: ClaimedJob): ConnectorConnection {
function postOf(job: ClaimedJob): NormalizedPost {
const visibility = job.post.visibility;
if (!["public", "unlisted", "private", "followers", "provider_default"].includes(visibility)) throw new Error("INVALID_POST_VISIBILITY");
return { ...job.post, visibility: visibility as NormalizedPost["visibility"] };
const post = job.post;
// Positional alt texts (aligned with mediaAssetIds at intake) become the
// connector's asset-id → description map; the Mastodon upload reads it.
const providerMetadata: Record<string, unknown> = { ...post.providerMetadata };
const altTexts = post.altTexts;
if (Array.isArray(altTexts) && altTexts.length > 0) {
const altText: Record<string, string> = {};
post.mediaAssetIds.forEach((id, index) => {
const text = altTexts[index];
if (typeof text === "string" && text.trim() !== "") altText[id] = text;
});
if (Object.keys(altText).length > 0) providerMetadata.altText = altText;
}
return { ...post, visibility: visibility as NormalizedPost["visibility"], providerMetadata };
}
/** Persist only documented remote evidence; unknown fields never enter DB/history. */
export function safeMetadata(metadata: Record<string, unknown>): Record<string, unknown> {