Files
t3code/packages/shared/src/filePreview.ts
T
Julius Marminge 44dd6f67f6 Render saved screenshots and recordings in chat markdown
- Add secure asset access for workspace media and browser artifacts
- Support saving preview screenshots and embedding playable recordings
2026-07-29 16:58:57 -04:00

40 lines
1.2 KiB
TypeScript

export const WORKSPACE_BROWSER_PREVIEW_EXTENSIONS = [".htm", ".html", ".pdf"] as const;
export const WORKSPACE_IMAGE_PREVIEW_EXTENSIONS = [
".avif",
".gif",
".ico",
".jpeg",
".jpg",
".png",
".svg",
".webp",
] as const;
export const WORKSPACE_VIDEO_PREVIEW_EXTENSIONS = [".m4v", ".mov", ".mp4", ".webm"] as const;
function hasPreviewExtension(path: string, extensions: ReadonlyArray<string>): boolean {
const pathWithoutQuery = path.split(/[?#]/, 1)[0]?.toLowerCase() ?? "";
return extensions.some((extension) => pathWithoutQuery.endsWith(extension));
}
export function isWorkspaceBrowserPreviewPath(path: string): boolean {
return hasPreviewExtension(path, WORKSPACE_BROWSER_PREVIEW_EXTENSIONS);
}
export function isWorkspaceImagePreviewPath(path: string): boolean {
return hasPreviewExtension(path, WORKSPACE_IMAGE_PREVIEW_EXTENSIONS);
}
export function isWorkspaceVideoPreviewPath(path: string): boolean {
return hasPreviewExtension(path, WORKSPACE_VIDEO_PREVIEW_EXTENSIONS);
}
export function isWorkspacePreviewEntryPath(path: string): boolean {
return (
isWorkspaceBrowserPreviewPath(path) ||
isWorkspaceImagePreviewPath(path) ||
isWorkspaceVideoPreviewPath(path)
);
}