fix: add exotic format decoding to OCR tool

OCR was the only AI tool missing HEIC/HEIF and CLI-decoded format
support (RAW, PSD, TGA, EXR, HDR, BMP, ICO, JXL, JP2, EPS, etc.).
This commit is contained in:
SnapOtter
2026-05-13 11:50:28 +08:00
parent f46219c730
commit 6a90f29960
+16
View File
@@ -3,10 +3,13 @@ import { extractText } from "@snapotter/ai";
import { getBundleForTool, TOOL_BUNDLE_MAP } from "@snapotter/shared";
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { z } from "zod";
import { autoOrient } from "../../lib/auto-orient.js";
import { formatZodErrors } from "../../lib/errors.js";
import { isToolInstalled } from "../../lib/feature-status.js";
import { validateImageBuffer } from "../../lib/file-validation.js";
import { sanitizeFilename } from "../../lib/filename.js";
import { decodeToSharpCompat, needsCliDecode } from "../../lib/format-decoders.js";
import { decodeHeic } from "../../lib/heic-converter.js";
import { createWorkspace } from "../../lib/workspace.js";
import { updateSingleFileProgress } from "../progress.js";
@@ -74,6 +77,19 @@ export function registerOcr(app: FastifyInstance) {
}
try {
// Decode HEIC/HEIF input via system decoder
if (validation.format === "heif") {
fileBuffer = await decodeHeic(fileBuffer);
}
// Decode CLI-decoded formats (RAW, TGA, PSD, EXR, HDR, etc.)
if (needsCliDecode(validation.format)) {
fileBuffer = await decodeToSharpCompat(fileBuffer, validation.format);
}
// Auto-orient to fix EXIF rotation before OCR
fileBuffer = await autoOrient(fileBuffer);
let settings: z.infer<typeof settingsSchema>;
try {
const parsed = settingsRaw ? JSON.parse(settingsRaw) : {};