v2.0: sound library, image upload, DnD, ResourceBrowser, Barotrauma HUD, captain sanity
Deploy / build-and-deploy (push) Failing after 52s
Deploy / build-and-deploy (push) Failing after 52s
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getServerSession } from "@/lib/auth";
|
||||
import { db } from "@/lib/db";
|
||||
import { sounds } from "@/lib/db/schema";
|
||||
import { writeFile, mkdir } from "fs/promises";
|
||||
import path from "path";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
@@ -32,6 +34,19 @@ export async function POST(req: NextRequest) {
|
||||
const bytes = await file.arrayBuffer();
|
||||
await writeFile(filepath, Buffer.from(bytes));
|
||||
|
||||
// approximate duration
|
||||
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();
|
||||
|
||||
return NextResponse.json({ url: `/uploads/sounds/${filename}` });
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Upload failed" }, { status: 500 });
|
||||
|
||||
Reference in New Issue
Block a user