import { ResolveError, type Media, type Post, type Segment } from '../types.ts'; import { readOpenGraph } from '../browser/capture.ts'; import { findCaption, findMetaMedia, mediaFromMetaNode, metaHeaders, type MetaMediaNode } from './meta-media.ts'; import { hostMatcher } from './url.ts'; import type { PlatformSpec, ResolveContext } from './types.ts'; const REFERER = 'https://www.threads.com/'; /** One post as Threads ships it, alongside the media fields Instagram shares. */ type ThreadsPost = MetaMediaNode & { code?: string; taken_at?: number; caption?: { text?: string }; user?: { username?: string }; text_post_app_info?: { reply_to_author?: { username?: string }; }; }; type ThreadContainer = { thread_items?: Array<{ post?: ThreadsPost }>; }; function handleFromPath(pathRest: string): string | undefined { return /^(@[^/]+)/.exec(pathRest)?.[1]; } function codeFromPath(pathRest: string): string | undefined { return /\/post\/([A-Za-z0-9_-]+)/.exec(`/${pathRest}`)?.[1]; } /** Threads ships its Relay payloads in `