fix: fall back to Sharp when CLI decoders are unavailable

DNG and FITS previews showed "Preview not available" because their CLI
decoders (ExifTool/ImageMagick) were not installed. Sharp can read both
formats natively (DNG is TIFF-based, FITS via libvips fitsload).

Added Sharp fallback to the preview endpoint, batch processing, and
tool factory: when decodeToSharpCompat throws, try sharp(buffer).metadata()
before returning 422. If Sharp can read the buffer, processing continues
without the CLI decoder.
This commit is contained in:
SnapOtter
2026-05-11 18:00:59 +08:00
parent 7d9612784e
commit 2acf0ea48a
3 changed files with 36 additions and 16 deletions
+6 -1
View File
@@ -13,6 +13,7 @@ import { getBundleForTool, TOOL_BUNDLE_MAP } from "@snapotter/shared";
import archiver from "archiver";
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import PQueue from "p-queue";
import sharp from "sharp";
import { env } from "../config.js";
import { autoOrient } from "../lib/auto-orient.js";
import { resolveConcurrency } from "../lib/env.js";
@@ -169,7 +170,11 @@ export async function registerBatchRoutes(app: FastifyInstance): Promise<void> {
if (ext) processFilename = `${processFilename.slice(0, -ext.length)}.png`;
}
if (!skipPreprocess && needsCliDecode(validation.format)) {
processBuffer = await decodeToSharpCompat(processBuffer, validation.format);
try {
processBuffer = await decodeToSharpCompat(processBuffer, validation.format);
} catch {
await sharp(processBuffer).metadata();
}
const ext = processFilename.match(/\.[^.]+$/)?.[0];
if (ext) processFilename = `${processFilename.slice(0, -ext.length)}.png`;
}