feat: API contenuti taggati

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-05 17:18:30 +02:00
parent b5c0c107bc
commit eda4d73aac
7 changed files with 182 additions and 11 deletions
+16
View File
@@ -0,0 +1,16 @@
import { extname } from 'node:path';
export const ALLOWED: Record<string, string> = {
'.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png', '.webp': 'image/webp', '.gif': 'image/gif',
};
export const MAX_BYTES = 5 * 1024 * 1024;
export function validateUploadFile(file: unknown):
| { ok: true; file: File; ext: string }
| { ok: false; error: string } {
if (!(file instanceof File)) return { ok: false, error: 'Nessun file.' };
const ext = extname(file.name).toLowerCase();
if (!ALLOWED[ext]) return { ok: false, error: 'Formato non consentito (jpg, png, webp, gif).' };
if (file.size > MAX_BYTES) return { ok: false, error: 'File troppo grande (max 5 MB).' };
return { ok: true, file, ext };
}