Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
manuc66 committed Nov 18, 2024
1 parent 6bad6ce commit 99f2c2c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
2 changes: 0 additions & 2 deletions src/ScanContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ export interface ScanPage {
xResolution: number;
yResolution: number;
}


4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os from "os";
import { Command, Option, OptionValues, program } from "commander";
import { Bonjour } from 'bonjour-service'
import { Bonjour } from "bonjour-service";
import config from "config";
import HPApi from "./HPApi";
import PathHelper from "./PathHelper";
Expand Down Expand Up @@ -174,7 +174,7 @@ async function clearRegistrationsCmd(cmd: Command) {

function findOfficejetIp(deviceNamePrefix: string): Promise<string> {
return new Promise((resolve) => {
const bonjour = new Bonjour()
const bonjour = new Bonjour();
console.log("Searching device...");
const browser = bonjour.find(
{
Expand Down
2 changes: 1 addition & 1 deletion src/paperless/PaperlessConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export type PaperlessConfig = {
keepFiles: boolean;
groupMultiPageScanIntoAPdf: boolean;
alwaysSendAsPdfFile: boolean;
};
};
40 changes: 28 additions & 12 deletions src/paperless/paperless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,82 @@ import fs from "fs/promises";
import { convertToPdf, mergeToPdf } from "../pdfProcessing";
import { PaperlessConfig } from "./PaperlessConfig";

export async function uploadImagesAsSeparateDocumentsToPaperless(scanJobContent: ScanContent, paperlessConfig: PaperlessConfig) {
export async function uploadImagesAsSeparateDocumentsToPaperless(
scanJobContent: ScanContent,
paperlessConfig: PaperlessConfig,
) {
for (let i = 0; i < scanJobContent.elements.length; ++i) {
const filePath = scanJobContent.elements[i].path;
await uploadToPaperless(filePath, paperlessConfig);
if (!paperlessConfig.keepFiles) {
await fs.unlink(filePath);
console.log(
`Image document ${filePath} has been removed from the filesystem`
`Image document ${filePath} has been removed from the filesystem`,
);
}
}
}

export async function convertImagesToPdfAndUploadAsSeparateDocumentsToPaperless(scanJobContent: ScanContent, paperlessConfig: PaperlessConfig) {
export async function convertImagesToPdfAndUploadAsSeparateDocumentsToPaperless(
scanJobContent: ScanContent,
paperlessConfig: PaperlessConfig,
) {
for (let i = 0; i < scanJobContent.elements.length; ++i) {
const pdfFilePath = await convertToPdf(
scanJobContent.elements[i],
!paperlessConfig.keepFiles
!paperlessConfig.keepFiles,
);
if (pdfFilePath) {
await uploadToPaperless(pdfFilePath, paperlessConfig);
await fs.unlink(pdfFilePath);
} else {
console.log(
"Pdf generation has failed, nothing is going to be uploaded to paperless for: " +
scanJobContent.elements[i].path
scanJobContent.elements[i].path,
);
}
}
}

export async function mergeToPdfAndUploadAsSingleDocumentToPaperless(folder: string, scanCount: number, scanJobContent: ScanContent, scanConfig: ScanConfig, scanDate: Date, paperlessConfig: PaperlessConfig) {
export async function mergeToPdfAndUploadAsSingleDocumentToPaperless(
folder: string,
scanCount: number,
scanJobContent: ScanContent,
scanConfig: ScanConfig,
scanDate: Date,
paperlessConfig: PaperlessConfig,
) {
const pdfFilePath = await mergeToPdf(
folder,
scanCount,
scanJobContent,
scanConfig.directoryConfig.filePattern,
scanDate,
!paperlessConfig.keepFiles
!paperlessConfig.keepFiles,
);
if (pdfFilePath) {
await uploadToPaperless(pdfFilePath, paperlessConfig);
await fs.unlink(pdfFilePath);
console.log(
`Pdf document ${pdfFilePath} has been removed from the filesystem`
`Pdf document ${pdfFilePath} has been removed from the filesystem`,
);
} else {
console.log(
"Pdf generation has failed, nothing is going to be uploaded to paperless"
"Pdf generation has failed, nothing is going to be uploaded to paperless",
);
}
}

export async function uploadPdfToPaperless(pdfFilePath: string | null, paperlessConfig: PaperlessConfig) {
export async function uploadPdfToPaperless(
pdfFilePath: string | null,
paperlessConfig: PaperlessConfig,
) {
if (pdfFilePath) {
await uploadToPaperless(pdfFilePath, paperlessConfig);
if (!paperlessConfig.keepFiles) {
await fs.unlink(pdfFilePath);
console.log(
`Pdf document ${pdfFilePath} has been removed from the filesystem`
`Pdf document ${pdfFilePath} has been removed from the filesystem`,
);
}
} else {
Expand Down Expand Up @@ -103,4 +119,4 @@ async function uploadToPaperless(
console.error("Fail to upload document:", error);
}
fileStream.close();
}
}
2 changes: 1 addition & 1 deletion src/pdfProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ export async function createPdfFrom(
doc.addImage(imageByteBuffer, "JPEG", 0, 0, widthInInches, heightInInches);
}
doc?.save(destination);
}
}
7 changes: 4 additions & 3 deletions src/postProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { ScanContent } from "./ScanContent";
import { mergeToPdf } from "./pdfProcessing";
import {
convertImagesToPdfAndUploadAsSeparateDocumentsToPaperless,
mergeToPdfAndUploadAsSingleDocumentToPaperless, uploadImagesAsSeparateDocumentsToPaperless,
uploadPdfToPaperless
mergeToPdfAndUploadAsSingleDocumentToPaperless,
uploadImagesAsSeparateDocumentsToPaperless,
uploadPdfToPaperless,
} from "./paperless/paperless";
import { ScanConfig } from "./scanProcessing";

Expand Down Expand Up @@ -87,4 +88,4 @@ function displayJpegScan(scanJobContent: ScanContent) {
} - ${e.path}`,
),
);
}
}

0 comments on commit 99f2c2c

Please sign in to comment.