f7a0c8618f
CI / build (push) Has been cancelled
Event photos and videos are now stored only on the NFS/local share named in Settings -> Media storage. Uploads, photo editing, video processing and the per-event filing step refuse to run until that share is configured and writable, so nothing is silently written inside the container. Video originals, renditions, posters and sidecars share one folder on the share. Also adds volunteer growth goals with a mentor queue, an admin retention and storage sweep with a cron entry point, cached gallery thumbnails with per-folder ZIP downloads, a server-rendered booth-sheet PDF, and in-app confirm/release for every upcoming assignment. Service reminders now ignore the one-off event reminder rule, which had been queueing an extra bogus reminder for each published service. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { rm } from "node:fs/promises";
|
|
import { gateOrUser } from "@/auth/api";
|
|
import { db } from "@/db";
|
|
import { writeAudit } from "@/db/audit";
|
|
import { deleteEvent, getEventAccess } from "@/db/events";
|
|
import { listEventVideos } from "@/db/videos";
|
|
import { getStorageSettings } from "@/db/storage-settings";
|
|
import { mediaStorage } from "@/lib/media-storage";
|
|
import { eventPhotoDir } from "@/lib/event-photos";
|
|
import { eventVideoArchiveDir } from "@/lib/event-videos";
|
|
import { errorResponse, jsonResponse } from "@/lib/http";
|
|
|
|
/**
|
|
* DELETE /api/events/:id — manager-only. Removes the event, its folders/photos
|
|
* and the event's directory on the uploads volume. The database cascade commits
|
|
* first; bytes are then removed best-effort so a storage hiccup cannot leave a
|
|
* half-deleted event row. Any orphaned bytes are reported in the server log.
|
|
*/
|
|
export const DELETE = async (
|
|
_req: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> },
|
|
) => {
|
|
const gate = await gateOrUser("schedule.publish");
|
|
if (gate instanceof Response) return gate;
|
|
|
|
const { id } = await params;
|
|
const access = await getEventAccess(id, gate.id, gate.systemRole);
|
|
if (!access) return errorResponse(404, "unknown event");
|
|
const videos = await listEventVideos(id);
|
|
|
|
const deleted = await deleteEvent(id);
|
|
if (!deleted) return errorResponse(404, "unknown event");
|
|
|
|
const media = await mediaStorage();
|
|
if (media.ok) {
|
|
try {
|
|
await rm(eventPhotoDir(media.root, id), { recursive: true, force: true });
|
|
} catch (error) {
|
|
console.error(`event ${id}: database deleted but photos remain`, error);
|
|
}
|
|
}
|
|
|
|
// Video originals are the largest files; remove the whole event video folder
|
|
// on the archive after the cascade has removed the rows, so a deletion cannot
|
|
// orphan GBs. Originals and derivatives share one folder per video.
|
|
try {
|
|
const storage = await getStorageSettings();
|
|
const folders = new Set(videos.map((video) => video.archiveFolder));
|
|
for (const folder of folders) {
|
|
await rm(eventVideoArchiveDir(storage.archivePath, folder, id), {
|
|
recursive: true,
|
|
force: true,
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error(`event ${id}: NFS video files were not removed`, error);
|
|
}
|
|
|
|
await writeAudit(db, {
|
|
actorId: gate.id,
|
|
action: "event.deleted",
|
|
entityType: "event",
|
|
entityId: id,
|
|
before: {
|
|
title: deleted.event.title,
|
|
startsAt: deleted.event.startsAt.toISOString(),
|
|
photoCount: deleted.photoCount,
|
|
videoCount: videos.length,
|
|
},
|
|
});
|
|
|
|
return jsonResponse({ ok: true });
|
|
};
|