Skip to content

Commit bb42bfb

Browse files
storing uploads directly to CSI instead of temp file
1 parent e927933 commit bb42bfb

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

apps/pdf-analyzer-service/src/routes/jobs.routes.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { Router } from 'express';
22
import multer from 'multer';
3+
import path from 'path';
4+
import { v4 as uuidv4 } from 'uuid';
35
import { paths } from '../config/index.js';
46
import { upload, listJobs, getJob, completeJob } from '../controllers/jobs.controller.js';
57

68
const router = Router();
79

8-
const uploadMw = multer({ dest: paths.tmpUploadDir });
10+
const uploadMw = multer({
11+
storage: multer.diskStorage({
12+
destination: paths.uploadsDir,
13+
filename: (_req, file, cb) => {
14+
const id = uuidv4().replace(/-/g, '');
15+
const ext = path.extname(file.originalname) || '.pdf';
16+
cb(null, `${id}${ext}`);
17+
},
18+
}),
19+
});
920

1021
router.post('/v1/uploads', uploadMw.single('file'), upload);
1122
router.get('/v1/jobs', listJobs);

apps/pdf-analyzer-service/src/services/job.service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ class JobService {
1212
ensureDir(paths.uploadsDir);
1313
}
1414

15-
createJobFromUpload(tempPath: string, originalName: string): string {
16-
const id = uuidv4().replace(/-/g, '');
17-
const ext = path.extname(originalName) || '.pdf';
18-
const finalPath = path.join(paths.uploadsDir, `${id}${ext}`);
19-
fs.renameSync(tempPath, finalPath);
15+
createJobFromUpload(filePath: string, originalName: string): string {
16+
// Extract ID from the filename (multer has already named it with UUID + extension)
17+
const id = path.basename(filePath, path.extname(filePath));
2018
const now = new Date().toISOString();
2119
const job: Job = {
2220
id,
2321
status: 'queued',
24-
filePath: finalPath,
22+
filePath,
2523
originalName,
2624
createdAt: now,
2725
updatedAt: now,

0 commit comments

Comments
 (0)