mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: verbose error handling, batch processing, and multi-file support
- Replace [object Object] errors with readable messages across all 20+ API routes by normalizing Zod validation errors to strings (formatZodErrors) - Add parseApiError() on frontend to defensively handle any details type - Add global Fastify error handler with full stack traces in logs - Fix image-to-pdf auth: Object.entries(headers) → headers.forEach() - Fix passport-photo: safeParse + formatZodErrors, safe error extraction - Fix OCR silent fallbacks: log exception type/message when falling back, include actual engine used in API response and Docker logs - Fix split tool: process all uploaded images, combine into ZIP with subfolders per image - Fix batch support for blur-faces, strip-metadata, edit-metadata, vectorize: add processAllFiles branch for multi-file uploads - Docker: LOG_LEVEL=debug, PYTHONWARNINGS=default for visibility - Add Playwright e2e tests verifying all fixes against Docker container
This commit is contained in:
@@ -115,41 +115,92 @@ export function VectorizeSettings() {
|
||||
setError(null);
|
||||
setDownloadUrl(null);
|
||||
|
||||
const settingsJson = JSON.stringify({
|
||||
colorMode,
|
||||
threshold,
|
||||
colorPrecision,
|
||||
layerDifference,
|
||||
filterSpeckle,
|
||||
pathMode,
|
||||
cornerThreshold,
|
||||
invert,
|
||||
});
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append("file", files[0]);
|
||||
formData.append(
|
||||
"settings",
|
||||
JSON.stringify({
|
||||
colorMode,
|
||||
threshold,
|
||||
colorPrecision,
|
||||
layerDifference,
|
||||
filterSpeckle,
|
||||
pathMode,
|
||||
cornerThreshold,
|
||||
invert,
|
||||
}),
|
||||
);
|
||||
if (files.length === 1) {
|
||||
const formData = new FormData();
|
||||
formData.append("file", files[0]);
|
||||
formData.append("settings", settingsJson);
|
||||
|
||||
const res = await fetch("/api/v1/tools/vectorize", {
|
||||
method: "POST",
|
||||
headers: formatHeaders(),
|
||||
body: formData,
|
||||
});
|
||||
const res = await fetch("/api/v1/tools/vectorize", {
|
||||
method: "POST",
|
||||
headers: formatHeaders(),
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error || `Failed: ${res.status}`);
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.error || `Failed: ${res.status}`);
|
||||
}
|
||||
|
||||
const result = await res.json();
|
||||
setJobId(result.jobId);
|
||||
setProcessedUrl(result.downloadUrl);
|
||||
setDownloadUrl(result.downloadUrl);
|
||||
setOriginalSize(result.originalSize);
|
||||
setProcessedSize(result.processedSize);
|
||||
setSizes(result.originalSize, result.processedSize);
|
||||
} else {
|
||||
const { updateEntry, setBatchZip } = useFileStore.getState();
|
||||
const JSZip = (await import("jszip")).default;
|
||||
const zip = new JSZip();
|
||||
let totalOriginal = 0;
|
||||
let totalProcessed = 0;
|
||||
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = files[i];
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("settings", settingsJson);
|
||||
|
||||
const res = await fetch("/api/v1/tools/vectorize", {
|
||||
method: "POST",
|
||||
headers: formatHeaders(),
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
updateEntry(i, {
|
||||
status: "failed",
|
||||
error: body.error || `Failed: ${res.status}`,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
const result = await res.json();
|
||||
totalOriginal += result.originalSize;
|
||||
totalProcessed += result.processedSize;
|
||||
|
||||
const svgRes = await fetch(result.downloadUrl, { headers: formatHeaders() });
|
||||
const svgBlob = await svgRes.blob();
|
||||
const svgName = file.name.replace(/\.[^.]+$/, ".svg");
|
||||
zip.file(svgName, svgBlob);
|
||||
|
||||
updateEntry(i, {
|
||||
processedUrl: result.downloadUrl,
|
||||
processedSize: result.processedSize,
|
||||
status: "completed",
|
||||
error: null,
|
||||
});
|
||||
}
|
||||
|
||||
const zipBlob = await zip.generateAsync({ type: "blob" });
|
||||
setBatchZip(zipBlob, "vectorize-batch.zip");
|
||||
setOriginalSize(totalOriginal);
|
||||
setProcessedSize(totalProcessed);
|
||||
setSizes(totalOriginal, totalProcessed);
|
||||
}
|
||||
|
||||
const result = await res.json();
|
||||
setJobId(result.jobId);
|
||||
setProcessedUrl(result.downloadUrl);
|
||||
setDownloadUrl(result.downloadUrl);
|
||||
setOriginalSize(result.originalSize);
|
||||
setProcessedSize(result.processedSize);
|
||||
setSizes(result.originalSize, result.processedSize);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Vectorization failed");
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user