优化docker

This commit is contained in:
2026-06-30 16:31:03 +08:00
parent 68bc72ff2a
commit 908bad097c
10 changed files with 5020 additions and 7832 deletions
+38
View File
@@ -0,0 +1,38 @@
import { stat, readFile } from "node:fs/promises";
import path from "node:path";
import { NextRequest, NextResponse } from "next/server";
import { resolveAudioFilePath } from "@/lib/audio";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
type RouteContext = {
params: Promise<{ path: string[] }>;
};
export async function GET(_request: NextRequest, context: RouteContext) {
const { path: audioPath } = await context.params;
const filePath = resolveAudioFilePath(audioPath);
if (!filePath || path.extname(filePath).toLowerCase() !== ".mp3") {
return new NextResponse("Not found", { status: 404 });
}
try {
const fileStat = await stat(filePath);
if (!fileStat.isFile()) {
return new NextResponse("Not found", { status: 404 });
}
const file = await readFile(filePath);
return new NextResponse(new Uint8Array(file), {
headers: {
"Content-Type": "audio/mpeg",
"Content-Length": String(fileStat.size),
"Cache-Control": "public, max-age=31536000, immutable",
},
});
} catch {
return new NextResponse("Not found", { status: 404 });
}
}