refactor: strengthen upload boundary types
This commit is contained in:
@@ -4,6 +4,7 @@ import { getRemoteFolder } from '@/lib/github'
|
||||
import { classifyFileChanges } from '@/lib/diff-files'
|
||||
import { getModelFolderPath } from '@/lib/model-paths'
|
||||
import { ensurePreparedStagingAssets } from '@/lib/upload-staging'
|
||||
import { parseStagingRequestBody } from '@/lib/upload-request'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -19,11 +20,8 @@ export async function POST(req: NextRequest) {
|
||||
let stagingId: string
|
||||
|
||||
try {
|
||||
const body = await req.json()
|
||||
stagingId = body.stagingId
|
||||
if (!stagingId || typeof stagingId !== 'string') {
|
||||
throw new Error('stagingId manquant')
|
||||
}
|
||||
const body: unknown = await req.json()
|
||||
stagingId = parseStagingRequestBody(body).stagingId
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||
return NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
findNextVersion,
|
||||
} from '@/lib/nextcloud'
|
||||
import { acquireUploadLock, releaseUploadLock } from '@/lib/upload-lock'
|
||||
import { parseDriveRequestBody } from '@/lib/upload-request'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -45,15 +46,13 @@ export async function POST(req: NextRequest) {
|
||||
// --- Parse staging request ---
|
||||
let folderName: string
|
||||
let parsedFiles: Awaited<ReturnType<typeof readStagedOriginalFiles>>['files']
|
||||
let action: string
|
||||
let action: 'new' | 'replace'
|
||||
|
||||
try {
|
||||
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 body: unknown = await req.json()
|
||||
const parsedBody = parseDriveRequestBody(body)
|
||||
action = parsedBody.action
|
||||
const stagingId = parsedBody.stagingId
|
||||
const staged = await readStagedOriginalFiles(stagingId)
|
||||
folderName = staged.folderName
|
||||
parsedFiles = staged.files
|
||||
|
||||
@@ -6,6 +6,7 @@ import { classifyFileChanges } from '@/lib/diff-files'
|
||||
import { getModelFolderPath } from '@/lib/model-paths'
|
||||
import { cleanupStagingUpload, ensurePreparedStagingAssets, readStagedManifest } from '@/lib/upload-staging'
|
||||
import { acquireUploadLock, releaseUploadLock } from '@/lib/upload-lock'
|
||||
import { parseStagingRequestBody } from '@/lib/upload-request'
|
||||
|
||||
export const runtime = 'nodejs'
|
||||
export const dynamic = 'force-dynamic'
|
||||
@@ -23,11 +24,8 @@ export async function POST(req: NextRequest) {
|
||||
let stagingId: string
|
||||
|
||||
try {
|
||||
const body = await req.json()
|
||||
stagingId = body.stagingId
|
||||
if (!stagingId || typeof stagingId !== 'string') {
|
||||
throw new Error('stagingId manquant')
|
||||
}
|
||||
const body: unknown = await req.json()
|
||||
stagingId = parseStagingRequestBody(body).stagingId
|
||||
const manifest = await readStagedManifest(stagingId)
|
||||
folderName = manifest.folderName
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user