refactor: stage uploads before drive and git delivery
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { validateUploadSecret } from '@/lib/auth'
|
||||
import { parseMultiUpload } from '@/lib/parse-upload'
|
||||
import { readStagedOriginalFiles } from '@/lib/upload-staging'
|
||||
import {
|
||||
mkdirRecursive,
|
||||
moveFolder,
|
||||
@@ -17,8 +17,8 @@ export const dynamic = 'force-dynamic'
|
||||
//
|
||||
// Upload **original** files (no Blender compression) to Nextcloud Drive.
|
||||
//
|
||||
// FormData fields:
|
||||
// - folderName, files[], fileTypes[], textureNames[] (same as /api/upload/git)
|
||||
// JSON body:
|
||||
// - stagingId
|
||||
// - action: "new" | "replace"
|
||||
//
|
||||
// Versioning logic:
|
||||
@@ -42,16 +42,21 @@ export async function POST(req: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
// --- Parse files (includes extra fields like "action") ---
|
||||
// --- Parse staging request ---
|
||||
let folderName: string
|
||||
let parsedFiles: Awaited<ReturnType<typeof parseMultiUpload>>['files']
|
||||
let parsedFiles: Awaited<ReturnType<typeof readStagedOriginalFiles>>['files']
|
||||
let action: string
|
||||
|
||||
try {
|
||||
const parsed = await parseMultiUpload(req)
|
||||
folderName = parsed.folderName
|
||||
parsedFiles = parsed.files
|
||||
action = parsed.extra.action?.trim() || 'new'
|
||||
const body = await req.json()
|
||||
const stagingId = body.stagingId
|
||||
if (!stagingId || typeof stagingId !== 'string') {
|
||||
throw new Error('stagingId manquant')
|
||||
}
|
||||
action = typeof body.action === 'string' ? body.action.trim() || 'new' : 'new'
|
||||
const staged = await readStagedOriginalFiles(stagingId)
|
||||
folderName = staged.folderName
|
||||
parsedFiles = staged.files
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
|
||||
Reference in New Issue
Block a user