node-hp-scan-to 1.3.0 → 1.4.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 +76 -15
- package/dist/Destination.js.map +1 -1
- package/dist/DeviceCapabilities.d.ts +4 -0
- package/dist/DeviceCapabilities.js.map +1 -1
- package/dist/DiscoveryTree.js.map +1 -1
- package/dist/Event.js +2 -2
- package/dist/Event.js.map +1 -1
- package/dist/EventTable.js.map +1 -1
- package/dist/HPApi.js.map +1 -1
- package/dist/InputSource.d.ts +4 -0
- package/dist/InputSource.js +9 -0
- package/dist/InputSource.js.map +1 -0
- package/dist/Job.d.ts +2 -0
- package/dist/Job.js +2 -2
- package/dist/Job.js.map +1 -1
- package/dist/JpegUtil.js +1 -1
- package/dist/JpegUtil.js.map +1 -1
- package/dist/PathHelper.d.ts +4 -3
- package/dist/PathHelper.js +28 -13
- package/dist/PathHelper.js.map +1 -1
- package/dist/ScanCaps.d.ts +18 -0
- package/dist/ScanCaps.js +14 -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.d.ts +4 -1
- package/dist/ScanJobSettings.js +19 -8
- package/dist/ScanJobSettings.js.map +1 -1
- package/dist/ScanStatus.d.ts +2 -1
- package/dist/ScanStatus.js +3 -2
- package/dist/ScanStatus.js.map +1 -1
- package/dist/WalkupScanDestination.js +2 -2
- package/dist/WalkupScanDestination.js.map +1 -1
- package/dist/WalkupScanDestinations.js +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 +2 -2
- package/dist/WalkupScanToCompDestination.js.map +1 -1
- package/dist/WalkupScanToCompDestinations.js +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/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/dist/listening.js.map +1 -1
- package/dist/readDeviceCapabilities.js +6 -1
- package/dist/readDeviceCapabilities.js.map +1 -1
- package/dist/scanProcessing.d.ts +5 -1
- package/dist/scanProcessing.js +61 -21
- package/dist/scanProcessing.js.map +1 -1
- package/package.json +7 -7
- package/src/Destination.ts +1 -1
- package/src/DeviceCapabilities.ts +4 -0
- package/src/DiscoveryTree.ts +1 -1
- package/src/Event.ts +4 -4
- package/src/EventTable.ts +1 -1
- package/src/HPApi.ts +19 -19
- package/src/InputSource.ts +4 -0
- package/src/Job.ts +19 -7
- package/src/JpegUtil.ts +18 -14
- package/src/PathHelper.ts +48 -20
- package/src/ScanCaps.ts +43 -1
- package/src/ScanContent.ts +1 -1
- package/src/ScanJobManifest.ts +3 -2
- package/src/ScanJobSettings.ts +23 -9
- package/src/ScanStatus.ts +6 -3
- package/src/WalkupScanDestination.ts +9 -5
- package/src/WalkupScanDestinations.ts +9 -4
- package/src/WalkupScanManifest.ts +3 -3
- package/src/WalkupScanToCompCaps.ts +2 -2
- package/src/WalkupScanToCompDestination.ts +15 -5
- package/src/WalkupScanToCompDestinations.ts +5 -4
- package/src/WalkupScanToCompEvent.ts +1 -1
- package/src/WalkupScanToCompManifest.ts +3 -3
- package/src/index.ts +92 -35
- package/src/listening.ts +14 -15
- package/src/readDeviceCapabilities.ts +12 -6
- package/src/scanProcessing.ts +129 -52
- package/dist/fixJpegSize.d.ts +0 -19
- package/dist/fixJpegSize.js +0 -292
- package/dist/fixJpegSize.js.map +0 -1
- package/dist/scanProcess.d.ts +0 -19
- package/dist/scanProcess.js +0 -292
- package/dist/scanProcess.js.map +0 -1
- package/dist/src/Destination.d.ts +0 -8
- package/dist/src/Destination.js +0 -68
- package/dist/src/Destination.js.map +0 -1
- package/dist/src/DiscoveryTree.d.ts +0 -16
- package/dist/src/DiscoveryTree.js +0 -38
- package/dist/src/DiscoveryTree.js.map +0 -1
- package/dist/src/Event.d.ts +0 -21
- package/dist/src/Event.js +0 -32
- package/dist/src/Event.js.map +0 -1
- package/dist/src/EventTable.d.ts +0 -16
- package/dist/src/EventTable.js +0 -33
- package/dist/src/EventTable.js.map +0 -1
- package/dist/src/HPApi.d.ts +0 -50
- package/dist/src/HPApi.js +0 -454
- package/dist/src/HPApi.js.map +0 -1
- package/dist/src/Job.d.ts +0 -37
- package/dist/src/Job.js +0 -78
- package/dist/src/Job.js.map +0 -1
- package/dist/src/JpegUtil.d.ts +0 -26
- package/dist/src/JpegUtil.js +0 -229
- package/dist/src/JpegUtil.js.map +0 -1
- package/dist/src/KnownShortcut.d.ts +0 -1
- package/dist/src/KnownShortcut.js +0 -3
- package/dist/src/KnownShortcut.js.map +0 -1
- package/dist/src/PathHelper.d.ts +0 -6
- package/dist/src/PathHelper.js +0 -52
- package/dist/src/PathHelper.js.map +0 -1
- package/dist/src/ScanCaps.d.ts +0 -7
- package/dist/src/ScanCaps.js +0 -17
- package/dist/src/ScanCaps.js.map +0 -1
- package/dist/src/ScanJobManifest.d.ts +0 -23
- package/dist/src/ScanJobManifest.js +0 -24
- package/dist/src/ScanJobManifest.js.map +0 -1
- package/dist/src/ScanJobSettings.d.ts +0 -8
- package/dist/src/ScanJobSettings.js +0 -56
- package/dist/src/ScanJobSettings.js.map +0 -1
- package/dist/src/ScanStatus.d.ts +0 -19
- package/dist/src/ScanStatus.js +0 -35
- package/dist/src/ScanStatus.js.map +0 -1
- package/dist/src/WalkupScanDestination.d.ts +0 -22
- package/dist/src/WalkupScanDestination.js +0 -38
- package/dist/src/WalkupScanDestination.js.map +0 -1
- package/dist/src/WalkupScanDestinations.d.ts +0 -12
- package/dist/src/WalkupScanDestinations.js +0 -30
- package/dist/src/WalkupScanDestinations.js.map +0 -1
- package/dist/src/WalkupScanManifest.d.ts +0 -23
- package/dist/src/WalkupScanManifest.js +0 -25
- package/dist/src/WalkupScanManifest.js.map +0 -1
- package/dist/src/WalkupScanToCompCaps.d.ts +0 -12
- package/dist/src/WalkupScanToCompCaps.js +0 -20
- package/dist/src/WalkupScanToCompCaps.js.map +0 -1
- package/dist/src/WalkupScanToCompDestination.d.ts +0 -22
- package/dist/src/WalkupScanToCompDestination.js +0 -38
- package/dist/src/WalkupScanToCompDestination.js.map +0 -1
- package/dist/src/WalkupScanToCompDestinations.d.ts +0 -12
- package/dist/src/WalkupScanToCompDestinations.js +0 -30
- package/dist/src/WalkupScanToCompDestinations.js.map +0 -1
- package/dist/src/WalkupScanToCompEvent.d.ts +0 -11
- package/dist/src/WalkupScanToCompEvent.js +0 -20
- package/dist/src/WalkupScanToCompEvent.js.map +0 -1
- package/dist/src/WalkupScanToCompManifest.d.ts +0 -23
- package/dist/src/WalkupScanToCompManifest.js +0 -25
- package/dist/src/WalkupScanToCompManifest.js.map +0 -1
- package/dist/src/delay.d.ts +0 -1
- package/dist/src/delay.js +0 -10
- package/dist/src/delay.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 -51
- 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 -99
- package/dist/test/PathHelper.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 -53
- 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/src/listening.ts
CHANGED
|
@@ -6,9 +6,8 @@ import { DeviceCapabilities } from "./DeviceCapabilities";
|
|
|
6
6
|
export async function waitScanRequest(compEventURI: string): Promise<boolean> {
|
|
7
7
|
const waitMax = 50;
|
|
8
8
|
for (let i = 0; i < waitMax; i++) {
|
|
9
|
-
let walkupScanToCompEvent =
|
|
10
|
-
compEventURI
|
|
11
|
-
);
|
|
9
|
+
let walkupScanToCompEvent =
|
|
10
|
+
await HPApi.getWalkupScanToCompEvent(compEventURI);
|
|
12
11
|
let message = walkupScanToCompEvent.eventType;
|
|
13
12
|
if (message === "HostSelected") {
|
|
14
13
|
// this ok to wait
|
|
@@ -32,7 +31,7 @@ export async function waitScanRequest(compEventURI: string): Promise<boolean> {
|
|
|
32
31
|
|
|
33
32
|
export async function waitForScanEvent(
|
|
34
33
|
resourceURI: string,
|
|
35
|
-
afterEtag: string | null = null
|
|
34
|
+
afterEtag: string | null = null,
|
|
36
35
|
): Promise<Event> {
|
|
37
36
|
console.log("Start listening for new ScanEvent");
|
|
38
37
|
|
|
@@ -47,21 +46,21 @@ export async function waitForScanEvent(
|
|
|
47
46
|
(ev) =>
|
|
48
47
|
ev.isScanEvent &&
|
|
49
48
|
ev.destinationURI &&
|
|
50
|
-
ev.destinationURI.indexOf(resourceURI) >= 0
|
|
49
|
+
ev.destinationURI.indexOf(resourceURI) >= 0,
|
|
51
50
|
);
|
|
52
51
|
}
|
|
53
52
|
return acceptedScanEvent;
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
async function registerWalkupScanToCompDestination(
|
|
57
|
-
registrationConfig: RegistrationConfig
|
|
56
|
+
registrationConfig: RegistrationConfig,
|
|
58
57
|
): Promise<string> {
|
|
59
58
|
const walkupScanDestinations = await HPApi.getWalkupScanToCompDestinations();
|
|
60
59
|
const destinations = walkupScanDestinations.destinations;
|
|
61
60
|
|
|
62
61
|
console.log(
|
|
63
62
|
"Host destinations fetched:",
|
|
64
|
-
destinations.map((d) => d.name).join(", ")
|
|
63
|
+
destinations.map((d) => d.name).join(", "),
|
|
65
64
|
);
|
|
66
65
|
|
|
67
66
|
const hostname = registrationConfig.label;
|
|
@@ -70,12 +69,12 @@ async function registerWalkupScanToCompDestination(
|
|
|
70
69
|
let resourceURI;
|
|
71
70
|
if (destination) {
|
|
72
71
|
console.log(
|
|
73
|
-
`Re-using existing destination: ${hostname} - ${destination.resourceURI}
|
|
72
|
+
`Re-using existing destination: ${hostname} - ${destination.resourceURI}`,
|
|
74
73
|
);
|
|
75
74
|
resourceURI = destination.resourceURI;
|
|
76
75
|
} else {
|
|
77
76
|
resourceURI = await HPApi.registerWalkupScanToCompDestination(
|
|
78
|
-
new Destination(hostname, hostname, true)
|
|
77
|
+
new Destination(hostname, hostname, true),
|
|
79
78
|
);
|
|
80
79
|
console.log(`New Destination registered: ${hostname} - ${resourceURI}`);
|
|
81
80
|
}
|
|
@@ -86,14 +85,14 @@ async function registerWalkupScanToCompDestination(
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
async function registerWalkupScanDestination(
|
|
89
|
-
registrationConfig: RegistrationConfig
|
|
88
|
+
registrationConfig: RegistrationConfig,
|
|
90
89
|
): Promise<string> {
|
|
91
90
|
const walkupScanDestinations = await HPApi.getWalkupScanDestinations();
|
|
92
91
|
const destinations = walkupScanDestinations.destinations;
|
|
93
92
|
|
|
94
93
|
console.log(
|
|
95
94
|
"Host destinations fetched:",
|
|
96
|
-
destinations.map((d) => d.name).join(", ")
|
|
95
|
+
destinations.map((d) => d.name).join(", "),
|
|
97
96
|
);
|
|
98
97
|
|
|
99
98
|
const hostname = registrationConfig.label;
|
|
@@ -102,12 +101,12 @@ async function registerWalkupScanDestination(
|
|
|
102
101
|
let resourceURI;
|
|
103
102
|
if (destination) {
|
|
104
103
|
console.log(
|
|
105
|
-
`Re-using existing destination: ${hostname} - ${destination.resourceURI}
|
|
104
|
+
`Re-using existing destination: ${hostname} - ${destination.resourceURI}`,
|
|
106
105
|
);
|
|
107
106
|
resourceURI = destination.resourceURI;
|
|
108
107
|
} else {
|
|
109
108
|
resourceURI = await HPApi.registerWalkupScanDestination(
|
|
110
|
-
new Destination(hostname, hostname, false)
|
|
109
|
+
new Destination(hostname, hostname, false),
|
|
111
110
|
);
|
|
112
111
|
console.log(`New Destination registered: ${hostname} - ${resourceURI}`);
|
|
113
112
|
}
|
|
@@ -123,7 +122,7 @@ export type RegistrationConfig = {
|
|
|
123
122
|
|
|
124
123
|
export async function waitScanEvent(
|
|
125
124
|
deviceCapabilities: DeviceCapabilities,
|
|
126
|
-
registrationConfig: RegistrationConfig
|
|
125
|
+
registrationConfig: RegistrationConfig,
|
|
127
126
|
): Promise<Event> {
|
|
128
127
|
let resourceURI: string;
|
|
129
128
|
if (deviceCapabilities.useWalkupScanToComp) {
|
|
@@ -142,4 +141,4 @@ export async function clearRegistrations() {
|
|
|
142
141
|
console.log(`Removing: ${dests.destinations[i].name}`);
|
|
143
142
|
await HPApi.removeDestination(dests.destinations[i]);
|
|
144
143
|
}
|
|
145
|
-
}
|
|
144
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DeviceCapabilities } from "./DeviceCapabilities";
|
|
2
2
|
import HPApi from "./HPApi";
|
|
3
3
|
import WalkupScanToCompCaps from "./WalkupScanToCompCaps";
|
|
4
|
+
import ScanCaps from "./ScanCaps";
|
|
4
5
|
|
|
5
6
|
export async function readDeviceCapabilities(): Promise<DeviceCapabilities> {
|
|
6
7
|
let supportsMultiItemScanFromPlaten = true;
|
|
@@ -8,39 +9,44 @@ export async function readDeviceCapabilities(): Promise<DeviceCapabilities> {
|
|
|
8
9
|
let walkupScanToCompCaps: WalkupScanToCompCaps | null = null;
|
|
9
10
|
if (discoveryTree.WalkupScanToCompManifestURI != null) {
|
|
10
11
|
const walkupScanToCompManifest = await HPApi.getWalkupScanToCompManifest(
|
|
11
|
-
discoveryTree.WalkupScanToCompManifestURI
|
|
12
|
+
discoveryTree.WalkupScanToCompManifestURI,
|
|
12
13
|
);
|
|
13
14
|
if (walkupScanToCompManifest.WalkupScanToCompCapsURI != null) {
|
|
14
15
|
walkupScanToCompCaps = await HPApi.getWalkupScanToCompCaps(
|
|
15
|
-
walkupScanToCompManifest.WalkupScanToCompCapsURI
|
|
16
|
+
walkupScanToCompManifest.WalkupScanToCompCapsURI,
|
|
16
17
|
);
|
|
17
18
|
supportsMultiItemScanFromPlaten =
|
|
18
19
|
walkupScanToCompCaps.supportsMultiItemScanFromPlaten;
|
|
19
20
|
}
|
|
20
21
|
} else if (discoveryTree.WalkupScanManifestURI != null) {
|
|
21
22
|
const walkupScanManifest = await HPApi.getWalkupScanManifest(
|
|
22
|
-
discoveryTree.WalkupScanManifestURI
|
|
23
|
+
discoveryTree.WalkupScanManifestURI,
|
|
23
24
|
);
|
|
24
25
|
if (walkupScanManifest.walkupScanDestinationsURI != null) {
|
|
25
26
|
await HPApi.getWalkupScanDestinations(
|
|
26
|
-
walkupScanManifest.walkupScanDestinationsURI
|
|
27
|
+
walkupScanManifest.walkupScanDestinationsURI,
|
|
27
28
|
);
|
|
28
29
|
}
|
|
29
30
|
} else {
|
|
30
31
|
console.log("Unknown device!");
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
let scanCaps: ScanCaps | null = null;
|
|
33
35
|
if (discoveryTree.ScanJobManifestURI != null) {
|
|
34
36
|
const scanJobManifest = await HPApi.getScanJobManifest(
|
|
35
|
-
discoveryTree.ScanJobManifestURI
|
|
37
|
+
discoveryTree.ScanJobManifestURI,
|
|
36
38
|
);
|
|
37
39
|
if (scanJobManifest.ScanCapsURI != null) {
|
|
38
|
-
await HPApi.getScanCaps(scanJobManifest.ScanCapsURI);
|
|
40
|
+
scanCaps = await HPApi.getScanCaps(scanJobManifest.ScanCapsURI);
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
return {
|
|
43
45
|
supportsMultiItemScanFromPlaten,
|
|
44
46
|
useWalkupScanToComp: walkupScanToCompCaps != null,
|
|
47
|
+
platenMaxWidth: scanCaps?.PlatenMaxWidth || null,
|
|
48
|
+
platenMaxHeight: scanCaps?.PlatenMaxHeight || null,
|
|
49
|
+
adfMaxWidth: scanCaps?.AdfMaxWidth || null,
|
|
50
|
+
adfMaxHeight: scanCaps?.AdfMaxHeight || null,
|
|
45
51
|
};
|
|
46
52
|
}
|
package/src/scanProcessing.ts
CHANGED
|
@@ -12,9 +12,10 @@ import Job from "./Job";
|
|
|
12
12
|
import { delay } from "./delay";
|
|
13
13
|
import PathHelper from "./PathHelper";
|
|
14
14
|
import ScanStatus from "./ScanStatus";
|
|
15
|
+
import { InputSource } from "./InputSource";
|
|
15
16
|
|
|
16
17
|
async function waitDeviceUntilItIsReadyToUploadOrCompleted(
|
|
17
|
-
jobUrl: string
|
|
18
|
+
jobUrl: string,
|
|
18
19
|
): Promise<Job> {
|
|
19
20
|
let job = null;
|
|
20
21
|
let isReadyToUpload = false;
|
|
@@ -38,7 +39,7 @@ async function waitDeviceUntilItIsReadyToUploadOrCompleted(
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
async function TryGetDestination(
|
|
41
|
-
event: Event
|
|
42
|
+
event: Event,
|
|
42
43
|
): Promise<WalkupScanDestination | WalkupScanToCompDestination | null> {
|
|
43
44
|
//this code can in some cases be executed before the user actually chooses between Document or Photo
|
|
44
45
|
//so lets fetch the contentType (Document or Photo) until we get a value
|
|
@@ -83,7 +84,7 @@ function createScanPage(
|
|
|
83
84
|
job: Job,
|
|
84
85
|
currentPageNumber: number,
|
|
85
86
|
filePath: string,
|
|
86
|
-
sizeFixed: number | null
|
|
87
|
+
sizeFixed: number | null,
|
|
87
88
|
): ScanPage {
|
|
88
89
|
let height = sizeFixed ?? job.imageHeight;
|
|
89
90
|
return {
|
|
@@ -92,17 +93,18 @@ function createScanPage(
|
|
|
92
93
|
width: job.imageWidth ?? 0,
|
|
93
94
|
height: height ?? 0,
|
|
94
95
|
xResolution: job.xResolution ?? 200,
|
|
95
|
-
yResolution: job.yResolution ?? 200
|
|
96
|
+
yResolution: job.yResolution ?? 200,
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
async function handleProcessingState(
|
|
100
101
|
job: Job,
|
|
101
|
-
inputSource:
|
|
102
|
+
inputSource: InputSource,
|
|
102
103
|
folder: string,
|
|
103
104
|
scanCount: number,
|
|
104
105
|
currentPageNumber: number,
|
|
105
|
-
filePattern: string | undefined
|
|
106
|
+
filePattern: string | undefined,
|
|
107
|
+
date: Date,
|
|
106
108
|
): Promise<ScanPage | null> {
|
|
107
109
|
if (
|
|
108
110
|
job.pageState == "ReadyToUpload" &&
|
|
@@ -111,7 +113,7 @@ async function handleProcessingState(
|
|
|
111
113
|
) {
|
|
112
114
|
console.log(
|
|
113
115
|
`Ready to download page job page ${job.currentPageNumber} at:`,
|
|
114
|
-
job.binaryURL
|
|
116
|
+
job.binaryURL,
|
|
115
117
|
);
|
|
116
118
|
|
|
117
119
|
const destinationFilePath = PathHelper.getFileForPage(
|
|
@@ -119,20 +121,21 @@ async function handleProcessingState(
|
|
|
119
121
|
scanCount,
|
|
120
122
|
currentPageNumber,
|
|
121
123
|
filePattern,
|
|
122
|
-
"jpg"
|
|
124
|
+
"jpg",
|
|
125
|
+
date,
|
|
123
126
|
);
|
|
124
127
|
const filePath = await HPApi.downloadPage(
|
|
125
128
|
job.binaryURL,
|
|
126
|
-
destinationFilePath
|
|
129
|
+
destinationFilePath,
|
|
127
130
|
);
|
|
128
131
|
console.log("Page downloaded to:", filePath);
|
|
129
132
|
|
|
130
133
|
let sizeFixed: null | number = null;
|
|
131
|
-
if (inputSource ==
|
|
134
|
+
if (inputSource == InputSource.Adf) {
|
|
132
135
|
sizeFixed = await scanProcessing(filePath);
|
|
133
136
|
if (sizeFixed == null) {
|
|
134
137
|
console.log(
|
|
135
|
-
`File size has not been fixed, DNF may not have been found and approximate height is: ${job.imageHeight}
|
|
138
|
+
`File size has not been fixed, DNF may not have been found and approximate height is: ${job.imageHeight}`,
|
|
136
139
|
);
|
|
137
140
|
}
|
|
138
141
|
}
|
|
@@ -146,11 +149,12 @@ async function handleProcessingState(
|
|
|
146
149
|
|
|
147
150
|
async function executeScanJob(
|
|
148
151
|
scanJobSettings: ScanJobSettings,
|
|
149
|
-
inputSource:
|
|
152
|
+
inputSource: InputSource,
|
|
150
153
|
folder: string,
|
|
151
154
|
scanCount: number,
|
|
152
155
|
scanJobContent: ScanContent,
|
|
153
|
-
filePattern: string | undefined
|
|
156
|
+
filePattern: string | undefined,
|
|
157
|
+
date: Date,
|
|
154
158
|
): Promise<"Completed" | "Canceled"> {
|
|
155
159
|
const jobUrl = await HPApi.postJob(scanJobSettings);
|
|
156
160
|
|
|
@@ -171,7 +175,8 @@ async function executeScanJob(
|
|
|
171
175
|
folder,
|
|
172
176
|
scanCount,
|
|
173
177
|
scanJobContent.elements.length + 1,
|
|
174
|
-
filePattern
|
|
178
|
+
filePattern,
|
|
179
|
+
date,
|
|
175
180
|
);
|
|
176
181
|
job = await HPApi.getJob(jobUrl);
|
|
177
182
|
if (page != null && job.jobState != "Canceled") {
|
|
@@ -186,7 +191,7 @@ async function executeScanJob(
|
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
193
|
console.log(
|
|
189
|
-
`Job state: ${job.jobState}, totalPages: ${scanJobContent.elements.length}
|
|
194
|
+
`Job state: ${job.jobState}, totalPages: ${scanJobContent.elements.length}:`,
|
|
190
195
|
);
|
|
191
196
|
return job.jobState;
|
|
192
197
|
}
|
|
@@ -197,9 +202,8 @@ async function waitScanNewPageRequest(compEventURI: string): Promise<boolean> {
|
|
|
197
202
|
while (wait) {
|
|
198
203
|
await new Promise((resolve) => setTimeout(resolve, 1000)); //wait 1s
|
|
199
204
|
|
|
200
|
-
let walkupScanToCompEvent =
|
|
201
|
-
compEventURI
|
|
202
|
-
);
|
|
205
|
+
let walkupScanToCompEvent =
|
|
206
|
+
await HPApi.getWalkupScanToCompEvent(compEventURI);
|
|
203
207
|
let message = walkupScanToCompEvent.eventType;
|
|
204
208
|
|
|
205
209
|
if (message === "ScanNewPageRequested") {
|
|
@@ -219,13 +223,14 @@ async function waitScanNewPageRequest(compEventURI: string): Promise<boolean> {
|
|
|
219
223
|
|
|
220
224
|
async function executeScanJobs(
|
|
221
225
|
scanJobSettings: ScanJobSettings,
|
|
222
|
-
inputSource:
|
|
226
|
+
inputSource: InputSource,
|
|
223
227
|
folder: string,
|
|
224
228
|
scanCount: number,
|
|
225
229
|
scanJobContent: ScanContent,
|
|
226
230
|
firstEvent: Event,
|
|
227
231
|
deviceCapabilities: DeviceCapabilities,
|
|
228
|
-
filePattern: string | undefined
|
|
232
|
+
filePattern: string | undefined,
|
|
233
|
+
date: Date,
|
|
229
234
|
) {
|
|
230
235
|
let jobState = await executeScanJob(
|
|
231
236
|
scanJobSettings,
|
|
@@ -233,19 +238,20 @@ async function executeScanJobs(
|
|
|
233
238
|
folder,
|
|
234
239
|
scanCount,
|
|
235
240
|
scanJobContent,
|
|
236
|
-
filePattern
|
|
241
|
+
filePattern,
|
|
242
|
+
date,
|
|
237
243
|
);
|
|
238
244
|
let lastEvent = firstEvent;
|
|
239
245
|
if (
|
|
240
246
|
jobState === "Completed" &&
|
|
241
247
|
lastEvent.compEventURI &&
|
|
242
|
-
inputSource !==
|
|
248
|
+
inputSource !== InputSource.Adf &&
|
|
243
249
|
lastEvent.destinationURI &&
|
|
244
250
|
deviceCapabilities.supportsMultiItemScanFromPlaten
|
|
245
251
|
) {
|
|
246
252
|
lastEvent = await waitForScanEvent(
|
|
247
253
|
lastEvent.destinationURI,
|
|
248
|
-
lastEvent.agingStamp
|
|
254
|
+
lastEvent.agingStamp,
|
|
249
255
|
);
|
|
250
256
|
if (!lastEvent.compEventURI) {
|
|
251
257
|
return;
|
|
@@ -258,7 +264,8 @@ async function executeScanJobs(
|
|
|
258
264
|
folder,
|
|
259
265
|
scanCount,
|
|
260
266
|
scanJobContent,
|
|
261
|
-
filePattern
|
|
267
|
+
filePattern,
|
|
268
|
+
new Date(),
|
|
262
269
|
);
|
|
263
270
|
if (jobState !== "Completed") {
|
|
264
271
|
return;
|
|
@@ -268,7 +275,7 @@ async function executeScanJobs(
|
|
|
268
275
|
}
|
|
269
276
|
lastEvent = await waitForScanEvent(
|
|
270
277
|
lastEvent.destinationURI,
|
|
271
|
-
lastEvent.agingStamp
|
|
278
|
+
lastEvent.agingStamp,
|
|
272
279
|
);
|
|
273
280
|
if (!lastEvent.compEventURI) {
|
|
274
281
|
return;
|
|
@@ -282,14 +289,16 @@ async function mergeToPdf(
|
|
|
282
289
|
folder: string,
|
|
283
290
|
scanCount: number,
|
|
284
291
|
scanJobContent: ScanContent,
|
|
285
|
-
filePattern: string | undefined
|
|
292
|
+
filePattern: string | undefined,
|
|
293
|
+
date: Date,
|
|
286
294
|
): Promise<string | null> {
|
|
287
295
|
if (scanJobContent.elements.length > 0) {
|
|
288
|
-
const pdfFilePath = PathHelper.getFileForScan(
|
|
296
|
+
const pdfFilePath: string = PathHelper.getFileForScan(
|
|
289
297
|
folder,
|
|
290
298
|
scanCount,
|
|
291
299
|
filePattern,
|
|
292
|
-
"pdf"
|
|
300
|
+
"pdf",
|
|
301
|
+
date,
|
|
293
302
|
);
|
|
294
303
|
await createPdfFrom(scanJobContent, pdfFilePath);
|
|
295
304
|
scanJobContent.elements.forEach((e) => fs.unlink(e.path));
|
|
@@ -301,21 +310,21 @@ async function mergeToPdf(
|
|
|
301
310
|
|
|
302
311
|
function displayPdfScan(
|
|
303
312
|
pdfFilePath: string | null,
|
|
304
|
-
scanJobContent: ScanContent
|
|
313
|
+
scanJobContent: ScanContent,
|
|
305
314
|
) {
|
|
306
315
|
if (pdfFilePath === null) {
|
|
307
316
|
console.log(`Pdf generated has not been generated`);
|
|
308
317
|
return;
|
|
309
318
|
}
|
|
310
319
|
console.log(
|
|
311
|
-
`The following page(s) have been rendered inside '${pdfFilePath}':
|
|
320
|
+
`The following page(s) have been rendered inside '${pdfFilePath}': `,
|
|
312
321
|
);
|
|
313
322
|
scanJobContent.elements.forEach((e) =>
|
|
314
323
|
console.log(
|
|
315
324
|
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
316
325
|
e.height
|
|
317
|
-
}
|
|
318
|
-
)
|
|
326
|
+
}`,
|
|
327
|
+
),
|
|
319
328
|
);
|
|
320
329
|
}
|
|
321
330
|
|
|
@@ -324,13 +333,13 @@ function displayJpegScan(scanJobContent: ScanContent) {
|
|
|
324
333
|
console.log(
|
|
325
334
|
`\t- page ${e.pageNumber.toString().padStart(3, " ")} - ${e.width}x${
|
|
326
335
|
e.height
|
|
327
|
-
} - ${e.path}
|
|
328
|
-
)
|
|
336
|
+
} - ${e.path}`,
|
|
337
|
+
),
|
|
329
338
|
);
|
|
330
339
|
}
|
|
331
340
|
|
|
332
341
|
function isPdf(
|
|
333
|
-
destination: WalkupScanDestination | WalkupScanToCompDestination
|
|
342
|
+
destination: WalkupScanDestination | WalkupScanToCompDestination,
|
|
334
343
|
) {
|
|
335
344
|
if (
|
|
336
345
|
destination.shortcut === "SavePDF" ||
|
|
@@ -345,19 +354,61 @@ function isPdf(
|
|
|
345
354
|
return false;
|
|
346
355
|
} else {
|
|
347
356
|
console.log(
|
|
348
|
-
`Unexpected shortcut received: ${destination.shortcut}, considering it as non pdf target
|
|
357
|
+
`Unexpected shortcut received: ${destination.shortcut}, considering it as non pdf target!`,
|
|
349
358
|
);
|
|
350
359
|
return false;
|
|
351
360
|
}
|
|
352
361
|
}
|
|
353
362
|
|
|
363
|
+
export function getScanWidth(
|
|
364
|
+
scanConfig: ScanConfig,
|
|
365
|
+
inputSource: "Adf" | "Platen",
|
|
366
|
+
deviceCapabilities: DeviceCapabilities,
|
|
367
|
+
) {
|
|
368
|
+
if (scanConfig.width && scanConfig.width > 0) {
|
|
369
|
+
const maxWidth =
|
|
370
|
+
inputSource === "Adf"
|
|
371
|
+
? deviceCapabilities.adfMaxWidth
|
|
372
|
+
: deviceCapabilities.platenMaxWidth;
|
|
373
|
+
|
|
374
|
+
if (maxWidth && scanConfig.width > maxWidth) {
|
|
375
|
+
return maxWidth;
|
|
376
|
+
} else {
|
|
377
|
+
return scanConfig.width;
|
|
378
|
+
}
|
|
379
|
+
} else {
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export function getScanHeight(
|
|
385
|
+
scanConfig: ScanConfig,
|
|
386
|
+
inputSource: "Adf" | "Platen",
|
|
387
|
+
deviceCapabilities: DeviceCapabilities,
|
|
388
|
+
) {
|
|
389
|
+
if (scanConfig.height && scanConfig.height > 0) {
|
|
390
|
+
const maxHeight =
|
|
391
|
+
inputSource === "Adf"
|
|
392
|
+
? deviceCapabilities.adfMaxHeight
|
|
393
|
+
: deviceCapabilities.platenMaxHeight;
|
|
394
|
+
|
|
395
|
+
if (maxHeight && scanConfig.height > maxHeight) {
|
|
396
|
+
return maxHeight;
|
|
397
|
+
} else {
|
|
398
|
+
return scanConfig.height;
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
354
405
|
export async function saveScan(
|
|
355
406
|
event: Event,
|
|
356
407
|
folder: string,
|
|
357
408
|
tempFolder: string,
|
|
358
409
|
scanCount: number,
|
|
359
410
|
deviceCapabilities: DeviceCapabilities,
|
|
360
|
-
scanConfig: ScanConfig
|
|
411
|
+
scanConfig: ScanConfig,
|
|
361
412
|
): Promise<void> {
|
|
362
413
|
if (event.compEventURI) {
|
|
363
414
|
const proceedToScan = await waitScanRequest(event.compEventURI);
|
|
@@ -381,7 +432,7 @@ export async function saveScan(
|
|
|
381
432
|
contentType = "Document";
|
|
382
433
|
destinationFolder = tempFolder;
|
|
383
434
|
console.log(
|
|
384
|
-
`Scan will be converted to pdf, using ${destinationFolder} as temp scan output directory for individual pages
|
|
435
|
+
`Scan will be converted to pdf, using ${destinationFolder} as temp scan output directory for individual pages`,
|
|
385
436
|
);
|
|
386
437
|
} else {
|
|
387
438
|
toPdf = false;
|
|
@@ -397,16 +448,22 @@ export async function saveScan(
|
|
|
397
448
|
console.log("Afd is : " + scanStatus.adfState);
|
|
398
449
|
|
|
399
450
|
const inputSource = scanStatus.getInputSource();
|
|
451
|
+
const scanWidth = getScanWidth(scanConfig, inputSource, deviceCapabilities);
|
|
452
|
+
const scanHeight = getScanHeight(scanConfig, inputSource, deviceCapabilities);
|
|
400
453
|
|
|
401
454
|
const scanJobSettings = new ScanJobSettings(
|
|
402
455
|
inputSource,
|
|
403
456
|
contentType,
|
|
404
457
|
scanConfig.resolution,
|
|
405
|
-
|
|
458
|
+
scanWidth,
|
|
459
|
+
scanHeight,
|
|
460
|
+
isDuplex,
|
|
406
461
|
);
|
|
407
462
|
|
|
408
463
|
const scanJobContent: ScanContent = { elements: [] };
|
|
409
464
|
|
|
465
|
+
const scanDate = new Date();
|
|
466
|
+
|
|
410
467
|
await executeScanJobs(
|
|
411
468
|
scanJobSettings,
|
|
412
469
|
inputSource,
|
|
@@ -415,11 +472,12 @@ export async function saveScan(
|
|
|
415
472
|
scanJobContent,
|
|
416
473
|
event,
|
|
417
474
|
deviceCapabilities,
|
|
418
|
-
scanConfig.directoryConfig.filePattern
|
|
475
|
+
scanConfig.directoryConfig.filePattern,
|
|
476
|
+
scanDate,
|
|
419
477
|
);
|
|
420
478
|
|
|
421
479
|
console.log(
|
|
422
|
-
`Scan of page(s) completed totalPages: ${scanJobContent.elements.length}
|
|
480
|
+
`Scan of page(s) completed totalPages: ${scanJobContent.elements.length}:`,
|
|
423
481
|
);
|
|
424
482
|
|
|
425
483
|
if (toPdf) {
|
|
@@ -427,7 +485,8 @@ export async function saveScan(
|
|
|
427
485
|
folder,
|
|
428
486
|
scanCount,
|
|
429
487
|
scanJobContent,
|
|
430
|
-
scanConfig.directoryConfig.filePattern
|
|
488
|
+
scanConfig.directoryConfig.filePattern,
|
|
489
|
+
scanDate,
|
|
431
490
|
);
|
|
432
491
|
displayPdfScan(pdfFilePath, scanJobContent);
|
|
433
492
|
} else {
|
|
@@ -442,6 +501,8 @@ export type DirectoryConfig = {
|
|
|
442
501
|
};
|
|
443
502
|
export type ScanConfig = {
|
|
444
503
|
resolution: number;
|
|
504
|
+
width: number | null;
|
|
505
|
+
height: number | null;
|
|
445
506
|
directoryConfig: DirectoryConfig;
|
|
446
507
|
};
|
|
447
508
|
export type AdfAutoScanConfig = ScanConfig & {
|
|
@@ -455,7 +516,9 @@ export async function scanFromAdf(
|
|
|
455
516
|
scanCount: number,
|
|
456
517
|
folder: string,
|
|
457
518
|
tempFolder: string,
|
|
458
|
-
adfAutoScanConfig: AdfAutoScanConfig
|
|
519
|
+
adfAutoScanConfig: AdfAutoScanConfig,
|
|
520
|
+
deviceCapabilities: DeviceCapabilities,
|
|
521
|
+
date: Date,
|
|
459
522
|
) {
|
|
460
523
|
let destinationFolder: string;
|
|
461
524
|
let contentType: "Document" | "Photo";
|
|
@@ -463,33 +526,43 @@ export async function scanFromAdf(
|
|
|
463
526
|
contentType = "Document";
|
|
464
527
|
destinationFolder = tempFolder;
|
|
465
528
|
console.log(
|
|
466
|
-
`Scan will be converted to pdf, using ${destinationFolder} as temp scan output directory for individual pages
|
|
529
|
+
`Scan will be converted to pdf, using ${destinationFolder} as temp scan output directory for individual pages`,
|
|
467
530
|
);
|
|
468
531
|
} else {
|
|
469
532
|
contentType = "Photo";
|
|
470
533
|
destinationFolder = folder;
|
|
471
534
|
}
|
|
472
535
|
|
|
473
|
-
const
|
|
536
|
+
const scanWidth = getScanWidth(adfAutoScanConfig, "Adf", deviceCapabilities);
|
|
537
|
+
const scanHeight = getScanHeight(
|
|
538
|
+
adfAutoScanConfig,
|
|
474
539
|
"Adf",
|
|
540
|
+
deviceCapabilities,
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
const scanJobSettings = new ScanJobSettings(
|
|
544
|
+
InputSource.Adf,
|
|
475
545
|
contentType,
|
|
476
546
|
adfAutoScanConfig.resolution,
|
|
477
|
-
|
|
547
|
+
scanWidth,
|
|
548
|
+
scanHeight,
|
|
549
|
+
adfAutoScanConfig.isDuplex,
|
|
478
550
|
);
|
|
479
551
|
|
|
480
552
|
const scanJobContent: ScanContent = { elements: [] };
|
|
481
553
|
|
|
482
554
|
await executeScanJob(
|
|
483
555
|
scanJobSettings,
|
|
484
|
-
|
|
556
|
+
InputSource.Adf,
|
|
485
557
|
destinationFolder,
|
|
486
558
|
scanCount,
|
|
487
559
|
scanJobContent,
|
|
488
|
-
adfAutoScanConfig.directoryConfig.filePattern
|
|
560
|
+
adfAutoScanConfig.directoryConfig.filePattern,
|
|
561
|
+
date,
|
|
489
562
|
);
|
|
490
563
|
|
|
491
564
|
console.log(
|
|
492
|
-
`Scan of page(s) completed
|
|
565
|
+
`Scan of page(s) completed, total pages: ${scanJobContent.elements.length}:`,
|
|
493
566
|
);
|
|
494
567
|
|
|
495
568
|
if (adfAutoScanConfig.generatePdf) {
|
|
@@ -497,7 +570,8 @@ export async function scanFromAdf(
|
|
|
497
570
|
folder,
|
|
498
571
|
scanCount,
|
|
499
572
|
scanJobContent,
|
|
500
|
-
adfAutoScanConfig.directoryConfig.filePattern
|
|
573
|
+
adfAutoScanConfig.directoryConfig.filePattern,
|
|
574
|
+
date,
|
|
501
575
|
);
|
|
502
576
|
displayPdfScan(pdfFilePath, scanJobContent);
|
|
503
577
|
} else {
|
|
@@ -505,7 +579,10 @@ export async function scanFromAdf(
|
|
|
505
579
|
}
|
|
506
580
|
}
|
|
507
581
|
|
|
508
|
-
export async function waitAdfLoaded(
|
|
582
|
+
export async function waitAdfLoaded(
|
|
583
|
+
pollingInterval: number,
|
|
584
|
+
startScanDelay: number,
|
|
585
|
+
) {
|
|
509
586
|
let ready = false;
|
|
510
587
|
while (!ready) {
|
|
511
588
|
let scanStatus: ScanStatus = await HPApi.getScanStatus();
|
|
@@ -532,4 +609,4 @@ export async function waitAdfLoaded(pollingInterval: number, startScanDelay: num
|
|
|
532
609
|
console.log(`ADF not loaded anymore, waiting...`);
|
|
533
610
|
}
|
|
534
611
|
}
|
|
535
|
-
}
|
|
612
|
+
}
|
package/dist/fixJpegSize.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import Event from "./Event";
|
|
2
|
-
import { DeviceCapabilities } from "./DeviceCapabilities";
|
|
3
|
-
export declare function saveScan(event: Event, folder: string, tempFolder: string, scanCount: number, deviceCapabilities: DeviceCapabilities, scanConfig: ScanConfig): Promise<void>;
|
|
4
|
-
export type DirectoryConfig = {
|
|
5
|
-
directory: string | undefined;
|
|
6
|
-
tempDirectory: string | undefined;
|
|
7
|
-
filePattern: string | undefined;
|
|
8
|
-
};
|
|
9
|
-
export type ScanConfig = {
|
|
10
|
-
resolution: number;
|
|
11
|
-
directoryConfig: DirectoryConfig;
|
|
12
|
-
};
|
|
13
|
-
export type AdfAutoScanConfig = ScanConfig & {
|
|
14
|
-
isDuplex: boolean;
|
|
15
|
-
generatePdf: boolean;
|
|
16
|
-
pollingInterval: number;
|
|
17
|
-
startScanDelay: number;
|
|
18
|
-
};
|
|
19
|
-
export declare function scanFromAdf(scanCount: number, folder: string, tempFolder: string, adfAutoScanConfig: AdfAutoScanConfig): Promise<void>;
|