node-hp-scan-to 1.6.1 → 1.7.1
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 +247 -143
- package/dist/Destination.js +17 -7
- package/dist/Destination.js.map +1 -1
- package/dist/DeviceCapabilities.d.ts +2 -0
- package/dist/DeviceCapabilities.js.map +1 -1
- package/dist/DiscoveryTree.js.map +1 -1
- package/dist/Event.js.map +1 -1
- package/dist/EventTable.js.map +1 -1
- package/dist/HPApi.js +23 -15
- package/dist/HPApi.js.map +1 -1
- package/dist/InputSource.js +1 -1
- package/dist/InputSource.js.map +1 -1
- package/dist/Job.js +6 -6
- package/dist/Job.js.map +1 -1
- package/dist/JpegUtil.d.ts +0 -2
- package/dist/JpegUtil.js.map +1 -1
- package/dist/KnownShortcut.js.map +1 -1
- package/dist/PathHelper.js +2 -0
- package/dist/PathHelper.js.map +1 -1
- package/dist/ScanCaps.d.ts +6 -0
- package/dist/ScanCaps.js +18 -0
- package/dist/ScanCaps.js.map +1 -1
- package/dist/ScanContent.js.map +1 -1
- package/dist/ScanJobManifest.js.map +1 -1
- package/dist/ScanJobSettings.js.map +1 -1
- package/dist/ScanStatus.js.map +1 -1
- package/dist/WalkupScanDestination.js.map +1 -1
- package/dist/WalkupScanDestinations.js.map +1 -1
- package/dist/WalkupScanManifest.js.map +1 -1
- package/dist/WalkupScanToCompCaps.js.map +1 -1
- package/dist/WalkupScanToCompDestination.js.map +1 -1
- package/dist/WalkupScanToCompDestinations.js.map +1 -1
- package/dist/WalkupScanToCompEvent.js.map +1 -1
- package/dist/WalkupScanToCompManifest.js.map +1 -1
- package/dist/commitInfo.json +1 -1
- package/dist/delay.js +1 -2
- package/dist/delay.js.map +1 -1
- package/dist/healthcheck.js +1 -2
- package/dist/healthcheck.js.map +1 -1
- package/dist/index.js +22 -12
- package/dist/index.js.map +1 -1
- package/dist/listening.js +5 -6
- package/dist/listening.js.map +1 -1
- package/dist/nextcloud/NextcloudConfig.js.map +1 -1
- package/dist/nextcloud/nextcloud.js +4 -6
- package/dist/nextcloud/nextcloud.js.map +1 -1
- package/dist/paperless/PaperlessConfig.js.map +1 -1
- package/dist/paperless/paperless.js +4 -5
- package/dist/paperless/paperless.js.map +1 -1
- package/dist/pdfProcessing.js +4 -5
- package/dist/pdfProcessing.js.map +1 -1
- package/dist/postProcessing.js +2 -4
- package/dist/postProcessing.js.map +1 -1
- package/dist/readDeviceCapabilities.js +24 -20
- package/dist/readDeviceCapabilities.js.map +1 -1
- package/dist/scanProcessing.d.ts +2 -2
- package/dist/scanProcessing.js +28 -30
- package/dist/scanProcessing.js.map +1 -1
- package/package.json +19 -17
- package/dist/PaperlessCOnfig.d.ts +0 -7
- package/dist/PaperlessCOnfig.js +0 -3
- package/dist/PaperlessCOnfig.js.map +0 -1
- package/dist/PaperlessConfig.d.ts +0 -7
- package/dist/PaperlessConfig.js +0 -3
- package/dist/PaperlessConfig.js.map +0 -1
- package/dist/paperless.d.ts +0 -7
- package/dist/paperless.js +0 -83
- package/dist/paperless.js.map +0 -1
- package/dist/test/DiscoveryTree.test.d.ts +0 -1
- package/dist/test/DiscoveryTree.test.js +0 -68
- package/dist/test/DiscoveryTree.test.js.map +0 -1
- package/dist/test/EtagEventTable.test.d.ts +0 -1
- package/dist/test/EtagEventTable.test.js +0 -93
- package/dist/test/EtagEventTable.test.js.map +0 -1
- package/dist/test/Job.test.d.ts +0 -1
- package/dist/test/Job.test.js +0 -104
- package/dist/test/Job.test.js.map +0 -1
- package/dist/test/JpegUtil.test.d.ts +0 -1
- package/dist/test/JpegUtil.test.js +0 -53
- package/dist/test/JpegUtil.test.js.map +0 -1
- package/dist/test/PathHelper.test.d.ts +0 -1
- package/dist/test/PathHelper.test.js +0 -98
- package/dist/test/PathHelper.test.js.map +0 -1
- package/dist/test/ScanCaps.test.d.ts +0 -1
- package/dist/test/ScanCaps.test.js +0 -96
- package/dist/test/ScanCaps.test.js.map +0 -1
- package/dist/test/ScanJobManifest.test.d.ts +0 -1
- package/dist/test/ScanJobManifest.test.js +0 -56
- package/dist/test/ScanJobManifest.test.js.map +0 -1
- package/dist/test/ScanJobSettings.test.d.ts +0 -1
- package/dist/test/ScanJobSettings.test.js +0 -59
- package/dist/test/ScanJobSettings.test.js.map +0 -1
- package/dist/test/ScanStatus.test.d.ts +0 -1
- package/dist/test/ScanStatus.test.js +0 -75
- package/dist/test/ScanStatus.test.js.map +0 -1
- package/dist/test/WalkupScanDestination.test.d.ts +0 -1
- package/dist/test/WalkupScanDestination.test.js +0 -80
- package/dist/test/WalkupScanDestination.test.js.map +0 -1
- package/dist/test/WalkupScanDestinations.test.d.ts +0 -1
- package/dist/test/WalkupScanDestinations.test.js +0 -68
- package/dist/test/WalkupScanDestinations.test.js.map +0 -1
- package/dist/test/WalkupScanManifest.test.d.ts +0 -1
- package/dist/test/WalkupScanManifest.test.js +0 -46
- package/dist/test/WalkupScanManifest.test.js.map +0 -1
- package/dist/test/WalkupScanToCompCaps.test.d.ts +0 -1
- package/dist/test/WalkupScanToCompCaps.test.js +0 -56
- package/dist/test/WalkupScanToCompCaps.test.js.map +0 -1
- package/dist/test/WalkupScanToCompDestination.test.d.ts +0 -1
- package/dist/test/WalkupScanToCompDestination.test.js +0 -58
- package/dist/test/WalkupScanToCompDestination.test.js.map +0 -1
- package/dist/test/WalkupScanToCompDestinations.test.d.ts +0 -1
- package/dist/test/WalkupScanToCompDestinations.test.js +0 -58
- package/dist/test/WalkupScanToCompDestinations.test.js.map +0 -1
- package/dist/test/WalkupScanToCompEvent.test.d.ts +0 -1
- package/dist/test/WalkupScanToCompEvent.test.js +0 -46
- package/dist/test/WalkupScanToCompEvent.test.js.map +0 -1
- package/dist/test/WalkupScanToCompManifest.test.d.ts +0 -1
- package/dist/test/WalkupScanToCompManifest.test.js +0 -46
- package/dist/test/WalkupScanToCompManifest.test.js.map +0 -1
- package/dist/test/clean.d.ts +0 -1
- package/dist/test/clean.js +0 -21
- package/dist/test/clean.js.map +0 -1
- package/dist/test/nextcloud.test.d.ts +0 -1
- package/dist/test/nextcloud.test.js +0 -165
- package/dist/test/nextcloud.test.js.map +0 -1
- package/dist/test/scanProcessing.test.d.ts +0 -1
- package/dist/test/scanProcessing.test.js +0 -105
- package/dist/test/scanProcessing.test.js.map +0 -1
- package/dist/test-bonjour.d.ts +0 -1
- package/dist/test-bonjour.js +0 -20
- package/dist/test-bonjour.js.map +0 -1
- package/nodemon.json +0 -6
- package/src/Destination.ts +0 -63
- package/src/DeviceCapabilities.ts +0 -8
- package/src/DiscoveryTree.ts +0 -56
- package/src/Event.ts +0 -55
- package/src/EventTable.ts +0 -45
- package/src/HPApi.ts +0 -510
- package/src/InputSource.ts +0 -4
- package/src/Job.ts +0 -134
- package/src/JpegUtil.ts +0 -327
- package/src/KnownShortcut.ts +0 -6
- package/src/PathHelper.ts +0 -106
- package/src/ScanCaps.ts +0 -81
- package/src/ScanContent.ts +0 -15
- package/src/ScanJobManifest.ts +0 -56
- package/src/ScanJobSettings.ts +0 -84
- package/src/ScanStatus.ts +0 -48
- package/src/WalkupScanDestination.ts +0 -74
- package/src/WalkupScanDestinations.ts +0 -46
- package/src/WalkupScanManifest.ts +0 -59
- package/src/WalkupScanToCompCaps.ts +0 -36
- package/src/WalkupScanToCompDestination.ts +0 -79
- package/src/WalkupScanToCompDestinations.ts +0 -47
- package/src/WalkupScanToCompEvent.ts +0 -30
- package/src/WalkupScanToCompManifest.ts +0 -59
- package/src/commitInfo.json +0 -3
- package/src/delay.ts +0 -5
- package/src/healthcheck.ts +0 -17
- package/src/index.ts +0 -588
- package/src/listening.ts +0 -144
- package/src/nextcloud/NextcloudConfig.ts +0 -7
- package/src/nextcloud/nextcloud.ts +0 -146
- package/src/paperless/PaperlessConfig.ts +0 -7
- package/src/paperless/paperless.ts +0 -110
- package/src/pdfProcessing.ts +0 -67
- package/src/postProcessing.ts +0 -165
- package/src/readDeviceCapabilities.ts +0 -52
- package/src/scanProcessing.ts +0 -570
- package/tsconfig.json +0 -34
package/src/scanProcessing.ts
DELETED
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
import Event from "./Event";
|
|
2
|
-
import WalkupScanDestination from "./WalkupScanDestination";
|
|
3
|
-
import WalkupScanToCompDestination from "./WalkupScanToCompDestination";
|
|
4
|
-
import HPApi from "./HPApi";
|
|
5
|
-
import fs from "fs/promises";
|
|
6
|
-
import JpegUtil from "./JpegUtil";
|
|
7
|
-
import { DeviceCapabilities } from "./DeviceCapabilities";
|
|
8
|
-
import { waitForScanEvent, waitScanRequest } from "./listening";
|
|
9
|
-
import ScanJobSettings from "./ScanJobSettings";
|
|
10
|
-
import { ScanContent, ScanPage } from "./ScanContent";
|
|
11
|
-
import Job from "./Job";
|
|
12
|
-
import { delay } from "./delay";
|
|
13
|
-
import PathHelper from "./PathHelper";
|
|
14
|
-
import ScanStatus from "./ScanStatus";
|
|
15
|
-
import { InputSource } from "./InputSource";
|
|
16
|
-
import { PaperlessConfig } from "./paperless/PaperlessConfig";
|
|
17
|
-
import { NextcloudConfig } from "./nextcloud/NextcloudConfig";
|
|
18
|
-
import { postProcessing } from "./postProcessing";
|
|
19
|
-
|
|
20
|
-
async function waitDeviceUntilItIsReadyToUploadOrCompleted(
|
|
21
|
-
jobUrl: string,
|
|
22
|
-
): Promise<Job> {
|
|
23
|
-
let job = null;
|
|
24
|
-
let isReadyToUpload = false;
|
|
25
|
-
do {
|
|
26
|
-
job = await HPApi.getJob(jobUrl);
|
|
27
|
-
if (job.jobState === "Canceled") {
|
|
28
|
-
return job;
|
|
29
|
-
} else if (
|
|
30
|
-
job.pageState === "ReadyToUpload" ||
|
|
31
|
-
job.jobState === "Completed"
|
|
32
|
-
) {
|
|
33
|
-
isReadyToUpload = true;
|
|
34
|
-
} else if (job.jobState == "Processing") {
|
|
35
|
-
isReadyToUpload = false;
|
|
36
|
-
} else {
|
|
37
|
-
console.log(`Unknown jobState: ${job.jobState}`);
|
|
38
|
-
}
|
|
39
|
-
await delay(300);
|
|
40
|
-
} while (!isReadyToUpload);
|
|
41
|
-
return job;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function tryGetDestination(
|
|
45
|
-
event: Event,
|
|
46
|
-
): Promise<WalkupScanDestination | WalkupScanToCompDestination | null> {
|
|
47
|
-
//this code can in some cases be executed before the user actually chooses between Document or Photo
|
|
48
|
-
//so lets fetch the contentType (Document or Photo) until we get a value
|
|
49
|
-
let destination: WalkupScanDestination | WalkupScanToCompDestination | null =
|
|
50
|
-
null;
|
|
51
|
-
|
|
52
|
-
for (let i = 0; i < 20; i++) {
|
|
53
|
-
const destinationURI = event.destinationURI;
|
|
54
|
-
if (destinationURI) {
|
|
55
|
-
destination = await HPApi.getDestination(destinationURI);
|
|
56
|
-
|
|
57
|
-
const shortcut = destination.shortcut;
|
|
58
|
-
if (shortcut != null) {
|
|
59
|
-
return destination;
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
console.log(`No destination URI found`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
console.log(`No shortcut yet available, attempt: ${i + 1}/20`);
|
|
66
|
-
await new Promise((resolve) => setTimeout(resolve, 1000)); //wait 1s
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
console.log("Failing to detect destination shortcut");
|
|
70
|
-
console.log(JSON.stringify(destination));
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function scanProcessing(filePath: string): Promise<number | null> {
|
|
75
|
-
const buffer: Buffer = await fs.readFile(filePath);
|
|
76
|
-
|
|
77
|
-
const height = JpegUtil.fixSizeWithDNL(buffer);
|
|
78
|
-
if (height != null) {
|
|
79
|
-
// rewrite the fixed file
|
|
80
|
-
await fs.writeFile(filePath, buffer);
|
|
81
|
-
return height;
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function createScanPage(
|
|
87
|
-
job: Job,
|
|
88
|
-
currentPageNumber: number,
|
|
89
|
-
filePath: string,
|
|
90
|
-
sizeFixed: number | null,
|
|
91
|
-
): ScanPage {
|
|
92
|
-
const height = sizeFixed ?? job.imageHeight;
|
|
93
|
-
return {
|
|
94
|
-
path: filePath,
|
|
95
|
-
pageNumber: currentPageNumber,
|
|
96
|
-
width: job.imageWidth ?? 0,
|
|
97
|
-
height: height ?? 0,
|
|
98
|
-
xResolution: job.xResolution ?? 200,
|
|
99
|
-
yResolution: job.yResolution ?? 200,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async function handleScanProcessingState(
|
|
104
|
-
job: Job,
|
|
105
|
-
inputSource: InputSource,
|
|
106
|
-
folder: string,
|
|
107
|
-
scanCount: number,
|
|
108
|
-
currentPageNumber: number,
|
|
109
|
-
filePattern: string | undefined,
|
|
110
|
-
date: Date,
|
|
111
|
-
): Promise<ScanPage | null> {
|
|
112
|
-
if (
|
|
113
|
-
job.pageState == "ReadyToUpload" &&
|
|
114
|
-
job.binaryURL != null &&
|
|
115
|
-
job.currentPageNumber != null
|
|
116
|
-
) {
|
|
117
|
-
console.log(
|
|
118
|
-
`Ready to download page job page ${job.currentPageNumber} at:`,
|
|
119
|
-
job.binaryURL,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
const destinationFilePath = PathHelper.getFileForPage(
|
|
123
|
-
folder,
|
|
124
|
-
scanCount,
|
|
125
|
-
currentPageNumber,
|
|
126
|
-
filePattern,
|
|
127
|
-
"jpg",
|
|
128
|
-
date,
|
|
129
|
-
);
|
|
130
|
-
const filePath = await HPApi.downloadPage(
|
|
131
|
-
job.binaryURL,
|
|
132
|
-
destinationFilePath,
|
|
133
|
-
);
|
|
134
|
-
console.log("Page downloaded to:", filePath);
|
|
135
|
-
|
|
136
|
-
let sizeFixed: null | number = null;
|
|
137
|
-
if (inputSource == InputSource.Adf) {
|
|
138
|
-
sizeFixed = await scanProcessing(filePath);
|
|
139
|
-
if (sizeFixed == null) {
|
|
140
|
-
console.log(
|
|
141
|
-
`File size has not been fixed, DNF may not have been found and approximate height is: ${job.imageHeight}`,
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return createScanPage(job, currentPageNumber, filePath, sizeFixed);
|
|
146
|
-
} else {
|
|
147
|
-
console.log(`Unknown pageState: ${job.pageState}`);
|
|
148
|
-
await delay(200);
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async function executeScanJob(
|
|
154
|
-
scanJobSettings: ScanJobSettings,
|
|
155
|
-
inputSource: InputSource,
|
|
156
|
-
folder: string,
|
|
157
|
-
scanCount: number,
|
|
158
|
-
scanJobContent: ScanContent,
|
|
159
|
-
filePattern: string | undefined,
|
|
160
|
-
): Promise<"Completed" | "Canceled"> {
|
|
161
|
-
const jobUrl = await HPApi.postJob(scanJobSettings);
|
|
162
|
-
|
|
163
|
-
console.log("New job created:", jobUrl);
|
|
164
|
-
|
|
165
|
-
let job = await HPApi.getJob(jobUrl);
|
|
166
|
-
while (job.jobState !== "Completed") {
|
|
167
|
-
job = await waitDeviceUntilItIsReadyToUploadOrCompleted(jobUrl);
|
|
168
|
-
|
|
169
|
-
if (job.jobState == "Completed") {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (job.jobState === "Processing") {
|
|
174
|
-
const page = await handleScanProcessingState(
|
|
175
|
-
job,
|
|
176
|
-
inputSource,
|
|
177
|
-
folder,
|
|
178
|
-
scanCount,
|
|
179
|
-
scanJobContent.elements.length + 1,
|
|
180
|
-
filePattern,
|
|
181
|
-
new Date(),
|
|
182
|
-
);
|
|
183
|
-
job = await HPApi.getJob(jobUrl);
|
|
184
|
-
if (page != null && job.jobState != "Canceled") {
|
|
185
|
-
scanJobContent.elements.push(page);
|
|
186
|
-
}
|
|
187
|
-
} else if (job.jobState === "Canceled") {
|
|
188
|
-
console.log("Job cancelled by device");
|
|
189
|
-
break;
|
|
190
|
-
} else {
|
|
191
|
-
console.log(`Unhandled jobState: ${job.jobState}`);
|
|
192
|
-
await delay(200);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
console.log(
|
|
196
|
-
`Job state: ${job.jobState}, totalPages: ${scanJobContent.elements.length}:`,
|
|
197
|
-
);
|
|
198
|
-
return job.jobState;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function waitScanNewPageRequest(compEventURI: string): Promise<boolean> {
|
|
202
|
-
let startNewScanJob = false;
|
|
203
|
-
let wait = true;
|
|
204
|
-
while (wait) {
|
|
205
|
-
await new Promise((resolve) => setTimeout(resolve, 1000)); //wait 1s
|
|
206
|
-
|
|
207
|
-
const walkupScanToCompEvent =
|
|
208
|
-
await HPApi.getWalkupScanToCompEvent(compEventURI);
|
|
209
|
-
const message = walkupScanToCompEvent.eventType;
|
|
210
|
-
|
|
211
|
-
if (message === "ScanNewPageRequested") {
|
|
212
|
-
startNewScanJob = true;
|
|
213
|
-
wait = false;
|
|
214
|
-
} else if (message === "ScanPagesComplete") {
|
|
215
|
-
wait = false;
|
|
216
|
-
} else if (message === "ScanRequested") {
|
|
217
|
-
// continue waiting
|
|
218
|
-
} else {
|
|
219
|
-
wait = false;
|
|
220
|
-
console.log(`Unknown eventType: ${message}`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return startNewScanJob;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async function executeScanJobs(
|
|
227
|
-
scanJobSettings: ScanJobSettings,
|
|
228
|
-
inputSource: InputSource,
|
|
229
|
-
folder: string,
|
|
230
|
-
scanCount: number,
|
|
231
|
-
scanJobContent: ScanContent,
|
|
232
|
-
firstEvent: Event,
|
|
233
|
-
deviceCapabilities: DeviceCapabilities,
|
|
234
|
-
filePattern: string | undefined,
|
|
235
|
-
) {
|
|
236
|
-
let jobState = await executeScanJob(
|
|
237
|
-
scanJobSettings,
|
|
238
|
-
inputSource,
|
|
239
|
-
folder,
|
|
240
|
-
scanCount,
|
|
241
|
-
scanJobContent,
|
|
242
|
-
filePattern,
|
|
243
|
-
);
|
|
244
|
-
let lastEvent = firstEvent;
|
|
245
|
-
if (
|
|
246
|
-
jobState === "Completed" &&
|
|
247
|
-
lastEvent.compEventURI &&
|
|
248
|
-
inputSource !== InputSource.Adf &&
|
|
249
|
-
lastEvent.destinationURI &&
|
|
250
|
-
deviceCapabilities.supportsMultiItemScanFromPlaten
|
|
251
|
-
) {
|
|
252
|
-
lastEvent = await waitForScanEvent(
|
|
253
|
-
lastEvent.destinationURI,
|
|
254
|
-
lastEvent.agingStamp,
|
|
255
|
-
);
|
|
256
|
-
if (!lastEvent.compEventURI) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
let startNewScanJob = await waitScanNewPageRequest(lastEvent.compEventURI);
|
|
260
|
-
while (startNewScanJob) {
|
|
261
|
-
jobState = await executeScanJob(
|
|
262
|
-
scanJobSettings,
|
|
263
|
-
inputSource,
|
|
264
|
-
folder,
|
|
265
|
-
scanCount,
|
|
266
|
-
scanJobContent,
|
|
267
|
-
filePattern,
|
|
268
|
-
);
|
|
269
|
-
if (jobState !== "Completed") {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (!lastEvent.destinationURI) {
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
lastEvent = await waitForScanEvent(
|
|
276
|
-
lastEvent.destinationURI,
|
|
277
|
-
lastEvent.agingStamp,
|
|
278
|
-
);
|
|
279
|
-
if (!lastEvent.compEventURI) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
startNewScanJob = await waitScanNewPageRequest(lastEvent.compEventURI);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function isPdf(
|
|
288
|
-
destination: WalkupScanDestination | WalkupScanToCompDestination,
|
|
289
|
-
) {
|
|
290
|
-
if (
|
|
291
|
-
destination.shortcut === "SavePDF" ||
|
|
292
|
-
destination.shortcut === "EmailPDF" ||
|
|
293
|
-
destination.shortcut == "SaveDocument1"
|
|
294
|
-
) {
|
|
295
|
-
return true;
|
|
296
|
-
} else if (
|
|
297
|
-
destination.shortcut === "SaveJPEG" ||
|
|
298
|
-
destination.shortcut === "SavePhoto1"
|
|
299
|
-
) {
|
|
300
|
-
return false;
|
|
301
|
-
} else {
|
|
302
|
-
console.log(
|
|
303
|
-
`Unexpected shortcut received: ${destination.shortcut}, considering it as non pdf target!`,
|
|
304
|
-
);
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
export function getScanWidth(
|
|
310
|
-
scanConfig: ScanConfig,
|
|
311
|
-
inputSource: InputSource,
|
|
312
|
-
deviceCapabilities: DeviceCapabilities,
|
|
313
|
-
): number | null {
|
|
314
|
-
if (scanConfig.width && scanConfig.width > 0) {
|
|
315
|
-
const maxWidth =
|
|
316
|
-
inputSource === InputSource.Adf
|
|
317
|
-
? deviceCapabilities.adfMaxWidth
|
|
318
|
-
: deviceCapabilities.platenMaxWidth;
|
|
319
|
-
|
|
320
|
-
if (maxWidth && scanConfig.width > maxWidth) {
|
|
321
|
-
return maxWidth;
|
|
322
|
-
} else {
|
|
323
|
-
return scanConfig.width;
|
|
324
|
-
}
|
|
325
|
-
} else {
|
|
326
|
-
return inputSource === InputSource.Adf
|
|
327
|
-
? deviceCapabilities.adfMaxWidth
|
|
328
|
-
: deviceCapabilities.platenMaxWidth;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export function getScanHeight(
|
|
333
|
-
scanConfig: ScanConfig,
|
|
334
|
-
inputSource: InputSource,
|
|
335
|
-
deviceCapabilities: DeviceCapabilities,
|
|
336
|
-
): number | null {
|
|
337
|
-
if (scanConfig.height && scanConfig.height > 0) {
|
|
338
|
-
const maxHeight =
|
|
339
|
-
inputSource === InputSource.Adf
|
|
340
|
-
? deviceCapabilities.adfMaxHeight
|
|
341
|
-
: deviceCapabilities.platenMaxHeight;
|
|
342
|
-
|
|
343
|
-
if (maxHeight && scanConfig.height > maxHeight) {
|
|
344
|
-
return maxHeight;
|
|
345
|
-
} else {
|
|
346
|
-
return scanConfig.height;
|
|
347
|
-
}
|
|
348
|
-
} else {
|
|
349
|
-
return inputSource === InputSource.Adf
|
|
350
|
-
? deviceCapabilities.adfMaxHeight
|
|
351
|
-
: deviceCapabilities.platenMaxHeight;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
export async function saveScanFromEvent(
|
|
356
|
-
event: Event,
|
|
357
|
-
folder: string,
|
|
358
|
-
tempFolder: string,
|
|
359
|
-
scanCount: number,
|
|
360
|
-
deviceCapabilities: DeviceCapabilities,
|
|
361
|
-
scanConfig: ScanConfig,
|
|
362
|
-
): Promise<void> {
|
|
363
|
-
if (event.compEventURI) {
|
|
364
|
-
const proceedToScan = await waitScanRequest(event.compEventURI);
|
|
365
|
-
if (!proceedToScan) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
const destination = await tryGetDestination(event);
|
|
371
|
-
if (!destination) {
|
|
372
|
-
console.log("No shortcut selected!");
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
console.log("Selected shortcut: " + destination.shortcut);
|
|
376
|
-
|
|
377
|
-
let toPdf: boolean;
|
|
378
|
-
let destinationFolder: string;
|
|
379
|
-
let contentType: "Document" | "Photo";
|
|
380
|
-
if (isPdf(destination)) {
|
|
381
|
-
toPdf = true;
|
|
382
|
-
contentType = "Document";
|
|
383
|
-
destinationFolder = tempFolder;
|
|
384
|
-
console.log(
|
|
385
|
-
`Scan will be converted to pdf, using ${destinationFolder} as temp scan output directory for individual pages`,
|
|
386
|
-
);
|
|
387
|
-
} else {
|
|
388
|
-
toPdf = false;
|
|
389
|
-
contentType = "Photo";
|
|
390
|
-
destinationFolder = folder;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const isDuplex =
|
|
394
|
-
destination.scanPlexMode != null && destination.scanPlexMode != "Simplex";
|
|
395
|
-
console.log("ScanPlexMode is : " + destination.scanPlexMode);
|
|
396
|
-
|
|
397
|
-
const scanStatus = await HPApi.getScanStatus();
|
|
398
|
-
|
|
399
|
-
if (scanStatus.scannerState !== "Idle") {
|
|
400
|
-
console.log("Scanner state is not Idle, aborting scan attempt...!");
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
console.log("Afd is : " + scanStatus.adfState);
|
|
404
|
-
|
|
405
|
-
const inputSource = scanStatus.getInputSource();
|
|
406
|
-
const scanWidth = getScanWidth(scanConfig, inputSource, deviceCapabilities);
|
|
407
|
-
const scanHeight = getScanHeight(scanConfig, inputSource, deviceCapabilities);
|
|
408
|
-
|
|
409
|
-
const scanJobSettings = new ScanJobSettings(
|
|
410
|
-
inputSource,
|
|
411
|
-
contentType,
|
|
412
|
-
scanConfig.resolution,
|
|
413
|
-
scanWidth,
|
|
414
|
-
scanHeight,
|
|
415
|
-
isDuplex,
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
const scanJobContent: ScanContent = { elements: [] };
|
|
419
|
-
|
|
420
|
-
const scanDate = new Date();
|
|
421
|
-
|
|
422
|
-
await executeScanJobs(
|
|
423
|
-
scanJobSettings,
|
|
424
|
-
inputSource,
|
|
425
|
-
destinationFolder,
|
|
426
|
-
scanCount,
|
|
427
|
-
scanJobContent,
|
|
428
|
-
event,
|
|
429
|
-
deviceCapabilities,
|
|
430
|
-
scanConfig.directoryConfig.filePattern,
|
|
431
|
-
);
|
|
432
|
-
|
|
433
|
-
console.log(
|
|
434
|
-
`Scan of page(s) completed totalPages: ${scanJobContent.elements.length}:`,
|
|
435
|
-
);
|
|
436
|
-
await postProcessing(
|
|
437
|
-
scanConfig,
|
|
438
|
-
folder,
|
|
439
|
-
tempFolder,
|
|
440
|
-
scanCount,
|
|
441
|
-
scanJobContent,
|
|
442
|
-
scanDate,
|
|
443
|
-
toPdf,
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
export type DirectoryConfig = {
|
|
448
|
-
directory: string | undefined;
|
|
449
|
-
tempDirectory: string | undefined;
|
|
450
|
-
filePattern: string | undefined;
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
export type ScanConfig = {
|
|
454
|
-
resolution: number;
|
|
455
|
-
width: number | null;
|
|
456
|
-
height: number | null;
|
|
457
|
-
directoryConfig: DirectoryConfig;
|
|
458
|
-
paperlessConfig: PaperlessConfig | undefined;
|
|
459
|
-
nextcloudConfig: NextcloudConfig | undefined;
|
|
460
|
-
};
|
|
461
|
-
export type AdfAutoScanConfig = ScanConfig & {
|
|
462
|
-
isDuplex: boolean;
|
|
463
|
-
generatePdf: boolean;
|
|
464
|
-
pollingInterval: number;
|
|
465
|
-
startScanDelay: number;
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
export type SingleScanConfig = ScanConfig & {
|
|
469
|
-
isDuplex: boolean;
|
|
470
|
-
generatePdf: boolean;
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
export async function scanFromAdf(
|
|
474
|
-
scanCount: number,
|
|
475
|
-
folder: string,
|
|
476
|
-
tempFolder: string,
|
|
477
|
-
adfAutoScanConfig: AdfAutoScanConfig,
|
|
478
|
-
deviceCapabilities: DeviceCapabilities,
|
|
479
|
-
date: Date,
|
|
480
|
-
) {
|
|
481
|
-
let destinationFolder: string;
|
|
482
|
-
let contentType: "Document" | "Photo";
|
|
483
|
-
if (adfAutoScanConfig.generatePdf) {
|
|
484
|
-
contentType = "Document";
|
|
485
|
-
destinationFolder = tempFolder;
|
|
486
|
-
console.log(
|
|
487
|
-
`Scan will be converted to pdf, using ${destinationFolder} as temp scan output directory for individual pages`,
|
|
488
|
-
);
|
|
489
|
-
} else {
|
|
490
|
-
contentType = "Photo";
|
|
491
|
-
destinationFolder = folder;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
const scanWidth = getScanWidth(
|
|
495
|
-
adfAutoScanConfig,
|
|
496
|
-
InputSource.Adf,
|
|
497
|
-
deviceCapabilities,
|
|
498
|
-
);
|
|
499
|
-
const scanHeight = getScanHeight(
|
|
500
|
-
adfAutoScanConfig,
|
|
501
|
-
InputSource.Adf,
|
|
502
|
-
deviceCapabilities,
|
|
503
|
-
);
|
|
504
|
-
|
|
505
|
-
const scanJobSettings = new ScanJobSettings(
|
|
506
|
-
InputSource.Adf,
|
|
507
|
-
contentType,
|
|
508
|
-
adfAutoScanConfig.resolution,
|
|
509
|
-
scanWidth,
|
|
510
|
-
scanHeight,
|
|
511
|
-
adfAutoScanConfig.isDuplex,
|
|
512
|
-
);
|
|
513
|
-
|
|
514
|
-
const scanJobContent: ScanContent = { elements: [] };
|
|
515
|
-
|
|
516
|
-
await executeScanJob(
|
|
517
|
-
scanJobSettings,
|
|
518
|
-
InputSource.Adf,
|
|
519
|
-
destinationFolder,
|
|
520
|
-
scanCount,
|
|
521
|
-
scanJobContent,
|
|
522
|
-
adfAutoScanConfig.directoryConfig.filePattern,
|
|
523
|
-
);
|
|
524
|
-
|
|
525
|
-
console.log(
|
|
526
|
-
`Scan of page(s) completed, total pages: ${scanJobContent.elements.length}:`,
|
|
527
|
-
);
|
|
528
|
-
|
|
529
|
-
await postProcessing(
|
|
530
|
-
adfAutoScanConfig,
|
|
531
|
-
folder,
|
|
532
|
-
tempFolder,
|
|
533
|
-
scanCount,
|
|
534
|
-
scanJobContent,
|
|
535
|
-
date,
|
|
536
|
-
adfAutoScanConfig.generatePdf,
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
export async function waitAdfLoaded(
|
|
541
|
-
pollingInterval: number,
|
|
542
|
-
startScanDelay: number,
|
|
543
|
-
) {
|
|
544
|
-
let ready = false;
|
|
545
|
-
while (!ready) {
|
|
546
|
-
let scanStatus: ScanStatus = await HPApi.getScanStatus();
|
|
547
|
-
while (!scanStatus.isLoaded()) {
|
|
548
|
-
await delay(pollingInterval);
|
|
549
|
-
scanStatus = await HPApi.getScanStatus();
|
|
550
|
-
}
|
|
551
|
-
console.log(`ADF load detected`);
|
|
552
|
-
|
|
553
|
-
let loaded = true;
|
|
554
|
-
let counter = 0;
|
|
555
|
-
const shortPollingInterval = 500;
|
|
556
|
-
while (loaded && counter < startScanDelay) {
|
|
557
|
-
await delay(shortPollingInterval);
|
|
558
|
-
scanStatus = await HPApi.getScanStatus();
|
|
559
|
-
loaded = scanStatus.isLoaded();
|
|
560
|
-
counter += shortPollingInterval;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (loaded && counter >= startScanDelay) {
|
|
564
|
-
ready = true;
|
|
565
|
-
console.log(`ADF still loaded, proceeding`);
|
|
566
|
-
} else {
|
|
567
|
-
console.log(`ADF not loaded anymore, waiting...`);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "dist",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"target": "es2019",
|
|
6
|
-
"noImplicitAny": true,
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"inlineSources": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"allowSyntheticDefaultImports": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"strictNullChecks": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
"moduleResolution": "node",
|
|
16
|
-
"resolveJsonModule": true,
|
|
17
|
-
"declaration": true,
|
|
18
|
-
"jsx": "preserve",
|
|
19
|
-
"baseUrl": ".",
|
|
20
|
-
"paths": {
|
|
21
|
-
"*": [
|
|
22
|
-
"node_modules/*",
|
|
23
|
-
"src/types/*"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"exclude": [
|
|
28
|
-
"node_modules",
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
|
-
"include": [
|
|
32
|
-
"src"
|
|
33
|
-
]
|
|
34
|
-
}
|