Files
drop/server/internal/utils/handlefileupload.ts
DecDuck 251ddb8ff8 Rearchitecture for v0.4.0 (#197)
* feat: database redist support

* feat: rearchitecture of database schemas, migration reset, and #180

* feat: import redists

* fix: giantbomb logging bug

* feat: partial user platform support + statusMessage -> message

* feat: add user platform filters to store view

* fix: sanitize svg uploads

... copilot suggested this

I feel dirty.

* feat: beginnings of platform & redist management

* feat: add server side redist patching

* fix: update drop-base commit

* feat: import of custom platforms & file extensions

* fix: redelete platform

* fix: remove platform

* feat: uninstall commands, new R UI

* checkpoint: before migrating to nuxt v4

* update to nuxt 4

* fix: fixes for Nuxt v4 update

* fix: remaining type issues

* feat: initial feedback to import other kinds of versions

* working commit

* fix: lint

* feat: redist import
2025-11-10 10:36:13 +11:00

49 lines
1.4 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import type { EventHandlerRequest, H3Event } from "h3";
import type { Dump, Pull, Register } from "../objects/transactional";
import { ObjectTransactionalHandler } from "../objects/transactional";
type RecursiveType =
| { [key: string]: RecursiveType }
| string
| number
| Array<RecursiveType>;
export async function handleFileUpload(
h3: H3Event<EventHandlerRequest>,
metadata: { [key: string]: string },
permissions: Array<string>,
max = -1,
): Promise<
[string[], { [key: string]: RecursiveType }, Pull, Dump, Register] | undefined
> {
const formData = await readMultipartFormData(h3);
if (!formData) return undefined;
const transactionalHandler = new ObjectTransactionalHandler();
const [add, pull, dump] = transactionalHandler.new(metadata, permissions);
const options: any = {};
const ids = [];
for (const entry of formData) {
if (entry.filename) {
if (max > 0 && ids.length >= max) continue;
// Add file to transaction handler so we can void it later if we error out
ids.push(add(entry.data));
continue;
}
if (!entry.name) continue;
const path = entry.name.split(".");
let v = options;
for (const pathPart of path.slice(0, -1)) {
(v as any)[pathPart] ??= {};
v = (v as any)[pathPart];
}
(v as any)[path.at(-1)!] = entry.data.toString("utf-8");
}
return [ids, options, pull, dump, add];
}