fix: harden upload resilience and contracts
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user