fix: OCR API error
All checks were successful
Deploy to Staging / Build Images (push) Successful in 7m45s
Deploy to Staging / Deploy to Staging (push) Successful in 51s
Deploy to Staging / Verify Staging (push) Successful in 2m31s
Deploy to Staging / Notify Staging Ready (push) Successful in 8s
Deploy to Staging / Notify Staging Failure (push) Has been skipped

This commit is contained in:
Eric Gullickson
2026-02-06 13:01:32 -06:00
parent 88db803b6a
commit 66314a0493
6 changed files with 244 additions and 26 deletions

View File

@@ -123,6 +123,106 @@ export class OcrController {
}
}
/**
* POST /api/ocr/extract/vin
* Extract VIN from an uploaded image using VIN-specific OCR.
*/
async extractVin(
request: FastifyRequest,
reply: FastifyReply
) {
const userId = (request as any).user?.sub as string;
logger.info('VIN extract requested', {
operation: 'ocr.controller.extractVin',
userId,
});
const file = await (request as any).file({ limits: { files: 1 } });
if (!file) {
logger.warn('No file provided for VIN extraction', {
operation: 'ocr.controller.extractVin.no_file',
userId,
});
return reply.code(400).send({
error: 'Bad Request',
message: 'No file provided',
});
}
const contentType = file.mimetype as string;
if (!SUPPORTED_TYPES.has(contentType)) {
logger.warn('Unsupported file type for VIN extraction', {
operation: 'ocr.controller.extractVin.unsupported_type',
userId,
contentType,
fileName: file.filename,
});
return reply.code(415).send({
error: 'Unsupported Media Type',
message: `Unsupported file type: ${contentType}. Supported: JPEG, PNG, HEIC, PDF`,
});
}
const chunks: Buffer[] = [];
for await (const chunk of file.file) {
chunks.push(chunk);
}
const fileBuffer = Buffer.concat(chunks);
if (fileBuffer.length === 0) {
logger.warn('Empty file provided for VIN extraction', {
operation: 'ocr.controller.extractVin.empty_file',
userId,
fileName: file.filename,
});
return reply.code(400).send({
error: 'Bad Request',
message: 'Empty file provided',
});
}
try {
const result = await ocrService.extractVin(userId, {
fileBuffer,
contentType,
});
logger.info('VIN extract completed', {
operation: 'ocr.controller.extractVin.success',
userId,
success: result.success,
processingTimeMs: result.processingTimeMs,
});
return reply.code(200).send(result);
} catch (error: any) {
if (error.statusCode === 413) {
return reply.code(413).send({
error: 'Payload Too Large',
message: error.message,
});
}
if (error.statusCode === 415) {
return reply.code(415).send({
error: 'Unsupported Media Type',
message: error.message,
});
}
logger.error('VIN extract failed', {
operation: 'ocr.controller.extractVin.error',
userId,
error: error.message,
});
return reply.code(500).send({
error: 'Internal Server Error',
message: 'VIN extraction failed',
});
}
}
/**
* POST /api/ocr/jobs
* Submit an async OCR job for large files.