Skip to content

Commit a8b6081

Browse files
committed
fix type issues
1 parent 165fc4b commit a8b6081

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

  • apps/sim/app/api/tools/jupyter/upload

apps/sim/app/api/tools/jupyter/upload/route.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createLogger } from '@sim/logger'
22
import { getErrorMessage } from '@sim/utils/errors'
3+
import { isPlainRecord } from '@sim/utils/object'
34
import { type NextRequest, NextResponse } from 'next/server'
45
import { jupyterUploadContract } from '@/lib/api/contracts/storage-transfer'
56
import { parseRequest } from '@/lib/api/server'
@@ -129,16 +130,28 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
129130
}
130131

131132
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
132145

133-
logger.info(`[${requestId}] File uploaded to Jupyter: ${uploaded.path}`)
146+
logger.info(`[${requestId}] File uploaded to Jupyter: ${uploadedPath}`)
134147

135148
return NextResponse.json({
136149
success: true,
137150
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,
142155
},
143156
})
144157
} catch (error) {

0 commit comments

Comments
 (0)