refactor: stage uploads before drive and git delivery
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { validateUploadSecret } from '@/lib/auth'
|
||||
import { parseMultiUpload } from '@/lib/parse-upload'
|
||||
import { getRemoteFolder } from '@/lib/github'
|
||||
import { classifyFileChanges } from '@/lib/diff-files'
|
||||
import { prepareGitAssets } from '@/lib/prepare-git-assets'
|
||||
import { ensurePreparedStagingAssets } from '@/lib/upload-staging'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -16,22 +15,22 @@ export async function POST(req: NextRequest) {
|
||||
const authError = validateUploadSecret(req)
|
||||
if (authError) return authError
|
||||
|
||||
let folderName: string
|
||||
let parsedFiles: Awaited<ReturnType<typeof parseMultiUpload>>['files']
|
||||
let stagingId: string
|
||||
|
||||
try {
|
||||
const parsed = await parseMultiUpload(req)
|
||||
folderName = parsed.folderName
|
||||
parsedFiles = parsed.files
|
||||
const body = await req.json()
|
||||
stagingId = body.stagingId
|
||||
if (!stagingId || typeof stagingId !== 'string') {
|
||||
throw new Error('stagingId manquant')
|
||||
}
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
}
|
||||
|
||||
const folderPath = `public/models/${folderName}`
|
||||
|
||||
try {
|
||||
const { filesToPush } = await prepareGitAssets({ folderName, parsedFiles })
|
||||
const { folderName, filesToPush } = await ensurePreparedStagingAssets(stagingId)
|
||||
const folderPath = `public/models/${folderName}`
|
||||
const { exists, files } = await getRemoteFolder(folderPath)
|
||||
|
||||
if (exists) {
|
||||
|
||||
Reference in New Issue
Block a user