-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiple-files-processor.ts
More file actions
43 lines (41 loc) · 1.2 KB
/
Copy pathmultiple-files-processor.ts
File metadata and controls
43 lines (41 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { basename } from 'node:path'
import { processFile } from '@backend/services/file-processor/processor'
import type {
FileInput,
FileValidationOptions,
ProcessedFile,
} from '@backend/services/file-processor/types'
export const processMultipleFiles = async (
uploadFiles: FileInput[],
options: Partial<FileValidationOptions> = {},
): Promise<ProcessedFile[]> => {
const results = await Promise.allSettled(uploadFiles.map((file) => processFile(file, options)))
return results.map((result, index) => {
if (result.status === 'fulfilled') {
return result.value
} else {
return {
metadata: {
filename:
uploadFiles[index]?.type === 'filepath'
? basename(uploadFiles[index].path!)
: uploadFiles[index]?.filename || 'unknown',
size: 0,
mimeType: '',
extension: '',
hash: '',
},
buffer: Buffer.alloc(0),
isValid: false,
errors: [
{
field: 'file',
code: 'PROCESSING_FAILED',
message: `Failed to process file: ${result.reason}`,
details: { error: result.reason },
},
],
}
}
})
}