Skip to content

Commit 7183764

Browse files
committed
cleanup
1 parent 6833cde commit 7183764

File tree

4 files changed

+78
-295
lines changed

4 files changed

+78
-295
lines changed

backend/src/document-processor/controllers/document-processor.controller.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ export class DocumentProcessorController {
4848
}
4949

5050
// Validate file type
51-
const validMimeTypes = ['image/jpeg', 'image/png', 'image/tiff', 'application/pdf'];
51+
const validMimeTypes = [
52+
'image/jpeg',
53+
'image/png',
54+
'image/heic',
55+
'image/heif',
56+
'application/pdf',
57+
];
5258

5359
if (!validMimeTypes.includes(file.mimetype)) {
5460
throw new BadRequestException(
55-
`Invalid file type: ${file.mimetype}. Supported types: JPEG, PNG, TIFF, and PDF.`,
61+
`Invalid file type: ${file.mimetype}. Supported types: JPEG, PNG, HEIC, HEIF, and PDF.`,
5662
);
5763
}
5864

@@ -373,8 +379,8 @@ export class DocumentProcessorController {
373379
374380
<form id="uploadForm" enctype="multipart/form-data">
375381
<div class="form-group">
376-
<label for="file">Select File (PDF, JPEG, PNG, TIFF):</label>
377-
<input type="file" id="file" name="file" accept=".pdf,.jpg,.jpeg,.png,.tiff">
382+
<label for="file">Select File (PDF, JPEG, PNG, HEIC, HEIF):</label>
383+
<input type="file" id="file" name="file" accept=".pdf,.jpg,.jpeg,.png,.heic,.heif">
378384
</div>
379385
380386
<div id="filePreview"></div>

backend/src/document-processor/services/aws-textract.service.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { vi, describe, it, expect, beforeEach } from 'vitest';
55

66
// Mock the security.utils module
77
vi.mock('../../utils/security.utils', () => ({
8-
validateFileSecurely: vi.fn(),
98
RateLimiter: vi.fn().mockImplementation(() => ({
109
tryRequest: vi.fn().mockReturnValue(true),
1110
})),

backend/src/document-processor/services/aws-textract.service.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, Logger, BadRequestException } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
33
import { TextractClient, AnalyzeDocumentCommand, Block } from '@aws-sdk/client-textract';
4-
import { validateFileSecurely, RateLimiter } from '../../utils/security.utils';
4+
import { RateLimiter } from '../../utils/security.utils';
55
import { createHash } from 'crypto';
66

77
export interface ExtractedTextResult {
@@ -88,24 +88,18 @@ export class AwsTextractService {
8888
try {
8989
const startTime = Date.now();
9090

91-
// 1. Rate limiting check
9291
if (!this.rateLimiter.tryRequest(userId)) {
9392
throw new BadRequestException('Too many requests. Please try again later.');
9493
}
9594

96-
// 2. Validate file securely
97-
validateFileSecurely(fileBuffer);
98-
9995
// Add diagnostic information about the document being processed
10096
this.logger.debug('Processing document', {
10197
fileSize: `${(fileBuffer.length / 1024).toFixed(2)} KB`,
10298
contentHashPrefix: createHash('sha256').update(fileBuffer).digest('hex').substring(0, 10),
10399
});
104100

105-
// 3. Process document
106101
const result = await this.processDocument(fileBuffer);
107102

108-
// 4. Calculate processing time
109103
const processingTime = Date.now() - startTime;
110104

111105
this.logger.log(`Document processed in ${processingTime}ms`, {

0 commit comments

Comments
 (0)