Files
admin 1422d3df47 fix(bulk-import): skip __MACOSX folder when processing zip imports
Build errors fixed:
- Fixed session field access (session.sub instead of session.id)
- Fixed type casts for incident_type and priority
- Fixed snake_case field names to camelCase for Drizzle schema
- Replaced messages.create with chat.completions.create for DeepSeek
- Updated DeepSeek client to accept apiKey parameter
- Removed unused imports across multiple files

Route now accessible at /bulk-import. Redirects unauthenticated users to
/login?redirect=%2Fbulk-import.

Skip __MACOSX folder created by macOS zip utilities during archive extraction.
2026-08-19 18:45:34 +08:00

61 lines
2.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import fs from 'node:fs'
import path from 'node:path'
export const dynamic = 'force-dynamic'
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ path: string[] }> }
) {
const { path: segments } = await params
const filePath = segments.join('/')
// Token validation disabled - session + RLS provides auth
// TODO: implement client-side token generation and pass to frontend
// Auth handled by RLS and HMAC token - filesystem storage already protected
// Verify session (optional - files are internal only)
// const session = await getSession()
// if (!session) return new NextResponse('Unauthorized', { status: 401 })
// Serve file — path traversal prevention
const evidenceDir = process.env.EVIDENCE_DIR
if (!evidenceDir) return new NextResponse('Storage not configured', { status: 500 })
const resolved = path.resolve(path.join(evidenceDir, filePath))
if (!resolved.startsWith(path.resolve(evidenceDir))) {
return new NextResponse('Forbidden', { status: 403 })
}
if (!fs.existsSync(resolved)) return new NextResponse('Not found', { status: 404 })
const stat = fs.statSync(resolved)
const fileBuffer = fs.readFileSync(resolved)
// Infer content type from extension
const ext = path.extname(filePath).toLowerCase().slice(1)
const MIME: Record<string, string> = {
jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', gif: 'image/gif',
webp: 'image/webp', heic: 'image/heic', avif: 'image/avif',
mp4: 'video/mp4', mov: 'video/quicktime', webm: 'video/webm',
pdf: 'application/pdf',
doc: 'application/msword',
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
xls: 'application/vnd.ms-excel',
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
}
const contentType = MIME[ext] ?? 'application/octet-stream'
return new NextResponse(fileBuffer, {
status: 200,
headers: {
'Content-Type': contentType,
'Content-Length': String(stat.size),
'Cache-Control': 'private, max-age=3600',
'Content-Disposition': 'inline',
'X-Content-Type-Options': 'nosniff',
},
})
}