fix: harden upload resilience and contracts

This commit is contained in:
Tom Boullay
2026-05-12 23:49:30 +02:00
parent 101af23418
commit 606df93b69
19 changed files with 479 additions and 159 deletions
+13 -10
View File
@@ -4,8 +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'
import { getErrorMessage } from '@/lib/guards'
import { readStagingRequestBody, uploadErrorResponse } from '@/lib/upload-request'
import type { FileDiff } from '@/lib/types'
export const runtime = 'nodejs'
@@ -22,15 +21,13 @@ export async function POST(req: NextRequest) {
let stagingId: string
try {
const body: unknown = await req.json()
stagingId = parseStagingRequestBody(body).stagingId
stagingId = (await readStagingRequestBody(req)).stagingId
} catch (err) {
const message = getErrorMessage(err)
return NextResponse.json({ success: false, error: message }, { status: 400 })
return uploadErrorResponse(err, 400)
}
try {
const { folderName, filesToPush } = await ensurePreparedStagingAssets(stagingId)
const { folderName, filesToPush, deliveryMode, compressionError } = await ensurePreparedStagingAssets(stagingId)
const folderPath = getModelFolderPath(folderName)
const { exists, files } = await getRemoteFolder(folderPath)
@@ -53,12 +50,18 @@ export async function POST(req: NextRequest) {
exists: true,
path: folderPath,
diffs,
deliveryMode,
compressionError,
})
}
return NextResponse.json({ success: true, exists: false })
return NextResponse.json({
success: true,
exists: false,
deliveryMode,
compressionError,
})
} catch (err) {
const message = getErrorMessage(err)
return NextResponse.json({ success: false, error: message }, { status: 500 })
return uploadErrorResponse(err, 500)
}
}