Skip to content

Commit 75450af

Browse files
committed
ack pr comments
1 parent dbee20e commit 75450af

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

apps/sim/app/api/tools/textract/parse/route.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

apps/sim/tools/textract/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export const textractParserTool: ToolConfig<TextractParserInput, TextractParserO
280280
textractData.DocumentMetadata?.Pages ?? textractData.documentMetadata?.pages ?? 0,
281281
},
282282
modelVersion:
283+
textractData.modelVersion ??
283284
textractData.AnalyzeDocumentModelVersion ??
284285
textractData.analyzeDocumentModelVersion ??
285286
textractData.DetectDocumentTextModelVersion ??

0 commit comments

Comments
 (0)