/* eslint-disable no-console */ import { LocalFile } from "@entity-access/server-pages/dist/core/LocalFile.js"; import { randomUUID } from "node:crypto"; import { copyFile, unlink } from "node:fs/promises"; import { globalEnv } from "./globalEnv.js"; export default class FailedReporter { static async copy(src: LocalFile, error?: any) { if (!globalEnv.mime.failed) { return { delete() { // do nothing.. } }; } const failedPath = `${globalEnv.mime.failed}/${randomUUID()}.${src.fileName}`; await copyFile(src.path, failedPath); if (error) { console.log(error.cause?.stack ?? error.stack ?? error); } console.log(`Saved failed file to ${failedPath}`); return { delete() { unlink(failedPath).catch(() => void 0); } }; } }