v2.0: sound library, image upload, DnD, ResourceBrowser, Barotrauma HUD, captain sanity
Deploy / build-and-deploy (push) Failing after 52s

This commit is contained in:
2026-06-15 01:07:05 +03:00
parent 9deec9d23e
commit d0cd008f6e
16 changed files with 1039 additions and 231 deletions
+62 -10
View File
@@ -1,9 +1,13 @@
import { NextRequest, NextResponse } from "next/server";
import { getServerSession } from "@/lib/auth";
import { readdir, unlink } from "fs/promises";
import { db } from "@/lib/db";
import { sounds } from "@/lib/db/schema";
import { writeFile, mkdir, unlink } from "fs/promises";
import path from "path";
import { v4 as uuidv4 } from "uuid";
import { eq } from "drizzle-orm";
const SOUNDS_DIR = path.join(process.cwd(), "public", "uploads", "sounds");
const UPLOAD_DIR = path.join(process.cwd(), "public", "uploads", "sounds");
export async function GET() {
const session = await getServerSession();
@@ -11,17 +15,64 @@ export async function GET() {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
try {
const files = await readdir(SOUNDS_DIR);
const sounds = files
.filter(f => f.endsWith(".ogg"))
.map(f => ({ filename: f, url: `/uploads/sounds/${f}` }))
.sort((a, b) => a.filename.localeCompare(b.filename));
return NextResponse.json({ sounds });
const all = db.select().from(sounds).orderBy(sounds.createdAt).all();
const list = all.map(s => ({
id: s.id,
originalName: s.originalName,
url: `/uploads/sounds/${s.storedFilename}`,
duration: s.duration,
}));
return NextResponse.json({ sounds: list });
} catch {
return NextResponse.json({ sounds: [] });
}
}
export async function POST(req: NextRequest) {
const session = await getServerSession();
if (!session || !session.isAdmin) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
try {
const formData = await req.formData();
const files = formData.getAll("files") as File[];
if (!files.length) return NextResponse.json({ error: "No files" }, { status: 400 });
await mkdir(UPLOAD_DIR, { recursive: true });
const results: { url: string; originalName: string; duration: number }[] = [];
for (const file of files) {
if (!file.name.toLowerCase().endsWith(".ogg")) continue;
if (file.size > 2 * 1024 * 1024) continue;
const ext = path.extname(file.name);
const filename = `${uuidv4()}${ext}`;
const filepath = path.join(UPLOAD_DIR, filename);
const bytes = await file.arrayBuffer();
await writeFile(filepath, Buffer.from(bytes));
// compute duration from file size (approximate for OGG Vorbis ~64kbps)
const duration = Math.round((file.size / (64 * 128)) * 10) / 10;
const id = uuidv4();
db.insert(sounds).values({
id,
originalName: file.name,
storedFilename: filename,
duration: Math.min(duration, 6),
uploadedBy: session.id,
createdAt: new Date().toISOString(),
}).run();
results.push({ url: `/uploads/sounds/${filename}`, originalName: file.name, duration: Math.min(duration, 6) });
}
return NextResponse.json({ sounds: results });
} catch {
return NextResponse.json({ error: "Upload failed" }, { status: 500 });
}
}
export async function DELETE(req: NextRequest) {
const session = await getServerSession();
if (!session || !session.isAdmin) {
@@ -30,8 +81,9 @@ export async function DELETE(req: NextRequest) {
const filename = req.nextUrl.searchParams.get("filename");
if (!filename) return NextResponse.json({ error: "No filename" }, { status: 400 });
try {
const filepath = path.join(SOUNDS_DIR, filename);
await unlink(filepath);
const filepath = path.join(UPLOAD_DIR, filename);
await unlink(filepath).catch(() => {});
db.delete(sounds).where(eq(sounds.storedFilename, filename)).run();
return NextResponse.json({ success: true });
} catch {
return NextResponse.json({ error: "Delete failed" }, { status: 500 });