Skip to content

Commit

Permalink
Refactor PDF processing to remove thumbnail deletion and streamline f…
Browse files Browse the repository at this point in the history
…ile saving
  • Loading branch information
Joao-vi committed Jan 17, 2025
1 parent 8dc35e4 commit e33c1c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
4 changes: 0 additions & 4 deletions app/api/files/PDF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ class PDF extends EventEmitter {
return Promise.resolve(response);
}

async deleteThumbnail(filename: string) {
await storage.removeFile(filename, 'thumbnail');
}

async convert() {
return this.extractText().then(conversion => ({
...conversion,
Expand Down
17 changes: 7 additions & 10 deletions app/api/files/processDocument.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-statements */
import { convertToPDFService } from 'api/services/convertToPDF/convertToPdfService';
import settings from 'api/settings';
import { FileType } from 'shared/types/fileType';
Expand Down Expand Up @@ -25,6 +26,12 @@ export const processPDF = async (
conversion.language = file.language;
}

const saved = await files.save({
...upload,
...conversion,
status: 'ready',
});

thumbnail = await pdf.createThumbnail(upload._id.toString());

await files.save({
Expand All @@ -35,18 +42,8 @@ export const processPDF = async (
mimetype: 'image/jpeg',
});

const saved = await files.save({
...upload,
...conversion,
status: 'ready',
});

return saved;
} catch (e) {
if (e.constructor === UpdateFileError) {
await pdf.deleteThumbnail(thumbnail);
}

await files.save({
...upload,
status: 'failed',
Expand Down

0 comments on commit e33c1c6

Please sign in to comment.