Projektstart
This commit is contained in:
@@ -3,6 +3,8 @@ import { z } from "zod";
|
||||
import { prisma } from "../db.js";
|
||||
import { logJobEvent } from "../queue/jobEvents.js";
|
||||
import { queueCleanupJob, removeQueueJob } from "../queue/queue.js";
|
||||
import { createReadStream } from "node:fs";
|
||||
import { access } from "node:fs/promises";
|
||||
|
||||
const roleSchema = z.object({
|
||||
role: z.enum(["USER", "ADMIN"])
|
||||
@@ -94,10 +96,34 @@ export async function adminRoutes(app: FastifyInstance) {
|
||||
const params = request.params as { id: string };
|
||||
const job = await prisma.exportJob.findUnique({ where: { id: params.id } });
|
||||
if (!job || !job.filePath) return reply.code(404).send({ message: "Export file not ready" });
|
||||
if (job.expiresAt && job.expiresAt < new Date()) {
|
||||
return reply.code(410).send({ message: "Export expired" });
|
||||
}
|
||||
|
||||
try {
|
||||
await access(job.filePath);
|
||||
} catch {
|
||||
return reply.code(404).send({ message: "Export file missing" });
|
||||
}
|
||||
|
||||
reply.header("Content-Type", "application/zip");
|
||||
reply.header("Content-Disposition", `attachment; filename=export-${job.id}.zip`);
|
||||
return reply.sendFile(job.filePath);
|
||||
return reply.send(createReadStream(job.filePath));
|
||||
});
|
||||
|
||||
app.get("/exports", async () => {
|
||||
const exports = await prisma.exportJob.findMany({
|
||||
orderBy: { createdAt: "desc" }
|
||||
});
|
||||
const sanitized = exports.map((job) => ({
|
||||
id: job.id,
|
||||
status: job.status,
|
||||
format: job.format,
|
||||
scope: job.scope,
|
||||
expiresAt: job.expiresAt,
|
||||
createdAt: job.createdAt
|
||||
}));
|
||||
return { exports: sanitized };
|
||||
});
|
||||
|
||||
app.delete("/tenants/:id", async (request, reply) => {
|
||||
|
||||
Reference in New Issue
Block a user