mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -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`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user