|
1 | 1 | import { createLogger } from '@sim/logger' |
2 | 2 | import { getErrorMessage } from '@sim/utils/errors' |
| 3 | +import { isPlainRecord } from '@sim/utils/object' |
3 | 4 | import { type NextRequest, NextResponse } from 'next/server' |
4 | 5 | import { jupyterUploadContract } from '@/lib/api/contracts/storage-transfer' |
5 | 6 | import { parseRequest } from '@/lib/api/server' |
@@ -129,16 +130,28 @@ export const POST = withRouteHandler(async (request: NextRequest) => { |
129 | 130 | } |
130 | 131 |
|
131 | 132 | const uploaded = await response.json() |
| 133 | + if (!isPlainRecord(uploaded)) { |
| 134 | + logger.error(`[${requestId}] Jupyter returned an invalid upload response`) |
| 135 | + return NextResponse.json( |
| 136 | + { success: false, error: 'Jupyter returned an invalid upload response' }, |
| 137 | + { status: 502 } |
| 138 | + ) |
| 139 | + } |
| 140 | + |
| 141 | + const uploadedName = typeof uploaded.name === 'string' ? uploaded.name : fileName |
| 142 | + const uploadedPath = typeof uploaded.path === 'string' ? uploaded.path : destinationPath |
| 143 | + const uploadedSize = typeof uploaded.size === 'number' ? uploaded.size : fileBuffer.length |
| 144 | + const lastModified = typeof uploaded.last_modified === 'string' ? uploaded.last_modified : null |
132 | 145 |
|
133 | | - logger.info(`[${requestId}] File uploaded to Jupyter: ${uploaded.path}`) |
| 146 | + logger.info(`[${requestId}] File uploaded to Jupyter: ${uploadedPath}`) |
134 | 147 |
|
135 | 148 | return NextResponse.json({ |
136 | 149 | success: true, |
137 | 150 | output: { |
138 | | - name: uploaded.name ?? fileName, |
139 | | - path: uploaded.path ?? destinationPath, |
140 | | - size: uploaded.size ?? fileBuffer.length, |
141 | | - lastModified: uploaded.last_modified ?? null, |
| 151 | + name: uploadedName, |
| 152 | + path: uploadedPath, |
| 153 | + size: uploadedSize, |
| 154 | + lastModified, |
142 | 155 | }, |
143 | 156 | }) |
144 | 157 | } catch (error) { |
|
0 commit comments