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

@@ -8,6 +8,7 @@ import type {
OcrExtractRequest,
OcrJobSubmitRequest,
OcrResponse,
VinExtractionResponse,
} from './ocr.types';
/** Maximum file size for sync processing (10MB) */
@@ -92,6 +93,63 @@ export class OcrService {
}
}
/**
* Extract VIN from an image using VIN-specific OCR.
*
* @param userId - User ID for logging
* @param request - OCR extraction request
* @returns VIN extraction result
*/
async extractVin(userId: string, request: OcrExtractRequest): Promise<VinExtractionResponse> {
if (request.fileBuffer.length > MAX_SYNC_SIZE) {
const err: any = new Error(
`File too large. Max: ${MAX_SYNC_SIZE / (1024 * 1024)}MB.`
);
err.statusCode = 413;
throw err;
}
if (!SUPPORTED_TYPES.has(request.contentType)) {
const err: any = new Error(
`Unsupported file type: ${request.contentType}. Supported: ${[...SUPPORTED_TYPES].join(', ')}`
);
err.statusCode = 415;
throw err;
}
logger.info('VIN extract requested', {
operation: 'ocr.service.extractVin',
userId,
contentType: request.contentType,
fileSize: request.fileBuffer.length,
});
try {
const result = await ocrClient.extractVin(
request.fileBuffer,
request.contentType
);
logger.info('VIN extract completed', {
operation: 'ocr.service.extractVin.success',
userId,
success: result.success,
vin: result.vin,
confidence: result.confidence,
processingTimeMs: result.processingTimeMs,
});
return result;
} catch (error) {
logger.error('VIN extract failed', {
operation: 'ocr.service.extractVin.error',
userId,
error: error instanceof Error ? error.message : 'Unknown error',
});
throw error;
}
}
/**
* Submit an async OCR job for large files.
*