mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Extends the platform to handle 7 new image format families alongside the existing AVIF support gap-fill. Uses the established HEIC decoder pattern (CLI decode → PNG → Sharp) for formats Sharp can't handle natively: Camera RAW via dcraw_emu/LibRaw, PSD/TGA/EXR/HDR via ImageMagick. JXL and ICO are Sharp-native. Adds server-side preview for non-browser-displayable formats and JXL as a new convert output target. All 27 validateImageBuffer callers updated with filename for extension-based format detection.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { formatHeaders } from "@/lib/api";
|
|
|
|
const SERVER_PREVIEW_EXTENSIONS = new Set([
|
|
"heic", "heif", "hif", // HEIF
|
|
"jxl", // JPEG XL (Chrome dropped support)
|
|
"dng", "cr2", "nef", "arw", "orf", "rw2", // Camera RAW
|
|
"tga", // Targa
|
|
"psd", // Photoshop
|
|
"exr", // OpenEXR
|
|
"hdr", // Radiance HDR
|
|
]);
|
|
|
|
export function needsServerPreview(file: File): boolean {
|
|
const ext = file.name.split(".").pop()?.toLowerCase() ?? "";
|
|
return SERVER_PREVIEW_EXTENSIONS.has(ext);
|
|
}
|
|
|
|
export async function fetchDecodedPreview(file: File): Promise<string | null> {
|
|
try {
|
|
const formData = new FormData();
|
|
formData.append("file", file);
|
|
const res = await fetch("/api/v1/preview", {
|
|
method: "POST",
|
|
headers: formatHeaders(),
|
|
body: formData,
|
|
});
|
|
if (!res.ok) return null;
|
|
const blob = await res.blob();
|
|
return URL.createObjectURL(blob);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function revokePreviewUrl(url: string): void {
|
|
URL.revokeObjectURL(url);
|
|
}
|