node-hp-scan-to 1.4.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -23
- package/dist/Destination.js +2 -2
- package/dist/Destination.js.map +1 -1
- package/dist/EventTable.js +1 -1
- package/dist/EventTable.js.map +1 -1
- package/dist/HPApi.d.ts +1 -0
- package/dist/HPApi.js +7 -4
- package/dist/HPApi.js.map +1 -1
- package/dist/Job.js +2 -2
- package/dist/Job.js.map +1 -1
- package/dist/JpegUtil.d.ts +1 -0
- package/dist/PaperlessCOnfig.d.ts +7 -0
- package/dist/PaperlessCOnfig.js +3 -0
- package/dist/PaperlessCOnfig.js.map +1 -0
- package/dist/PaperlessConfig.d.ts +7 -0
- package/dist/PaperlessConfig.js +3 -0
- package/dist/PaperlessConfig.js.map +1 -0
- package/dist/ScanCaps.js +12 -2
- package/dist/ScanCaps.js.map +1 -1
- package/dist/ScanContent.d.ts +0 -1
- package/dist/ScanContent.js +0 -24
- package/dist/ScanContent.js.map +1 -1
- package/dist/ScanJobSettings.js +2 -2
- package/dist/ScanJobSettings.js.map +1 -1
- package/dist/ScanStatus.d.ts +1 -1
- package/dist/ScanStatus.js.map +1 -1
- package/dist/WalkupScanDestinations.js +1 -1
- package/dist/WalkupScanDestinations.js.map +1 -1
- package/dist/WalkupScanToCompDestinations.js +1 -1
- package/dist/WalkupScanToCompDestinations.js.map +1 -1
- package/dist/commitInfo.json +3 -0
- package/dist/healthcheck.d.ts +1 -0
- package/dist/healthcheck.js +24 -0
- package/dist/healthcheck.js.map +1 -0
- package/dist/index.js +109 -19
- package/dist/index.js.map +1 -1
- package/dist/listening.js +2 -2
- package/dist/listening.js.map +1 -1
- package/dist/paperless/PaperlessConfig.d.ts +7 -0
- package/dist/paperless/PaperlessConfig.js +3 -0
- package/dist/paperless/PaperlessConfig.js.map +1 -0
- package/dist/paperless/paperless.d.ts +7 -0
- package/dist/paperless/paperless.js +83 -0
- package/dist/paperless/paperless.js.map +1 -0
- package/dist/paperless.d.ts +7 -0
- package/dist/paperless.js +83 -0
- package/dist/paperless.js.map +1 -0
- package/dist/pdfProcessing.d.ts +4 -0
- package/dist/pdfProcessing.js +52 -0
- package/dist/pdfProcessing.js.map +1 -0
- package/dist/postProcessing.d.ts +3 -0
- package/dist/postProcessing.js +44 -0
- package/dist/postProcessing.js.map +1 -0
- package/dist/scanProcessing.d.ts +7 -1
- package/dist/scanProcessing.js +23 -49
- package/dist/scanProcessing.js.map +1 -1
- package/dist/test/PathHelper.test.js +2 -2
- package/dist/test/PathHelper.test.js.map +1 -1
- package/dist/test/ScanCaps.test.js +20 -0
- package/dist/test/ScanCaps.test.js.map +1 -1
- package/dist/test/scanProcessing.test.js +1 -0
- package/dist/test/scanProcessing.test.js.map +1 -1
- package/dist/test-bonjour.d.ts +1 -0
- package/dist/test-bonjour.js +20 -0
- package/dist/test-bonjour.js.map +1 -0
- package/package.json +14 -11
- package/src/Destination.ts +2 -2
- package/src/EventTable.ts +1 -1
- package/src/HPApi.ts +9 -6
- package/src/Job.ts +2 -2
- package/src/ScanCaps.ts +18 -8
- package/src/ScanContent.ts +0 -22
- package/src/ScanJobSettings.ts +2 -2
- package/src/ScanStatus.ts +1 -1
- package/src/WalkupScanDestinations.ts +1 -1
- package/src/WalkupScanToCompDestinations.ts +1 -1
- package/src/commitInfo.json +3 -0
- package/src/healthcheck.ts +17 -0
- package/src/index.ts +135 -24
- package/src/listening.ts +2 -2
- package/src/paperless/PaperlessConfig.ts +7 -0
- package/src/paperless/paperless.ts +122 -0
- package/src/pdfProcessing.ts +67 -0
- package/src/postProcessing.ts +91 -0
- package/src/scanProcessing.ts +50 -92
package/src/scanProcessing.ts
CHANGED
|
@@ -7,12 +7,14 @@ import JpegUtil from "./JpegUtil";
|
|
|
7
7
|
import { DeviceCapabilities } from "./DeviceCapabilities";
|
|
8
8
|
import { waitForScanEvent, waitScanRequest } from "./listening";
|
|
9
9
|
import ScanJobSettings from "./ScanJobSettings";
|
|
10
|
-
import {
|
|
10
|
+
import { ScanContent, ScanPage } from "./ScanContent";
|
|
11
11
|
import Job from "./Job";
|
|
12
12
|
import { delay } from "./delay";
|
|
13
13
|
import PathHelper from "./PathHelper";
|
|
14
14
|
import ScanStatus from "./ScanStatus";
|
|
15
15
|
import { InputSource } from "./InputSource";
|
|
16
|
+
import { PaperlessConfig } from "./paperless/PaperlessConfig";
|
|
17
|
+
import { postProcessing } from "./postProcessing";
|
|
16
18
|
|
|
17
19
|
async function waitDeviceUntilItIsReadyToUploadOrCompleted(
|
|
18
20
|
jobUrl: string,
|
|
@@ -38,7 +40,7 @@ async function waitDeviceUntilItIsReadyToUploadOrCompleted(
|
|
|
38
40
|
return job;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
async function
|
|
43
|
+
async function tryGetDestination(
|
|
42
44
|
event: Event,
|
|
43
45
|
): Promise<WalkupScanDestination | WalkupScanToCompDestination | null> {
|
|
44
46
|
//this code can in some cases be executed before the user actually chooses between Document or Photo
|
|
@@ -71,7 +73,7 @@ async function TryGetDestination(
|
|
|
71
73
|
async function scanProcessing(filePath: string): Promise<number | null> {
|
|
72
74
|
const buffer: Buffer = await fs.readFile(filePath);
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
const height = JpegUtil.fixSizeWithDNL(buffer);
|
|
75
77
|
if (height != null) {
|
|
76
78
|
// rewrite the fixed file
|
|
77
79
|
await fs.writeFile(filePath, buffer);
|
|
@@ -86,7 +88,7 @@ function createScanPage(
|
|
|
86
88
|
filePath: string,
|
|
87
89
|
sizeFixed: number | null,
|
|
88
90
|
): ScanPage {
|
|
89
|
-
|
|
91
|
+
const height = sizeFixed ?? job.imageHeight;
|
|
90
92
|
return {
|
|
91
93
|
path: filePath,
|
|
92
94
|
pageNumber: currentPageNumber,
|
|
@@ -97,7 +99,7 @@ function createScanPage(
|
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
101
|
|
|
100
|
-
async function
|
|
102
|
+
async function handleScanProcessingState(
|
|
101
103
|
job: Job,
|
|
102
104
|
inputSource: InputSource,
|
|
103
105
|
folder: string,
|
|
@@ -168,7 +170,7 @@ async function executeScanJob(
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
if (job.jobState === "Processing") {
|
|
171
|
-
const page = await
|
|
173
|
+
const page = await handleScanProcessingState(
|
|
172
174
|
job,
|
|
173
175
|
inputSource,
|
|
174
176
|
folder,
|
|
@@ -201,9 +203,9 @@ async function waitScanNewPageRequest(compEventURI: string): Promise<boolean> {
|
|
|
201
203
|
while (wait) {
|
|
202
204
|
await new Promise((resolve) => setTimeout(resolve, 1000)); //wait 1s
|
|
203
205
|
|
|
204
|
-
|
|
206
|
+
const walkupScanToCompEvent =
|
|
205
207
|
await HPApi.getWalkupScanToCompEvent(compEventURI);
|
|
206
|
-
|
|
208
|
+
const message = walkupScanToCompEvent.eventType;
|
|
207
209
|
|
|
208
210
|
if (message === "ScanNewPageRequested") {
|
|
209
211
|
startNewScanJob = true;
|
|
@@ -281,59 +283,6 @@ async function executeScanJobs(
|
|
|
281
283
|
}
|
|
282
284
|
}
|
|
283
285
|
|
|
284
|
-
async function mergeToPdf(
|
|
285
|
-
folder: string,
|
|
286
|
-
scanCount: number,
|
|
287
|
-
scanJobContent: ScanContent,
|
|
288
|
-
filePattern: string | undefined,
|
|
289
|
-
date: Date,
|
|
290
|
-
): Promise<string | null> {
|
|
291
|
-
if (scanJobContent.elements.length > 0) {
|
|
292
|
-
const pdfFilePath: string = PathHelper.getFileForScan(
|
|
293
|
-
folder,
|
|
294
|
-
scanCount,
|
|
295
|
-
filePattern,
|
|
296
|
-
"pdf",
|
|
297
|
-
date,
|
|
298
|
-
);
|
|
299
|
-
await createPdfFrom(scanJobContent, pdfFilePath);
|
|
300
|
-
scanJobContent.elements.forEach((e) => fs.unlink(e.path));
|
|
301
|
-
return pdfFilePath;
|
|
302
|
-
}
|
|
303
|
-
console.log(`No page available to build a pdf file`);
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function displayPdfScan(
|
|
308
|
-
pdfFilePath: string | null,
|
|
309
|
-
scanJobContent: ScanContent,
|
|
310
|
-
) {
|
|
311
|
-
if (pdfFilePath === null) {
|
|
312
|
-
console.log(`Pdf generated has not been generated`);
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
console.log(
|
|
316
|
-
`The following page(s) have been rendered inside '${pdfFilePath}': `,
|
|
317
|
-
);
|
|
318
|
-
scanJobContent.elements.forEach((e) =>
|
|
319
|
-
console.log(
|
|
320
|
-
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
321
|
-
e.height
|
|
322
|
-
}`,
|
|
323
|
-
),
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function displayJpegScan(scanJobContent: ScanContent) {
|
|
328
|
-
scanJobContent.elements.forEach((e) =>
|
|
329
|
-
console.log(
|
|
330
|
-
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
331
|
-
e.height
|
|
332
|
-
} - ${e.path}`,
|
|
333
|
-
),
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
286
|
function isPdf(
|
|
338
287
|
destination: WalkupScanDestination | WalkupScanToCompDestination,
|
|
339
288
|
) {
|
|
@@ -360,7 +309,7 @@ export function getScanWidth(
|
|
|
360
309
|
scanConfig: ScanConfig,
|
|
361
310
|
inputSource: InputSource,
|
|
362
311
|
deviceCapabilities: DeviceCapabilities,
|
|
363
|
-
) {
|
|
312
|
+
): number | null {
|
|
364
313
|
if (scanConfig.width && scanConfig.width > 0) {
|
|
365
314
|
const maxWidth =
|
|
366
315
|
inputSource === InputSource.Adf
|
|
@@ -373,7 +322,9 @@ export function getScanWidth(
|
|
|
373
322
|
return scanConfig.width;
|
|
374
323
|
}
|
|
375
324
|
} else {
|
|
376
|
-
return
|
|
325
|
+
return inputSource === InputSource.Adf
|
|
326
|
+
? deviceCapabilities.adfMaxWidth
|
|
327
|
+
: deviceCapabilities.platenMaxWidth;
|
|
377
328
|
}
|
|
378
329
|
}
|
|
379
330
|
|
|
@@ -381,7 +332,7 @@ export function getScanHeight(
|
|
|
381
332
|
scanConfig: ScanConfig,
|
|
382
333
|
inputSource: InputSource,
|
|
383
334
|
deviceCapabilities: DeviceCapabilities,
|
|
384
|
-
) {
|
|
335
|
+
): number | null {
|
|
385
336
|
if (scanConfig.height && scanConfig.height > 0) {
|
|
386
337
|
const maxHeight =
|
|
387
338
|
inputSource === InputSource.Adf
|
|
@@ -394,11 +345,13 @@ export function getScanHeight(
|
|
|
394
345
|
return scanConfig.height;
|
|
395
346
|
}
|
|
396
347
|
} else {
|
|
397
|
-
return
|
|
348
|
+
return inputSource === InputSource.Adf
|
|
349
|
+
? deviceCapabilities.adfMaxHeight
|
|
350
|
+
: deviceCapabilities.platenMaxHeight;
|
|
398
351
|
}
|
|
399
352
|
}
|
|
400
353
|
|
|
401
|
-
export async function
|
|
354
|
+
export async function saveScanFromEvent(
|
|
402
355
|
event: Event,
|
|
403
356
|
folder: string,
|
|
404
357
|
tempFolder: string,
|
|
@@ -413,7 +366,7 @@ export async function saveScan(
|
|
|
413
366
|
}
|
|
414
367
|
}
|
|
415
368
|
|
|
416
|
-
const destination = await
|
|
369
|
+
const destination = await tryGetDestination(event);
|
|
417
370
|
if (!destination) {
|
|
418
371
|
console.log("No shortcut selected!");
|
|
419
372
|
return;
|
|
@@ -441,6 +394,11 @@ export async function saveScan(
|
|
|
441
394
|
console.log("ScanPlexMode is : " + destination.scanPlexMode);
|
|
442
395
|
|
|
443
396
|
const scanStatus = await HPApi.getScanStatus();
|
|
397
|
+
|
|
398
|
+
if (scanStatus.scannerState !== "Idle") {
|
|
399
|
+
console.log("Scanner state is not Idle, aborting scan attempt...!");
|
|
400
|
+
}
|
|
401
|
+
|
|
444
402
|
console.log("Afd is : " + scanStatus.adfState);
|
|
445
403
|
|
|
446
404
|
const inputSource = scanStatus.getInputSource();
|
|
@@ -474,19 +432,15 @@ export async function saveScan(
|
|
|
474
432
|
console.log(
|
|
475
433
|
`Scan of page(s) completed totalPages: ${scanJobContent.elements.length}:`,
|
|
476
434
|
);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
displayPdfScan(pdfFilePath, scanJobContent);
|
|
487
|
-
} else {
|
|
488
|
-
displayJpegScan(scanJobContent);
|
|
489
|
-
}
|
|
435
|
+
await postProcessing(
|
|
436
|
+
scanConfig,
|
|
437
|
+
folder,
|
|
438
|
+
tempFolder,
|
|
439
|
+
scanCount,
|
|
440
|
+
scanJobContent,
|
|
441
|
+
scanDate,
|
|
442
|
+
toPdf,
|
|
443
|
+
);
|
|
490
444
|
}
|
|
491
445
|
|
|
492
446
|
export type DirectoryConfig = {
|
|
@@ -494,11 +448,13 @@ export type DirectoryConfig = {
|
|
|
494
448
|
tempDirectory: string | undefined;
|
|
495
449
|
filePattern: string | undefined;
|
|
496
450
|
};
|
|
451
|
+
|
|
497
452
|
export type ScanConfig = {
|
|
498
453
|
resolution: number;
|
|
499
454
|
width: number | null;
|
|
500
455
|
height: number | null;
|
|
501
456
|
directoryConfig: DirectoryConfig;
|
|
457
|
+
paperlessConfig: PaperlessConfig | undefined;
|
|
502
458
|
};
|
|
503
459
|
export type AdfAutoScanConfig = ScanConfig & {
|
|
504
460
|
isDuplex: boolean;
|
|
@@ -507,6 +463,11 @@ export type AdfAutoScanConfig = ScanConfig & {
|
|
|
507
463
|
startScanDelay: number;
|
|
508
464
|
};
|
|
509
465
|
|
|
466
|
+
export type SingleScanConfig = ScanConfig & {
|
|
467
|
+
isDuplex: boolean;
|
|
468
|
+
generatePdf: boolean;
|
|
469
|
+
};
|
|
470
|
+
|
|
510
471
|
export async function scanFromAdf(
|
|
511
472
|
scanCount: number,
|
|
512
473
|
folder: string,
|
|
@@ -563,18 +524,15 @@ export async function scanFromAdf(
|
|
|
563
524
|
`Scan of page(s) completed, total pages: ${scanJobContent.elements.length}:`,
|
|
564
525
|
);
|
|
565
526
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
} else {
|
|
576
|
-
displayJpegScan(scanJobContent);
|
|
577
|
-
}
|
|
527
|
+
await postProcessing(
|
|
528
|
+
adfAutoScanConfig,
|
|
529
|
+
folder,
|
|
530
|
+
tempFolder,
|
|
531
|
+
scanCount,
|
|
532
|
+
scanJobContent,
|
|
533
|
+
date,
|
|
534
|
+
adfAutoScanConfig.generatePdf,
|
|
535
|
+
);
|
|
578
536
|
}
|
|
579
537
|
|
|
580
538
|
export async function waitAdfLoaded(
|