mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-14 16:51:15 +10:00
feat: partial user platform support + statusMessage -> message
This commit is contained in:
@ -1,18 +1,27 @@
|
||||
/* 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]: string }, Pull, Dump, Register] | undefined> {
|
||||
): 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: { [key: string]: string } = {};
|
||||
const options: any = {};
|
||||
const ids = [];
|
||||
|
||||
for (const entry of formData) {
|
||||
@ -25,7 +34,14 @@ export async function handleFileUpload(
|
||||
}
|
||||
if (!entry.name) continue;
|
||||
|
||||
options[entry.name] = entry.data.toString("utf-8");
|
||||
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];
|
||||
|
||||
Reference in New Issue
Block a user