Skip to content

Commit

Permalink
Merge pull request #1079 from manuc66/feature/fix-removed-pdf-files
Browse files Browse the repository at this point in the history
Should fix #1078
  • Loading branch information
manuc66 authored Jan 18, 2025
2 parents 22aece0 + c834e68 commit 691a0d2
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/postProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function postProcessing(
toPdf: boolean,
) {
if (toPdf) {
await handlePdfProcessing(
await handlePdfPostProcessing(
folder,
tempFolder,
scanCount,
Expand All @@ -34,7 +34,7 @@ export async function postProcessing(
scanConfig,
);
} else {
await handleImageProcessing(
await handleImagePostProcessing(
folder,
scanCount,
scanJobContent,
Expand All @@ -44,7 +44,7 @@ export async function postProcessing(
}
}

async function handlePdfProcessing(
async function handlePdfPostProcessing(
folder: string,
tempFolder: string,
scanCount: number,
Expand All @@ -63,17 +63,19 @@ async function handlePdfProcessing(
scanDate,
true,
);
displayPdfScan(pdfFilePath, scanJobContent);
if (paperlessConfig) {
await uploadPdfToPaperless(pdfFilePath, paperlessConfig);
}
if (nextcloudConfig) {
await uploadPdfToNextcloud(pdfFilePath, nextcloudConfig);
if (pdfFilePath != null) {
displayPdfScan(pdfFilePath, scanJobContent);
if (paperlessConfig) {
await uploadPdfToPaperless(pdfFilePath, paperlessConfig);
}
if (nextcloudConfig) {
await uploadPdfToNextcloud(pdfFilePath, nextcloudConfig);
}
await cleanUpFilesIfNeeded([pdfFilePath], paperlessConfig, nextcloudConfig);
}
await cleanUpFilesIfNeeded([pdfFilePath], paperlessConfig, nextcloudConfig);
}

async function handleImageProcessing(
async function handleImagePostProcessing(
folder: string,
scanCount: number,
scanJobContent: ScanContent,
Expand Down Expand Up @@ -146,17 +148,17 @@ function displayJpegScan(scanJobContent: ScanContent) {
}

async function cleanUpFilesIfNeeded(
filePaths: (string | null)[],
filePaths: string[],
paperlessConfig: PaperlessConfig | undefined,
nextcloudConfig: NextcloudConfig | undefined,
) {
if (!paperlessConfig?.keepFiles && !nextcloudConfig?.keepFiles) {
let keepFiles: boolean =
paperlessConfig?.keepFiles ?? nextcloudConfig?.keepFiles ?? true;
if (!keepFiles) {
await Promise.all(
filePaths.map(async (filePath) => {
if (filePath) {
await fs.unlink(filePath);
console.log(`File ${filePath} has been removed from the filesystem`);
}
await fs.unlink(filePath);
console.log(`File ${filePath} has been removed from the filesystem`);
}),
);
}
Expand Down

0 comments on commit 691a0d2

Please sign in to comment.