mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: handle non-image modalities across uploads, previews, and filenames (#255)
SnapOtter spans five modalities now, but several code paths still assumed image input. - dropzone: default to accept-all when no fileFilter is given (image tools still pass one); neutral "supported file types" error text instead of "image files" - automate (pipelines): accept any modality in the file pickers and dropzones; render modality-aware previews (video player, audio waveform, document/data card) instead of always using ImageViewer/BeforeAfterSlider - filename sanitizer: extend the double-extension allowlist beyond image extensions to video/audio/document/data so e.g. "report.csv.php" becomes "report.csv"; add tests - thumbnail route: return 422 for non-rasterisable files (audio, data, non-PDF docs) instead of attempting a doomed Sharp decode - pool: unknown tools fall back to the "system" pool, not the image pool - a11y labels: "Previous/Next image", "Image viewer/area/controls/drop zone" are now modality-neutral, across all 21 locales - copy: bulk-rename default, find-duplicates ZIP name, SSRF user-agent, fetch-urls fallback name, file-details MIME label, URL-import placeholder, help dialog
This commit is contained in:
@@ -110,7 +110,7 @@ function filenameFromUrl(url: string): string {
|
||||
} catch {
|
||||
// ignore parse errors
|
||||
}
|
||||
return `image-${randomUUID().slice(0, 8)}`;
|
||||
return `file-${randomUUID().slice(0, 8)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -524,6 +524,12 @@ export async function userFileRoutes(app: FastifyInstance): Promise<void> {
|
||||
|
||||
// Image thumbnail (existing path)
|
||||
const validation = await validateImageBuffer(rawBuffer, file.originalName);
|
||||
if (!validation.valid) {
|
||||
// Audio, data, and non-PDF document files have no raster thumbnail.
|
||||
// Return 422 (not 204) so the client's <img> onError falls back to a
|
||||
// modality icon instead of attempting a doomed Sharp decode below.
|
||||
return reply.status(422).send({ error: "No thumbnail available for this file type" });
|
||||
}
|
||||
let decoded: Buffer<ArrayBuffer> = Buffer.from(rawBuffer);
|
||||
if (validation.valid && validation.format === "heif") {
|
||||
decoded = Buffer.from(await decodeHeic(rawBuffer));
|
||||
|
||||
Reference in New Issue
Block a user