feat(media): support arbitrary file types with download cards (#810)

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
Wes
2026-06-01 12:57:04 -07:00
committed by GitHub
parent 247ac52391
commit 2b052eb465
31 changed files with 1596 additions and 543 deletions

View File

@@ -0,0 +1,42 @@
import { rewriteRelayUrl } from "@/shared/lib/mediaUrl";
/** Minimal shape of an imeta entry as consumed by the markdown renderer. */
export type FileCardImetaEntry = {
m?: string;
size?: number;
filename?: string;
};
export type ResolvedFileCard = {
href: string;
filename: string;
size?: number;
};
/**
* Decide whether a markdown link should render as a generic-file download
* card. A link qualifies when its href matches an imeta entry whose MIME is
* neither image nor video (media goes through the `img` renderer instead).
*
* Pure — extracted from `markdown.tsx` so the FileCard decision (the riskiest
* part of the generic-file rendering path) is unit-testable without mounting
* React. Returns the resolved card props, or `null` to fall through to normal
* link handling.
*/
export function resolveFileCard(
entry: FileCardImetaEntry | undefined,
href: string | undefined,
childText: string,
): ResolvedFileCard | null {
if (
!href ||
!entry?.m ||
entry.m.startsWith("image/") ||
entry.m.startsWith("video/")
) {
return null;
}
const filename =
entry.filename || childText.trim() || href.split("/").pop() || "file";
return { href: rewriteRelayUrl(href), filename, size: entry.size };
}