Files
aerbim-ht-monitor/frontend/app/api/big-models/[...path]/route.ts
2025-11-11 10:07:38 +03:00

37 lines
1.2 KiB
TypeScript

export const dynamic = 'force-static';
import fs from 'fs';
import path from 'path';
export async function GET(
request: Request,
{ params }: { params: Promise<{ path: string[] }> }
) {
const { path: pathParts } = await params;
const fileName = pathParts.join('/');
const filePath = path.join(process.cwd(), 'assets', 'big-models', fileName);
if (!fs.existsSync(filePath)) {
return new Response('Not Found', { status: 404 });
}
const stat = fs.statSync(filePath);
const stream = fs.createReadStream(filePath);
const ext = path.extname(fileName).toLowerCase();
let contentType = 'application/octet-stream';
if (ext === '.glb') contentType = 'model/gltf-binary';
else if (ext === '.gltf') contentType = 'model/gltf+json';
else if (ext === '.bin') contentType = 'application/octet-stream';
else if (ext === '.png') contentType = 'image/png';
else if (ext === '.jpg' || ext === '.jpeg') contentType = 'image/jpeg';
else if (ext === '.webp') contentType = 'image/webp';
else if (ext === '.ktx2') contentType = 'image/ktx2';
return new Response(stream as unknown as ReadableStream, {
headers: {
'Content-Length': stat.size.toString(),
'Content-Type': contentType,
},
});
}