@@ -253,7 +253,27 @@ async function pollForJobCompletion(
253253
254254 if ( jobStatus === 'PARTIAL_SUCCESS' ) {
255255 logger . warn ( `[${ requestId } ] Job completed with partial success: ${ result . StatusMessage } ` )
256- return result
256+
257+ let allBlocks = ( result . Blocks as unknown [ ] ) || [ ]
258+ let nextToken = result . NextToken as string | undefined
259+
260+ while ( nextToken ) {
261+ const nextResult = await callTextractAsync (
262+ host ,
263+ getTarget ,
264+ { JobId : jobId , NextToken : nextToken } ,
265+ accessKeyId ,
266+ secretAccessKey ,
267+ region
268+ )
269+ allBlocks = allBlocks . concat ( ( nextResult . Blocks as unknown [ ] ) || [ ] )
270+ nextToken = nextResult . NextToken as string | undefined
271+ }
272+
273+ return {
274+ ...result ,
275+ Blocks : allBlocks ,
276+ }
257277 }
258278
259279 logger . info ( `[${ requestId } ] Job status: ${ jobStatus } , attempt ${ attempt + 1 } /${ maxAttempts } ` )
@@ -295,8 +315,8 @@ export async function POST(request: NextRequest) {
295315
296316 logger . info ( `[${ requestId } ] Textract parse request` , {
297317 processingMode,
298- filePath : validatedData . filePath ,
299- s3Uri : validatedData . s3Uri ,
318+ filePath : validatedData . filePath ?. substring ( 0 , 50 ) ,
319+ s3Uri : validatedData . s3Uri ?. substring ( 0 , 50 ) ,
300320 featureTypes,
301321 userId,
302322 } )
@@ -465,6 +485,19 @@ export async function POST(request: NextRequest) {
465485 )
466486 }
467487 } else if ( validatedData . filePath ?. startsWith ( '/' ) ) {
488+ if ( ! validatedData . filePath . startsWith ( '/api/files/serve/' ) ) {
489+ logger . warn ( `[${ requestId } ] Invalid internal path` , {
490+ userId,
491+ path : validatedData . filePath . substring ( 0 , 50 ) ,
492+ } )
493+ return NextResponse . json (
494+ {
495+ success : false ,
496+ error : 'Invalid file path. Only uploaded files are supported for internal paths.' ,
497+ } ,
498+ { status : 400 }
499+ )
500+ }
468501 const baseUrl = getBaseUrl ( )
469502 fileUrl = `${ baseUrl } ${ validatedData . filePath } `
470503 } else {
0 commit comments