This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
@@ -3,29 +3,39 @@ import path from "node:path";
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import { getFurniAssetDirs } from "@/lib/services/furni-asset-dirs";
|
||||
|
||||
const CORS_HEADERS = { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "GET, OPTIONS" };
|
||||
const CORS_HEADERS = {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET, OPTIONS",
|
||||
};
|
||||
|
||||
export async function GET(_request: NextRequest, { params }: { params: Promise<{ path: string[] }> }) {
|
||||
const segments = (await params).path;
|
||||
const filename = segments.at(-1);
|
||||
if (!filename || filename !== path.basename(filename) || !filename.endsWith(".nitro")) {
|
||||
return new NextResponse(null, { status: 404, headers: CORS_HEADERS });
|
||||
}
|
||||
try {
|
||||
const { nitroDir } = await getFurniAssetDirs();
|
||||
const file = await fs.readFile(path.join(nitroDir, filename));
|
||||
return new NextResponse(file, {
|
||||
headers: {
|
||||
...CORS_HEADERS,
|
||||
"Content-Type": "application/octet-stream",
|
||||
"Cache-Control": "public, max-age=86400, immutable",
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return new NextResponse(null, { status: 404, headers: CORS_HEADERS });
|
||||
}
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ path: string[] }> },
|
||||
) {
|
||||
const segments = (await params).path;
|
||||
const filename = segments.at(-1);
|
||||
if (
|
||||
!filename ||
|
||||
filename !== path.basename(filename) ||
|
||||
!filename.endsWith(".nitro")
|
||||
) {
|
||||
return new NextResponse(null, { status: 404, headers: CORS_HEADERS });
|
||||
}
|
||||
try {
|
||||
const { nitroDir } = await getFurniAssetDirs();
|
||||
const file = await fs.readFile(path.join(nitroDir, filename));
|
||||
return new NextResponse(file, {
|
||||
headers: {
|
||||
...CORS_HEADERS,
|
||||
"Content-Type": "application/octet-stream",
|
||||
"Cache-Control": "public, max-age=86400, immutable",
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return new NextResponse(null, { status: 404, headers: CORS_HEADERS });
|
||||
}
|
||||
}
|
||||
|
||||
export function OPTIONS() {
|
||||
return new NextResponse(null, { status: 204, headers: CORS_HEADERS });
|
||||
return new NextResponse(null, { status: 204, headers: CORS_HEADERS });
|
||||
}
|
||||
Reference in new issue
Block a user