Add image upload and edit functions

This commit is contained in:
2025-12-20 16:34:50 +01:00
parent 96fa12993b
commit dfb6f7042a
72 changed files with 7413 additions and 81 deletions

View File

@ -0,0 +1,41 @@
import { createImageFromFile } from "./createImageFromFile";
type BulkResult =
| { ok: true; artworkId: string; name: string }
| { ok: false; name: string; error: string };
export async function createImagesBulk(formData: FormData): Promise<BulkResult[]> {
const entries = formData.getAll("file");
const files = entries.filter((x): x is File => x instanceof File);
if (files.length === 0) {
throw new Error("No files received. Ensure you send FormData with key 'file'.");
}
const results: BulkResult[] = [];
for (const f of files) {
try {
if (!f.type.startsWith("image/")) {
results.push({ ok: false, name: f.name, error: "Unsupported file type" });
continue;
}
const artwork = await createImageFromFile(f);
if (!artwork) {
results.push({ ok: false, name: f.name, error: "Upload failed" });
continue;
}
results.push({ ok: true, artworkId: artwork.id, name: f.name });
} catch (err) {
results.push({
ok: false,
name: f.name,
error: err instanceof Error ? err.message : "Upload failed",
});
}
}
return results;
}