Files
pihka-al/server/api/files/index.post.ts
Pihkaal 27cb044247
All checks were successful
Deploy / build (push) Successful in 12m22s
Deploy / deploy (push) Successful in 1s
feat: use portainer hook instead of pushing image to gitea package repository
2026-05-30 23:25:50 +02:00

23 lines
775 B
TypeScript

import { writeFile, mkdir } from "node:fs/promises";
import { resolve } from "node:path";
export default defineEventHandler(async (event) => {
const parts = await readMultipartFormData(event);
if (!parts || parts.length === 0) {
throw createError({ statusCode: 400, message: "No file provided" });
}
const filePart = parts.find((p) => p.name === "file");
if (!filePart || !filePart.filename) {
throw createError({ statusCode: 400, message: "No file provided" });
}
const filename = filePart.filename.replace(/[^a-zA-Z0-9._-]/g, "_");
const dir = resolve(process.cwd(), "public/files");
await mkdir(dir, { recursive: true });
await writeFile(resolve(dir, filename), filePart.data);
return { name: filename, size: filePart.data.length };
});