Share the link-preview fallback between the Meta adapters

Instagram and Threads both ended with the same twelve lines: read the Open
Graph tags, make og:video a video with og:image as its poster, otherwise make
og:image an image, and attach the referrer headers the CDN wants. Facebook
needs the same floor for the same reason, and three copies of a thing is where
it stops being a coincidence.

meta-media.ts already exists because these platforms are one product
underneath. The media schema it normalizes is Instagram's and Threads';
Facebook's is its own, but the headers and the link preview are shared with
both, so that is where this goes.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
2026-09-12 11:35:16 -03:00
co-authored by Claude Opus 5
parent 635bc9d0a4
commit fa07b43c1c
4 changed files with 67 additions and 34 deletions
+25 -1
View File
@@ -1,6 +1,11 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { findCaption, findMetaMedia, mediaFromMetaNode } from '../src/platforms/meta-media.ts';
import {
findCaption,
findMetaMedia,
mediaFromMetaNode,
mediaFromOpenGraph,
} from '../src/platforms/meta-media.ts';
import { fixture } from './helpers.ts';
const REFERER = 'https://www.threads.com/';
@@ -68,3 +73,22 @@ test('the caption is found the same way, and an empty one is not a caption', ()
assert.equal(findCaption({ x: { caption: { text: '' } } }), undefined);
assert.equal(findCaption({ x: { caption: null } }), undefined);
});
test('the link preview stands in for the post when there is nothing better', () => {
const image = mediaFromOpenGraph({ 'og:image': 'https://image.example/a.jpg' }, REFERER);
assert.deepEqual(image.map((item) => [item.kind, item.url]), [['image', 'https://image.example/a.jpg']]);
assert.equal(image[0]?.fetchHeaders?.['Referer'], REFERER);
});
test('a preview naming a video is a video, and its image is the poster', () => {
const media = mediaFromOpenGraph(
{ 'og:video': 'https://video.example/a.mp4', 'og:image': 'https://image.example/a.jpg' },
REFERER,
);
assert.equal(media[0]?.kind, 'video');
assert.equal(media[0]?.kind === 'video' ? media[0].poster?.url : undefined, 'https://image.example/a.jpg');
});
test('a page with no preview at all yields no media rather than an empty asset', () => {
assert.deepEqual(mediaFromOpenGraph({ 'og:title': 'just a title' }, REFERER), []);
});