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.
This commit is contained in:
@@ -4,8 +4,8 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const { session } = await requireAdmin()
|
||||
if (!session?.id) return new NextResponse('Unauthorized', { status: 401 })
|
||||
const userId = session.id
|
||||
if (!session?.sub) return new NextResponse('Unauthorized', { status: 401 })
|
||||
const userId = session.sub
|
||||
|
||||
try {
|
||||
const body = await request.json()
|
||||
@@ -25,8 +25,8 @@ export async function POST(request: NextRequest) {
|
||||
description: f.description,
|
||||
date: f.date,
|
||||
location: f.location,
|
||||
incident_type: f.incident_type as any,
|
||||
priority: f.priority as any
|
||||
incident_type: f.incident_type as 'env' | 'asset' | 'security' | 'fire' | undefined,
|
||||
priority: f.priority as 'low' | 'med' | 'high' | undefined
|
||||
}))
|
||||
|
||||
// Create incidents with user ID
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { requireAdmin } from '@/lib/auth/require-admin'
|
||||
import { analyzePdfsWithDeepSeek } from '@/lib/incidents/bulk-import'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { mkdir, readdir, readFile, rm, writeFile } from 'fs/promises'
|
||||
import { mkdir, readdir, rm, writeFile } from 'fs/promises'
|
||||
import path from 'path'
|
||||
import { tmpdir } from 'os'
|
||||
import { exec } from 'child_process'
|
||||
@@ -35,14 +35,14 @@ export async function POST(request: NextRequest) {
|
||||
await writeFile(uploadedFilePath, buffer)
|
||||
|
||||
// If .zip, extract; otherwise treat as folder
|
||||
let extractDir = tempDir
|
||||
const extractDir = tempDir
|
||||
if (file.name.endsWith('.zip')) {
|
||||
await execAsync(`unzip -q "${uploadedFilePath}" -d "${extractDir}"`)
|
||||
}
|
||||
|
||||
// Scan extracted folders
|
||||
// Scan extracted folders (skip __MACOSX)
|
||||
const entries = await readdir(extractDir, { withFileTypes: true })
|
||||
const folders = entries.filter((e) => e.isDirectory())
|
||||
const folders = entries.filter((e) => e.isDirectory() && e.name !== '__MACOSX')
|
||||
|
||||
const results = []
|
||||
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import crypto from 'node:crypto'
|
||||
import { getSession } from '@/lib/auth/get-session'
|
||||
import { signEvidencePath } from '@/lib/storage/evidence'
|
||||
import { asAdmin } from '@/lib/db/with-user'
|
||||
import { evidenceFiles } from '@/lib/db/schema'
|
||||
import { eq } from 'drizzle-orm'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user