node-hp-scan-to 1.2.1 → 1.3.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.
Files changed (235) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -10
  3. package/dist/Destination.js +36 -84
  4. package/dist/Destination.js.map +1 -1
  5. package/dist/DeviceCapabilities.d.ts +4 -0
  6. package/dist/DeviceCapabilities.js +3 -0
  7. package/dist/DeviceCapabilities.js.map +1 -0
  8. package/dist/DiscoveryTree.d.ts +16 -0
  9. package/dist/DiscoveryTree.js +38 -0
  10. package/dist/DiscoveryTree.js.map +1 -0
  11. package/dist/Event.d.ts +1 -1
  12. package/dist/Event.js +24 -39
  13. package/dist/Event.js.map +1 -1
  14. package/dist/EventTable.d.ts +5 -0
  15. package/dist/EventTable.js +24 -18
  16. package/dist/EventTable.js.map +1 -1
  17. package/dist/HPApi.d.ts +26 -18
  18. package/dist/HPApi.js +386 -461
  19. package/dist/HPApi.js.map +1 -1
  20. package/dist/Job.d.ts +8 -7
  21. package/dist/Job.js +69 -86
  22. package/dist/Job.js.map +1 -1
  23. package/dist/JpegUtil.js +73 -82
  24. package/dist/JpegUtil.js.map +1 -1
  25. package/dist/KnownShortcut.d.ts +1 -0
  26. package/dist/KnownShortcut.js +3 -0
  27. package/dist/KnownShortcut.js.map +1 -0
  28. package/dist/PathHelper.d.ts +2 -1
  29. package/dist/PathHelper.js +41 -68
  30. package/dist/PathHelper.js.map +1 -1
  31. package/dist/ScanCaps.d.ts +7 -0
  32. package/dist/ScanCaps.js +17 -0
  33. package/dist/ScanCaps.js.map +1 -0
  34. package/dist/ScanContent.js +18 -73
  35. package/dist/ScanContent.js.map +1 -1
  36. package/dist/ScanJobManifest.d.ts +23 -0
  37. package/dist/ScanJobManifest.js +24 -0
  38. package/dist/ScanJobManifest.js.map +1 -0
  39. package/dist/ScanJobSettings.d.ts +3 -1
  40. package/dist/ScanJobSettings.js +48 -88
  41. package/dist/ScanJobSettings.js.map +1 -1
  42. package/dist/ScanStatus.d.ts +1 -0
  43. package/dist/ScanStatus.js +27 -28
  44. package/dist/ScanStatus.js.map +1 -1
  45. package/dist/WalkupScanDestination.d.ts +11 -13
  46. package/dist/WalkupScanDestination.js +32 -35
  47. package/dist/WalkupScanDestination.js.map +1 -1
  48. package/dist/WalkupScanDestinations.d.ts +1 -0
  49. package/dist/WalkupScanDestinations.js +21 -18
  50. package/dist/WalkupScanDestinations.js.map +1 -1
  51. package/dist/WalkupScanManifest.d.ts +23 -0
  52. package/dist/WalkupScanManifest.js +25 -0
  53. package/dist/WalkupScanManifest.js.map +1 -0
  54. package/dist/WalkupScanToCompCaps.d.ts +12 -0
  55. package/dist/WalkupScanToCompCaps.js +20 -0
  56. package/dist/WalkupScanToCompCaps.js.map +1 -0
  57. package/dist/WalkupScanToCompDestination.d.ts +10 -14
  58. package/dist/WalkupScanToCompDestination.js +32 -38
  59. package/dist/WalkupScanToCompDestination.js.map +1 -1
  60. package/dist/WalkupScanToCompDestinations.d.ts +1 -0
  61. package/dist/WalkupScanToCompDestinations.js +21 -18
  62. package/dist/WalkupScanToCompDestinations.js.map +1 -1
  63. package/dist/WalkupScanToCompEvent.d.ts +2 -1
  64. package/dist/WalkupScanToCompEvent.js +14 -11
  65. package/dist/WalkupScanToCompEvent.js.map +1 -1
  66. package/dist/WalkupScanToCompManifest.d.ts +23 -0
  67. package/dist/WalkupScanToCompManifest.js +25 -0
  68. package/dist/WalkupScanToCompManifest.js.map +1 -0
  69. package/dist/delay.d.ts +1 -0
  70. package/dist/delay.js +10 -0
  71. package/dist/delay.js.map +1 -0
  72. package/dist/fixJpegSize.d.ts +19 -0
  73. package/dist/fixJpegSize.js +292 -0
  74. package/dist/fixJpegSize.js.map +1 -0
  75. package/dist/index.js +209 -607
  76. package/dist/index.js.map +1 -1
  77. package/dist/listening.d.ts +9 -0
  78. package/dist/listening.js +108 -0
  79. package/dist/listening.js.map +1 -0
  80. package/dist/readDeviceCapabilities.d.ts +2 -0
  81. package/dist/readDeviceCapabilities.js +41 -0
  82. package/dist/readDeviceCapabilities.js.map +1 -0
  83. package/dist/scanProcess.d.ts +19 -0
  84. package/dist/scanProcess.js +292 -0
  85. package/dist/scanProcess.js.map +1 -0
  86. package/dist/scanProcessing.d.ts +20 -0
  87. package/dist/scanProcessing.js +320 -0
  88. package/dist/scanProcessing.js.map +1 -0
  89. package/dist/src/Destination.d.ts +8 -0
  90. package/dist/src/Destination.js +68 -0
  91. package/dist/src/Destination.js.map +1 -0
  92. package/dist/src/DiscoveryTree.d.ts +16 -0
  93. package/dist/src/DiscoveryTree.js +38 -0
  94. package/dist/src/DiscoveryTree.js.map +1 -0
  95. package/dist/src/Event.d.ts +21 -0
  96. package/dist/src/Event.js +32 -0
  97. package/dist/src/Event.js.map +1 -0
  98. package/dist/src/EventTable.d.ts +16 -0
  99. package/dist/src/EventTable.js +33 -0
  100. package/dist/src/EventTable.js.map +1 -0
  101. package/dist/src/HPApi.d.ts +50 -0
  102. package/dist/src/HPApi.js +454 -0
  103. package/dist/src/HPApi.js.map +1 -0
  104. package/dist/src/Job.d.ts +37 -0
  105. package/dist/src/Job.js +78 -0
  106. package/dist/src/Job.js.map +1 -0
  107. package/dist/src/JpegUtil.d.ts +26 -0
  108. package/dist/src/JpegUtil.js +229 -0
  109. package/dist/src/JpegUtil.js.map +1 -0
  110. package/dist/src/KnownShortcut.d.ts +1 -0
  111. package/dist/src/KnownShortcut.js +3 -0
  112. package/dist/src/KnownShortcut.js.map +1 -0
  113. package/dist/src/PathHelper.d.ts +6 -0
  114. package/dist/src/PathHelper.js +52 -0
  115. package/dist/src/PathHelper.js.map +1 -0
  116. package/dist/src/ScanCaps.d.ts +7 -0
  117. package/dist/src/ScanCaps.js +17 -0
  118. package/dist/src/ScanCaps.js.map +1 -0
  119. package/dist/src/ScanJobManifest.d.ts +23 -0
  120. package/dist/src/ScanJobManifest.js +24 -0
  121. package/dist/src/ScanJobManifest.js.map +1 -0
  122. package/dist/src/ScanJobSettings.d.ts +8 -0
  123. package/dist/src/ScanJobSettings.js +56 -0
  124. package/dist/src/ScanJobSettings.js.map +1 -0
  125. package/dist/src/ScanStatus.d.ts +19 -0
  126. package/dist/src/ScanStatus.js +35 -0
  127. package/dist/src/ScanStatus.js.map +1 -0
  128. package/dist/src/WalkupScanDestination.d.ts +22 -0
  129. package/dist/src/WalkupScanDestination.js +38 -0
  130. package/dist/src/WalkupScanDestination.js.map +1 -0
  131. package/dist/src/WalkupScanDestinations.d.ts +12 -0
  132. package/dist/src/WalkupScanDestinations.js +30 -0
  133. package/dist/src/WalkupScanDestinations.js.map +1 -0
  134. package/dist/src/WalkupScanManifest.d.ts +23 -0
  135. package/dist/src/WalkupScanManifest.js +25 -0
  136. package/dist/src/WalkupScanManifest.js.map +1 -0
  137. package/dist/src/WalkupScanToCompCaps.d.ts +12 -0
  138. package/dist/src/WalkupScanToCompCaps.js +20 -0
  139. package/dist/src/WalkupScanToCompCaps.js.map +1 -0
  140. package/dist/src/WalkupScanToCompDestination.d.ts +22 -0
  141. package/dist/src/WalkupScanToCompDestination.js +38 -0
  142. package/dist/src/WalkupScanToCompDestination.js.map +1 -0
  143. package/dist/src/WalkupScanToCompDestinations.d.ts +12 -0
  144. package/dist/src/WalkupScanToCompDestinations.js +30 -0
  145. package/dist/src/WalkupScanToCompDestinations.js.map +1 -0
  146. package/dist/src/WalkupScanToCompEvent.d.ts +11 -0
  147. package/dist/src/WalkupScanToCompEvent.js +20 -0
  148. package/dist/src/WalkupScanToCompEvent.js.map +1 -0
  149. package/dist/src/WalkupScanToCompManifest.d.ts +23 -0
  150. package/dist/src/WalkupScanToCompManifest.js +25 -0
  151. package/dist/src/WalkupScanToCompManifest.js.map +1 -0
  152. package/dist/src/delay.d.ts +1 -0
  153. package/dist/src/delay.js +10 -0
  154. package/dist/src/delay.js.map +1 -0
  155. package/dist/test/DiscoveryTree.test.d.ts +1 -0
  156. package/dist/test/DiscoveryTree.test.js +68 -0
  157. package/dist/test/DiscoveryTree.test.js.map +1 -0
  158. package/dist/test/EtagEventTable.test.d.ts +1 -0
  159. package/dist/test/EtagEventTable.test.js +93 -0
  160. package/dist/test/EtagEventTable.test.js.map +1 -0
  161. package/dist/test/Job.test.d.ts +1 -0
  162. package/dist/test/Job.test.js +104 -0
  163. package/dist/test/Job.test.js.map +1 -0
  164. package/dist/test/JpegUtil.test.d.ts +1 -0
  165. package/dist/test/JpegUtil.test.js +51 -0
  166. package/dist/test/JpegUtil.test.js.map +1 -0
  167. package/dist/test/PathHelper.test.d.ts +1 -0
  168. package/dist/test/PathHelper.test.js +99 -0
  169. package/dist/test/PathHelper.test.js.map +1 -0
  170. package/dist/test/ScanJobManifest.test.d.ts +1 -0
  171. package/dist/test/ScanJobManifest.test.js +56 -0
  172. package/dist/test/ScanJobManifest.test.js.map +1 -0
  173. package/dist/test/ScanJobSettings.test.d.ts +1 -0
  174. package/dist/test/ScanJobSettings.test.js +53 -0
  175. package/dist/test/ScanJobSettings.test.js.map +1 -0
  176. package/dist/test/ScanStatus.test.d.ts +1 -0
  177. package/dist/test/ScanStatus.test.js +75 -0
  178. package/dist/test/ScanStatus.test.js.map +1 -0
  179. package/dist/test/WalkupScanDestination.test.d.ts +1 -0
  180. package/dist/test/WalkupScanDestination.test.js +80 -0
  181. package/dist/test/WalkupScanDestination.test.js.map +1 -0
  182. package/dist/test/WalkupScanDestinations.test.d.ts +1 -0
  183. package/dist/test/WalkupScanDestinations.test.js +68 -0
  184. package/dist/test/WalkupScanDestinations.test.js.map +1 -0
  185. package/dist/test/WalkupScanManifest.test.d.ts +1 -0
  186. package/dist/test/WalkupScanManifest.test.js +46 -0
  187. package/dist/test/WalkupScanManifest.test.js.map +1 -0
  188. package/dist/test/WalkupScanToCompCaps.test.d.ts +1 -0
  189. package/dist/test/WalkupScanToCompCaps.test.js +56 -0
  190. package/dist/test/WalkupScanToCompCaps.test.js.map +1 -0
  191. package/dist/test/WalkupScanToCompDestination.test.d.ts +1 -0
  192. package/dist/test/WalkupScanToCompDestination.test.js +58 -0
  193. package/dist/test/WalkupScanToCompDestination.test.js.map +1 -0
  194. package/dist/test/WalkupScanToCompDestinations.test.d.ts +1 -0
  195. package/dist/test/WalkupScanToCompDestinations.test.js +58 -0
  196. package/dist/test/WalkupScanToCompDestinations.test.js.map +1 -0
  197. package/dist/test/WalkupScanToCompEvent.test.d.ts +1 -0
  198. package/dist/test/WalkupScanToCompEvent.test.js +46 -0
  199. package/dist/test/WalkupScanToCompEvent.test.js.map +1 -0
  200. package/dist/test/WalkupScanToCompManifest.test.d.ts +1 -0
  201. package/dist/test/WalkupScanToCompManifest.test.js +46 -0
  202. package/dist/test/WalkupScanToCompManifest.test.js.map +1 -0
  203. package/dist/test/clean.d.ts +1 -0
  204. package/dist/test/clean.js +21 -0
  205. package/dist/test/clean.js.map +1 -0
  206. package/package.json +27 -18
  207. package/src/Destination.ts +1 -1
  208. package/src/DeviceCapabilities.ts +4 -0
  209. package/src/DiscoveryTree.ts +56 -0
  210. package/src/Event.ts +17 -7
  211. package/src/EventTable.ts +20 -0
  212. package/src/HPApi.ts +245 -103
  213. package/src/Job.ts +51 -29
  214. package/src/JpegUtil.ts +8 -4
  215. package/src/KnownShortcut.ts +6 -0
  216. package/src/PathHelper.ts +47 -13
  217. package/src/ScanCaps.ts +19 -0
  218. package/src/ScanContent.ts +4 -1
  219. package/src/ScanJobManifest.ts +55 -0
  220. package/src/ScanJobSettings.ts +18 -3
  221. package/src/ScanStatus.ts +9 -0
  222. package/src/WalkupScanDestination.ts +42 -18
  223. package/src/WalkupScanDestinations.ts +12 -0
  224. package/src/WalkupScanManifest.ts +59 -0
  225. package/src/WalkupScanToCompCaps.ts +36 -0
  226. package/src/WalkupScanToCompDestination.ts +38 -24
  227. package/src/WalkupScanToCompDestinations.ts +12 -0
  228. package/src/WalkupScanToCompEvent.ts +15 -3
  229. package/src/WalkupScanToCompManifest.ts +59 -0
  230. package/src/delay.ts +5 -0
  231. package/src/index.ts +267 -465
  232. package/src/listening.ts +145 -0
  233. package/src/readDeviceCapabilities.ts +46 -0
  234. package/src/scanProcessing.ts +535 -0
  235. package/tsconfig.json +1 -1
package/dist/index.js CHANGED
@@ -1,631 +1,233 @@
1
1
  #!/usr/bin/env node
2
2
  // noinspection XmlDeprecatedElement,HtmlDeprecatedTag
3
3
  "use strict";
4
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
- return new (P || (P = Promise))(function (resolve, reject) {
7
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
- step((generator = generator.apply(thisArg, _arguments || [])).next());
11
- });
12
- };
13
- var __generator = (this && this.__generator) || function (thisArg, body) {
14
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
15
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
16
- function verb(n) { return function (v) { return step([n, v]); }; }
17
- function step(op) {
18
- if (f) throw new TypeError("Generator is already executing.");
19
- while (_) try {
20
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
21
- if (y = 0, t) op = [op[0] & 2, t.value];
22
- switch (op[0]) {
23
- case 0: case 1: t = op; break;
24
- case 4: _.label++; return { value: op[1], done: false };
25
- case 5: _.label++; y = op[1]; op = [0]; continue;
26
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
27
- default:
28
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
29
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
30
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
31
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
32
- if (t[2]) _.ops.pop();
33
- _.trys.pop(); continue;
34
- }
35
- op = body.call(thisArg, _);
36
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
37
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
38
- }
39
- };
40
4
  var __importDefault = (this && this.__importDefault) || function (mod) {
41
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
42
6
  };
43
7
  Object.defineProperty(exports, "__esModule", { value: true });
44
- var os_1 = __importDefault(require("os"));
45
- var promises_1 = __importDefault(require("fs/promises"));
46
- var commander_1 = require("commander");
47
- var bonjour_1 = __importDefault(require("bonjour"));
48
- var Destination_1 = __importDefault(require("./Destination"));
49
- var ScanJobSettings_1 = __importDefault(require("./ScanJobSettings"));
50
- var HPApi_1 = __importDefault(require("./HPApi"));
51
- var JpegUtil_1 = __importDefault(require("./JpegUtil"));
52
- var PathHelper_1 = __importDefault(require("./PathHelper"));
53
- var ScanContent_1 = require("./ScanContent");
54
- var program = new commander_1.Command();
55
- function delay(t) {
56
- return new Promise(function (resolve) {
57
- setTimeout(resolve, t);
58
- });
59
- }
60
- function waitForScanEvent(resourceURI, afterEtag) {
61
- if (afterEtag === void 0) { afterEtag = null; }
62
- return __awaiter(this, void 0, void 0, function () {
63
- var eventTable, acceptedScanEvent, currentEtag;
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
66
- case 0:
67
- console.log("Start listening for new ScanEvent");
68
- return [4 /*yield*/, HPApi_1.default.getEvents(afterEtag !== null && afterEtag !== void 0 ? afterEtag : "")];
69
- case 1:
70
- eventTable = _a.sent();
71
- acceptedScanEvent = null;
72
- currentEtag = eventTable.etag;
73
- _a.label = 2;
74
- case 2:
75
- if (!(acceptedScanEvent == null)) return [3 /*break*/, 4];
76
- return [4 /*yield*/, HPApi_1.default.getEvents(currentEtag, 1200)];
77
- case 3:
78
- eventTable = _a.sent();
79
- currentEtag = eventTable.etag;
80
- acceptedScanEvent = eventTable.eventTable.events.find(function (ev) {
81
- return ev.isScanEvent &&
82
- ev.destinationURI &&
83
- ev.destinationURI.indexOf(resourceURI) >= 0;
84
- });
85
- return [3 /*break*/, 2];
86
- case 4: return [2 /*return*/, acceptedScanEvent];
87
- }
88
- });
89
- });
90
- }
91
- function waitPrinterUntilItIsReadyToUploadOrCompleted(jobUrl) {
92
- return __awaiter(this, void 0, void 0, function () {
93
- var job, isReadyToUpload;
94
- return __generator(this, function (_a) {
95
- switch (_a.label) {
96
- case 0:
97
- job = null;
98
- isReadyToUpload = false;
99
- _a.label = 1;
100
- case 1: return [4 /*yield*/, HPApi_1.default.getJob(jobUrl)];
101
- case 2:
102
- job = _a.sent();
103
- if (job.jobState === "Canceled") {
104
- return [2 /*return*/, job];
105
- }
106
- else if (job.pageState === "ReadyToUpload" ||
107
- job.jobState === "Completed") {
108
- isReadyToUpload = true;
109
- }
110
- else if (job.jobState == "Processing") {
111
- isReadyToUpload = false;
112
- }
113
- else {
114
- console.log("Unknown jobState: ".concat(job.jobState));
115
- }
116
- return [4 /*yield*/, delay(300)];
117
- case 3:
118
- _a.sent();
119
- _a.label = 4;
120
- case 4:
121
- if (!isReadyToUpload) return [3 /*break*/, 1];
122
- _a.label = 5;
123
- case 5: return [2 /*return*/, job];
124
- }
125
- });
126
- });
127
- }
128
- function register() {
129
- return __awaiter(this, void 0, void 0, function () {
130
- var destination, hostname, toComp, walkupScanDestinations, destinations, walkupScanDestinations, destinations, resourceURI;
131
- return __generator(this, function (_a) {
132
- switch (_a.label) {
133
- case 0:
134
- hostname = os_1.default.hostname();
135
- return [4 /*yield*/, HPApi_1.default.getWalkupScanToCompCaps()];
136
- case 1:
137
- toComp = _a.sent();
138
- if (!toComp) return [3 /*break*/, 3];
139
- return [4 /*yield*/, HPApi_1.default.getWalkupScanToCompDestinations()];
140
- case 2:
141
- walkupScanDestinations = _a.sent();
142
- destinations = walkupScanDestinations.destinations;
143
- console.log("Host destinations fetched:", destinations.map(function (d) { return d.name; }).join(", "));
144
- destination = destinations.find(function (x) { return x.name === hostname; });
145
- return [3 /*break*/, 5];
146
- case 3: return [4 /*yield*/, HPApi_1.default.getWalkupScanDestinations()];
147
- case 4:
148
- walkupScanDestinations = _a.sent();
149
- destinations = walkupScanDestinations.destinations;
150
- console.log("Host destinations fetched:", destinations.map(function (d) { return d.name; }).join(", "));
151
- destination = destinations.find(function (x) { return x.name === hostname; });
152
- _a.label = 5;
153
- case 5:
154
- if (!destination) return [3 /*break*/, 6];
155
- console.log("Re-using existing destination: ".concat(hostname, " - ").concat(destination.resourceURI));
156
- resourceURI = destination.resourceURI;
157
- return [3 /*break*/, 8];
158
- case 6: return [4 /*yield*/, HPApi_1.default.registerDestination(new Destination_1.default(hostname, hostname, toComp), toComp)];
159
- case 7:
160
- resourceURI = _a.sent();
161
- console.log("New Destination registered: ".concat(hostname, " - ").concat(resourceURI));
162
- _a.label = 8;
163
- case 8: return [2 /*return*/, resourceURI];
164
- }
165
- });
166
- });
167
- }
168
- function TryGetDestination(event) {
169
- return __awaiter(this, void 0, void 0, function () {
170
- var destination, i, destinationURI, shortcut;
171
- return __generator(this, function (_a) {
172
- switch (_a.label) {
173
- case 0:
174
- destination = null;
175
- i = 0;
176
- _a.label = 1;
177
- case 1:
178
- if (!(i < 20)) return [3 /*break*/, 7];
179
- destinationURI = event.destinationURI;
180
- if (!destinationURI) return [3 /*break*/, 3];
181
- return [4 /*yield*/, HPApi_1.default.getDestination(destinationURI)];
182
- case 2:
183
- destination = _a.sent();
184
- shortcut = destination.shortcut;
185
- if (shortcut !== "") {
186
- return [2 /*return*/, destination];
187
- }
188
- return [3 /*break*/, 4];
189
- case 3:
190
- console.log("No destination URI found");
191
- _a.label = 4;
192
- case 4:
193
- console.log("No shortcut yet available, attempt: ".concat(i + 1, "/20"));
194
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
195
- case 5:
196
- _a.sent(); //wait 1s
197
- _a.label = 6;
198
- case 6:
199
- i++;
200
- return [3 /*break*/, 1];
201
- case 7:
202
- console.log("Failing to detect destination shortcut");
203
- console.log(JSON.stringify(destination));
204
- return [2 /*return*/, null];
205
- }
206
- });
207
- });
208
- }
209
- function fixJpegSize(filePath) {
210
- return __awaiter(this, void 0, void 0, function () {
211
- var buffer, height;
212
- return __generator(this, function (_a) {
213
- switch (_a.label) {
214
- case 0: return [4 /*yield*/, promises_1.default.readFile(filePath)];
215
- case 1:
216
- buffer = _a.sent();
217
- height = JpegUtil_1.default.fixSizeWithDNL(buffer);
218
- if (!(height != null)) return [3 /*break*/, 3];
219
- // rewrite the fixed file
220
- return [4 /*yield*/, promises_1.default.writeFile(filePath, buffer)];
221
- case 2:
222
- // rewrite the fixed file
223
- _a.sent();
224
- return [2 /*return*/, height];
225
- case 3: return [2 /*return*/, null];
226
- }
227
- });
228
- });
229
- }
230
- function createScanPage(job, currentPageNumber, filePath, sizeFixed) {
231
- var height = sizeFixed !== null && sizeFixed !== void 0 ? sizeFixed : job.imageHeight;
232
- return {
233
- path: filePath,
234
- pageNumber: currentPageNumber,
235
- width: job.imageWidth,
236
- height: height,
237
- xResolution: job.xResolution,
238
- yResolution: job.yResolution,
239
- };
240
- }
241
- function handleProcessingState(job, inputSource, folder, scanCount, currentPageNumber) {
242
- return __awaiter(this, void 0, void 0, function () {
243
- var destinationFilePath, filePath, sizeFixed;
244
- return __generator(this, function (_a) {
245
- switch (_a.label) {
246
- case 0:
247
- if (!(job.pageState == "ReadyToUpload" &&
248
- job.binaryURL != null &&
249
- job.currentPageNumber != null)) return [3 /*break*/, 4];
250
- console.log("Ready to download page job page ".concat(job.currentPageNumber, " at:"), job.binaryURL);
251
- destinationFilePath = PathHelper_1.default.getFileForPage(folder, scanCount, currentPageNumber, program.opts().pattern, "jpg");
252
- return [4 /*yield*/, HPApi_1.default.downloadPage(job.binaryURL, destinationFilePath)];
253
- case 1:
254
- filePath = _a.sent();
255
- console.log("Page downloaded to:", filePath);
256
- sizeFixed = null;
257
- if (!(inputSource == "Adf")) return [3 /*break*/, 3];
258
- return [4 /*yield*/, fixJpegSize(filePath)];
259
- case 2:
260
- sizeFixed = _a.sent();
261
- if (sizeFixed == null) {
262
- console.log("File size has not been fixed, DNF may not have been found and approximate height is: ".concat(job.imageHeight));
263
- }
264
- _a.label = 3;
265
- case 3: return [2 /*return*/, createScanPage(job, currentPageNumber, filePath, sizeFixed)];
266
- case 4:
267
- console.log("Unknown pageState: ".concat(job.pageState));
268
- return [4 /*yield*/, delay(200)];
269
- case 5:
270
- _a.sent();
271
- return [2 /*return*/, null];
272
- }
273
- });
274
- });
275
- }
276
- function waitScanRequest(compEventURI) {
277
- return __awaiter(this, void 0, void 0, function () {
278
- var waitMax, i, walkupScanToCompEvent, message;
279
- return __generator(this, function (_a) {
280
- switch (_a.label) {
281
- case 0:
282
- waitMax = 50;
283
- i = 0;
284
- _a.label = 1;
285
- case 1:
286
- if (!(i < waitMax)) return [3 /*break*/, 5];
287
- return [4 /*yield*/, HPApi_1.default.getWalkupScanToCompEvent(compEventURI)];
288
- case 2:
289
- walkupScanToCompEvent = _a.sent();
290
- message = walkupScanToCompEvent.eventType;
291
- if (message === "HostSelected") {
292
- // this ok to wait
293
- }
294
- else if (message === "ScanRequested") {
295
- return [3 /*break*/, 5];
296
- }
297
- else if (message === "ScanNewPageRequested") {
298
- return [3 /*break*/, 5];
299
- }
300
- else if (message === "ScanPagesComplete") {
301
- console.log("no more page to scan, scan is finished");
302
- return [2 /*return*/, false];
303
- }
304
- else {
305
- console.log("Unknown eventType: ".concat(message));
306
- return [2 /*return*/, false];
307
- }
308
- console.log("Waiting user input: ".concat(i + 1, "/").concat(waitMax));
309
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
310
- case 3:
311
- _a.sent(); //wait 1s
312
- _a.label = 4;
313
- case 4:
314
- i++;
315
- return [3 /*break*/, 1];
316
- case 5: return [2 /*return*/, true];
317
- }
318
- });
319
- });
320
- }
321
- function executeScanJob(scanJobSettings, inputSource, folder, scanCount, scanJobContent) {
322
- return __awaiter(this, void 0, void 0, function () {
323
- var jobUrl, job, page;
324
- return __generator(this, function (_a) {
325
- switch (_a.label) {
326
- case 0: return [4 /*yield*/, HPApi_1.default.postJob(scanJobSettings)];
327
- case 1:
328
- jobUrl = _a.sent();
329
- console.log("New job created:", jobUrl);
330
- return [4 /*yield*/, HPApi_1.default.getJob(jobUrl)];
331
- case 2:
332
- job = _a.sent();
333
- _a.label = 3;
334
- case 3:
335
- if (!(job.jobState !== "Completed")) return [3 /*break*/, 10];
336
- return [4 /*yield*/, waitPrinterUntilItIsReadyToUploadOrCompleted(jobUrl)];
337
- case 4:
338
- job = _a.sent();
339
- if (job.jobState == "Completed") {
340
- return [3 /*break*/, 3];
341
- }
342
- if (!(job.jobState === "Processing")) return [3 /*break*/, 6];
343
- return [4 /*yield*/, handleProcessingState(job, inputSource, folder, scanCount, scanJobContent.elements.length + 1)];
344
- case 5:
345
- page = _a.sent();
346
- if (page != null) {
347
- scanJobContent.elements.push(page);
348
- }
349
- return [3 /*break*/, 9];
350
- case 6:
351
- if (!(job.jobState === "Canceled")) return [3 /*break*/, 7];
352
- console.log("Job cancelled by device");
353
- return [3 /*break*/, 10];
354
- case 7:
355
- console.log("Unhandled jobState: ".concat(job.jobState));
356
- return [4 /*yield*/, delay(200)];
357
- case 8:
358
- _a.sent();
359
- _a.label = 9;
360
- case 9: return [3 /*break*/, 3];
361
- case 10:
362
- console.log("Job state: ".concat(job.jobState, ", totalPages: ").concat(job.totalPageNumber, ":"));
363
- return [2 /*return*/];
364
- }
365
- });
366
- });
367
- }
368
- function waitScanNewPageRequest(compEventURI) {
369
- return __awaiter(this, void 0, void 0, function () {
370
- var startNewScanJob, wait, walkupScanToCompEvent, message;
371
- return __generator(this, function (_a) {
372
- switch (_a.label) {
373
- case 0:
374
- startNewScanJob = false;
375
- wait = true;
376
- _a.label = 1;
377
- case 1:
378
- if (!wait) return [3 /*break*/, 4];
379
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
380
- case 2:
381
- _a.sent(); //wait 1s
382
- return [4 /*yield*/, HPApi_1.default.getWalkupScanToCompEvent(compEventURI)];
383
- case 3:
384
- walkupScanToCompEvent = _a.sent();
385
- message = walkupScanToCompEvent.eventType;
386
- if (message === "ScanNewPageRequested") {
387
- startNewScanJob = true;
388
- wait = false;
389
- }
390
- else if (message === "ScanPagesComplete") {
391
- wait = false;
392
- }
393
- else if (message === "ScanRequested") {
394
- // continue waiting
395
- }
396
- else {
397
- wait = false;
398
- console.log("Unknown eventType: ".concat(message));
399
- }
400
- return [3 /*break*/, 1];
401
- case 4: return [2 /*return*/, startNewScanJob];
402
- }
403
- });
404
- });
405
- }
406
- function executeScanJobs(scanJobSettings, inputSource, folder, scanCount, scanJobContent, firstEvent) {
407
- return __awaiter(this, void 0, void 0, function () {
408
- var lastEvent, startNewScanJob;
409
- return __generator(this, function (_a) {
410
- switch (_a.label) {
411
- case 0: return [4 /*yield*/, executeScanJob(scanJobSettings, inputSource, folder, scanCount, scanJobContent)];
412
- case 1:
413
- _a.sent();
414
- lastEvent = firstEvent;
415
- if (!(lastEvent.compEventURI &&
416
- inputSource !== "Adf" &&
417
- lastEvent.destinationURI)) return [3 /*break*/, 8];
418
- return [4 /*yield*/, waitForScanEvent(lastEvent.destinationURI, lastEvent.agingStamp)];
419
- case 2:
420
- lastEvent = _a.sent();
421
- if (!lastEvent.compEventURI) {
422
- return [2 /*return*/];
423
- }
424
- return [4 /*yield*/, waitScanNewPageRequest(lastEvent.compEventURI)];
425
- case 3:
426
- startNewScanJob = _a.sent();
427
- _a.label = 4;
428
- case 4:
429
- if (!startNewScanJob) return [3 /*break*/, 8];
430
- return [4 /*yield*/, executeScanJob(scanJobSettings, inputSource, folder, scanCount, scanJobContent)];
431
- case 5:
432
- _a.sent();
433
- if (!lastEvent.destinationURI) {
434
- return [3 /*break*/, 8];
435
- }
436
- return [4 /*yield*/, waitForScanEvent(lastEvent.destinationURI, lastEvent.agingStamp)];
437
- case 6:
438
- lastEvent = _a.sent();
439
- if (!lastEvent.compEventURI) {
440
- return [2 /*return*/];
441
- }
442
- return [4 /*yield*/, waitScanNewPageRequest(lastEvent.compEventURI)];
443
- case 7:
444
- startNewScanJob = _a.sent();
445
- return [3 /*break*/, 4];
446
- case 8: return [2 /*return*/];
447
- }
448
- });
449
- });
450
- }
451
- function mergeToPdf(folder, scanCount, scanJobContent) {
452
- return __awaiter(this, void 0, void 0, function () {
453
- var pdfFilePath;
454
- return __generator(this, function (_a) {
455
- switch (_a.label) {
456
- case 0:
457
- pdfFilePath = PathHelper_1.default.getFileForScan(folder, scanCount, program.opts().pattern, "pdf");
458
- return [4 /*yield*/, (0, ScanContent_1.createPdfFrom)(scanJobContent, pdfFilePath)];
459
- case 1:
460
- _a.sent();
461
- scanJobContent.elements.forEach(function (e) { return promises_1.default.unlink(e.path); });
462
- return [2 /*return*/, pdfFilePath];
463
- }
464
- });
465
- });
466
- }
467
- function displayPdfScan(pdfFilePath, scanJobContent) {
468
- console.log("The following page(s) have been rendered inside '".concat(pdfFilePath, "': "));
469
- scanJobContent.elements.forEach(function (e) {
470
- return console.log("\t- page ".concat(e.pageNumber.toString().padStart(3, " "), " - ").concat(e.width, "x").concat(e.height));
471
- });
472
- }
473
- function displayJpegScan(scanJobContent) {
474
- scanJobContent.elements.forEach(function (e) {
475
- return console.log("\t- page ".concat(e.pageNumber.toString().padStart(3, " "), " - ").concat(e.width, "x").concat(e.height, " - ").concat(e.path));
476
- });
477
- }
478
- function saveScan(event, folder, scanCount) {
479
- return __awaiter(this, void 0, void 0, function () {
480
- var proceedToScan, destination, contentType, toPdf, scanStatus, inputSource, scanJobSettings, scanJobContent, pdfFilePath;
481
- return __generator(this, function (_a) {
482
- switch (_a.label) {
483
- case 0:
484
- if (!event.compEventURI) return [3 /*break*/, 2];
485
- return [4 /*yield*/, waitScanRequest(event.compEventURI)];
486
- case 1:
487
- proceedToScan = _a.sent();
488
- if (!proceedToScan) {
489
- return [2 /*return*/];
490
- }
491
- _a.label = 2;
492
- case 2: return [4 /*yield*/, TryGetDestination(event)];
493
- case 3:
494
- destination = _a.sent();
495
- if (!destination) {
496
- console.log("No shortcut selected!");
497
- return [2 /*return*/];
498
- }
499
- console.log("Selected shortcut: " + destination.shortcut);
500
- contentType = destination.getContentType();
501
- toPdf = destination.shortcut === "SavePDF" || destination.shortcut === "EmailPDF";
502
- return [4 /*yield*/, HPApi_1.default.getScanStatus()];
503
- case 4:
504
- scanStatus = _a.sent();
505
- console.log("Afd is : " + scanStatus.adfState);
506
- inputSource = scanStatus.getInputSource();
507
- scanJobSettings = new ScanJobSettings_1.default(inputSource, contentType);
508
- scanJobContent = { elements: [] };
509
- return [4 /*yield*/, executeScanJobs(scanJobSettings, inputSource, folder, scanCount, scanJobContent, event)];
510
- case 5:
511
- _a.sent();
512
- console.log("Scan of page(s) completed totalPages: ".concat(scanJobContent.elements.length, ":"));
513
- if (!toPdf) return [3 /*break*/, 7];
514
- return [4 /*yield*/, mergeToPdf(folder, scanCount, scanJobContent)];
515
- case 6:
516
- pdfFilePath = _a.sent();
517
- displayPdfScan(pdfFilePath, scanJobContent);
518
- return [3 /*break*/, 8];
519
- case 7:
520
- displayJpegScan(scanJobContent);
521
- _a.label = 8;
522
- case 8: return [2 /*return*/];
523
- }
524
- });
525
- });
8
+ const os_1 = __importDefault(require("os"));
9
+ const commander_1 = require("commander");
10
+ const bonjour_1 = __importDefault(require("bonjour"));
11
+ const config_1 = __importDefault(require("config"));
12
+ const HPApi_1 = __importDefault(require("./HPApi"));
13
+ const PathHelper_1 = __importDefault(require("./PathHelper"));
14
+ const delay_1 = require("./delay");
15
+ const readDeviceCapabilities_1 = require("./readDeviceCapabilities");
16
+ const listening_1 = require("./listening");
17
+ const scanProcessing_1 = require("./scanProcessing");
18
+ let iteration = 0;
19
+ async function listenCmd(registrationConfig, scanConfig, deviceUpPollingInterval) {
20
+ // first make sure the device is reachable
21
+ await HPApi_1.default.waitDeviceUp(deviceUpPollingInterval);
22
+ let deviceUp = true;
23
+ const folder = await PathHelper_1.default.getOutputFolder(scanConfig.directoryConfig.directory);
24
+ console.log(`Target folder: ${folder}`);
25
+ const tempFolder = await PathHelper_1.default.getOutputFolder(scanConfig.directoryConfig.tempDirectory);
26
+ console.log(`Temp folder: ${tempFolder}`);
27
+ const deviceCapabilities = await (0, readDeviceCapabilities_1.readDeviceCapabilities)();
28
+ let scanCount = 0;
29
+ let keepActive = true;
30
+ let errorCount = 0;
31
+ while (keepActive) {
32
+ console.log(`Running iteration: ${iteration} - errorCount: ${errorCount}`);
33
+ try {
34
+ const event = await (0, listening_1.waitScanEvent)(deviceCapabilities, registrationConfig);
35
+ scanCount++;
36
+ console.log(`Scan event captured, saving scan #${scanCount}`);
37
+ await (0, scanProcessing_1.saveScan)(event, folder, tempFolder, scanCount, deviceCapabilities, scanConfig);
38
+ }
39
+ catch (e) {
40
+ console.log(e);
41
+ if (await HPApi_1.default.isAlive()) {
42
+ errorCount++;
43
+ }
44
+ else {
45
+ deviceUp = false;
46
+ }
47
+ }
48
+ if (errorCount === 50) {
49
+ keepActive = false;
50
+ }
51
+ if (!deviceUp) {
52
+ await HPApi_1.default.waitDeviceUp(deviceUpPollingInterval);
53
+ }
54
+ else {
55
+ await (0, delay_1.delay)(1000);
56
+ }
57
+ }
526
58
  }
527
- var iteration = 0;
528
- function init() {
529
- return __awaiter(this, void 0, void 0, function () {
530
- var folder, scanCount, keepActive, errorCount, resourceURI, event_1, e_1;
531
- return __generator(this, function (_a) {
532
- switch (_a.label) {
533
- case 0: return [4 /*yield*/, PathHelper_1.default.getOutputFolder(program.opts().directory)];
534
- case 1:
535
- folder = _a.sent();
536
- console.log("Target folder: ".concat(folder));
537
- scanCount = 0;
538
- keepActive = true;
539
- errorCount = 0;
540
- _a.label = 2;
541
- case 2:
542
- if (!keepActive) return [3 /*break*/, 10];
543
- console.log("Running iteration: ".concat(iteration, " - errorCount: ").concat(errorCount));
544
- _a.label = 3;
545
- case 3:
546
- _a.trys.push([3, 7, , 8]);
547
- return [4 /*yield*/, register()];
548
- case 4:
549
- resourceURI = _a.sent();
550
- console.log("Waiting scan event for:", resourceURI);
551
- return [4 /*yield*/, waitForScanEvent(resourceURI)];
552
- case 5:
553
- event_1 = _a.sent();
554
- scanCount++;
555
- console.log("Scan event captured, saving scan #".concat(scanCount));
556
- return [4 /*yield*/, saveScan(event_1, folder, scanCount)];
557
- case 6:
558
- _a.sent();
559
- return [3 /*break*/, 8];
560
- case 7:
561
- e_1 = _a.sent();
562
- errorCount++;
563
- console.error(e_1);
564
- console.log(e_1);
565
- return [3 /*break*/, 8];
566
- case 8:
567
- if (errorCount === 50) {
568
- keepActive = false;
569
- }
570
- return [4 /*yield*/, delay(1000)];
571
- case 9:
572
- _a.sent();
573
- return [3 /*break*/, 2];
574
- case 10: return [2 /*return*/];
575
- }
576
- });
577
- });
59
+ async function adfAutoscanCmd(adfAutoScanConfig, deviceUpPollingInterval) {
60
+ // first make sure the device is reachable
61
+ await HPApi_1.default.waitDeviceUp(deviceUpPollingInterval);
62
+ let deviceUp = true;
63
+ const folder = await PathHelper_1.default.getOutputFolder(adfAutoScanConfig.directoryConfig.directory);
64
+ console.log(`Target folder: ${folder}`);
65
+ const tempFolder = await PathHelper_1.default.getOutputFolder(adfAutoScanConfig.directoryConfig.tempDirectory);
66
+ console.log(`Temp folder: ${tempFolder}`);
67
+ let scanCount = 0;
68
+ let keepActive = true;
69
+ let errorCount = 0;
70
+ while (keepActive) {
71
+ console.log(`Running iteration: ${iteration} - errorCount: ${errorCount}`);
72
+ try {
73
+ await (0, scanProcessing_1.waitAdfLoaded)(adfAutoScanConfig.pollingInterval, adfAutoScanConfig.startScanDelay);
74
+ scanCount++;
75
+ console.log(`Scan event captured, saving scan #${scanCount}`);
76
+ await (0, scanProcessing_1.scanFromAdf)(scanCount, folder, tempFolder, adfAutoScanConfig);
77
+ }
78
+ catch (e) {
79
+ console.log(e);
80
+ if (await HPApi_1.default.isAlive()) {
81
+ errorCount++;
82
+ }
83
+ else {
84
+ deviceUp = false;
85
+ }
86
+ }
87
+ if (errorCount === 50) {
88
+ keepActive = false;
89
+ }
90
+ if (!deviceUp) {
91
+ await HPApi_1.default.waitDeviceUp(deviceUpPollingInterval);
92
+ }
93
+ else {
94
+ await (0, delay_1.delay)(1000);
95
+ }
96
+ }
578
97
  }
579
- function findOfficejetIp() {
580
- return new Promise(function (resolve) {
581
- var bonjour = (0, bonjour_1.default)();
582
- console.log("Searching printer...");
583
- var browser = bonjour.find({
98
+ async function clearRegistrationsCmd(cmd) {
99
+ const parentOption = cmd.parent.opts();
100
+ const ip = await getDeviceIp(parentOption);
101
+ HPApi_1.default.setDeviceIP(ip);
102
+ const isDebug = getIsDebug(parentOption);
103
+ HPApi_1.default.setDebug(isDebug);
104
+ await (0, listening_1.clearRegistrations)();
105
+ }
106
+ function findOfficejetIp(deviceNamePrefix) {
107
+ return new Promise((resolve) => {
108
+ const bonjour = (0, bonjour_1.default)();
109
+ console.log("Searching device...");
110
+ let browser = bonjour.find({
584
111
  type: "http",
585
- }, function (service) {
112
+ }, (service) => {
586
113
  console.log(".");
587
- if (service.name.startsWith(program.opts().name) &&
114
+ if (service.name.startsWith(deviceNamePrefix) &&
588
115
  service.port === 80 &&
589
116
  service.type === "http" &&
590
117
  service.addresses != null) {
591
118
  browser.stop();
592
119
  bonjour.destroy();
593
- console.log("Found: ".concat(service.name));
120
+ console.log(`Found: ${service.name}`);
594
121
  resolve(service.addresses[0]);
595
122
  }
596
123
  });
597
124
  browser.start();
598
125
  });
599
126
  }
600
- function main() {
601
- return __awaiter(this, void 0, void 0, function () {
602
- var ip, debug;
603
- return __generator(this, function (_a) {
604
- switch (_a.label) {
605
- case 0:
606
- program.option("-ip, --address <ip>", "IP address of the printer (this overrides -p)");
607
- program.option("-n, --name <name>", "Name of the printer for service discovery", "HP Smart Tank Plus 570 series"); //or i.e. 'Deskjet 3520 series'
608
- program.option("-d, --directory <dir>", "Directory where scans are saved (defaults to /tmp/scan-to-pc<random>)");
609
- program.option("-p, --pattern <pattern>", 'Pattern for filename (i.e. "scan"_dd.mm.yyyy_hh:MM:ss, without this its scanPage<number>)');
610
- program.option("-D, --debug", "Enable debug");
611
- program.parse(process.argv);
612
- ip = program.opts().address || "192.168.1.53";
613
- if (!!ip) return [3 /*break*/, 2];
614
- return [4 /*yield*/, findOfficejetIp()];
615
- case 1:
616
- ip = _a.sent();
617
- _a.label = 2;
618
- case 2:
619
- debug = program.opts().debug != null;
620
- HPApi_1.default.setDebug(debug);
621
- HPApi_1.default.setPrinterIP(ip);
622
- return [4 /*yield*/, init()];
623
- case 3:
624
- _a.sent();
625
- return [2 /*return*/];
626
- }
627
- });
628
- });
127
+ function getConfig(name) {
128
+ return config_1.default.has(name) ? config_1.default.get(name) : undefined;
129
+ }
130
+ function setupScanParameters(command) {
131
+ command.option("-d, --directory <dir>", "Directory where scans are saved (default: /tmp/scan-to-pc<random>)");
132
+ command.option("-t, --temp-directory <dir>", "Temp directory used for processing (default: /tmp/scan-to-pc<random>)");
133
+ command.option("-p, --pattern <pattern>", 'Pattern for filename (i.e. "scan"_dd.mm.yyyy_hh:MM:ss, without this its scanPage<number>)');
134
+ command.option("-r, --resolution <dpi>", "Resolution in DPI of the scans (default: 200)");
135
+ return command;
136
+ }
137
+ function setupParameterOpts(command) {
138
+ command.option("-ip, --address <ip>", "IP address of the device (this overrides -p)");
139
+ command.option("--device-up-polling-interval <deviceUpPollingInterval>", "Device up polling interval in milliseconds", parseFloat);
140
+ command.option("-n, --name <name>", "Name of the device for service discovery"); // i.e. 'Deskjet 3520 series'
141
+ command.option("-D, --debug", "Enable debug");
142
+ return command;
143
+ }
144
+ async function getDeviceIp(options) {
145
+ let ip = options.address || getConfig("ip");
146
+ if (!ip) {
147
+ const name = options.name || getConfig("name");
148
+ ip = await findOfficejetIp(name || "HP Smart Tank Plus 570 series");
149
+ }
150
+ console.log(`Using device ip: ${ip}`);
151
+ return ip;
629
152
  }
630
- main();
153
+ function getIsDebug(options) {
154
+ const debug = options.debug != null ? true : getConfig("debug") || false;
155
+ if (debug) {
156
+ console.log(`IsDebug: ${debug}`);
157
+ }
158
+ return debug;
159
+ }
160
+ function getScanConfiguration(parentOption) {
161
+ const directoryConfig = {
162
+ directory: parentOption.directory || getConfig("directory"),
163
+ tempDirectory: parentOption.tempDirectory || getConfig("tempDirectory"),
164
+ filePattern: parentOption.pattern || getConfig("pattern"),
165
+ };
166
+ const scanConfig = {
167
+ resolution: parseInt(parentOption.resolution || getConfig("resolution") || 200, 10),
168
+ directoryConfig,
169
+ };
170
+ return scanConfig;
171
+ }
172
+ function getDeviceUpPollingInterval(parentOption) {
173
+ return (parentOption.deviceUpPollingInterval ||
174
+ getConfig("deviceUpPollingInterval") ||
175
+ 1000);
176
+ }
177
+ async function main() {
178
+ setupParameterOpts(commander_1.program);
179
+ const cmdListen = commander_1.program.createCommand("listen");
180
+ setupScanParameters(cmdListen)
181
+ .description("Listen the device for new scan job to save to this target")
182
+ .option("-l, --label <label>", "The label to display on the device (the default is the hostname)")
183
+ .action(async (options, cmd) => {
184
+ const parentOption = cmd.parent.opts();
185
+ const ip = await getDeviceIp(parentOption);
186
+ HPApi_1.default.setDeviceIP(ip);
187
+ const isDebug = getIsDebug(parentOption);
188
+ HPApi_1.default.setDebug(isDebug);
189
+ const registrationConfig = {
190
+ label: options.label || getConfig("label") || os_1.default.hostname(),
191
+ };
192
+ const deviceUpPollingInterval = getDeviceUpPollingInterval(parentOption);
193
+ const scanConfig = getScanConfiguration(parentOption);
194
+ await listenCmd(registrationConfig, scanConfig, deviceUpPollingInterval);
195
+ });
196
+ commander_1.program.addCommand(cmdListen, { isDefault: true });
197
+ const cmdAdfAutoscan = commander_1.program.createCommand("adf-autoscan");
198
+ setupScanParameters(cmdAdfAutoscan)
199
+ .addOption(new commander_1.Option("--duplex", "If specified, the scan will be in duplex"))
200
+ .addOption(new commander_1.Option("--pdf", "If specified, the scan result will be a pdf document, the default is multiple jpeg files"))
201
+ .addOption(new commander_1.Option("--pollingInterval <pollingInterval>", "Time interval in millisecond between each lookup for content in the automatic document feeder"))
202
+ .description("Automatically trigger a new scan job to this target once paper is detected in the automatic document feeder (adf)")
203
+ .addOption(new commander_1.Option("--start-scan-delay <startScanDelay>", "Once document are detected to be in the adf, this specify the wait delay in millisecond before triggering the scan"))
204
+ .description("Automatically trigger a new scan job to this target once paper is detected in the automatic document feeder (adf)")
205
+ .action(async (options, cmd) => {
206
+ const parentOption = cmd.parent.opts();
207
+ const ip = await getDeviceIp(parentOption);
208
+ HPApi_1.default.setDeviceIP(ip);
209
+ const isDebug = getIsDebug(parentOption);
210
+ HPApi_1.default.setDebug(isDebug);
211
+ const deviceUpPollingInterval = getDeviceUpPollingInterval(parentOption);
212
+ const scanConfig = getScanConfiguration(parentOption);
213
+ const adfScanConfig = {
214
+ ...scanConfig,
215
+ isDuplex: options.isDuplex || getConfig("autoscan_duplex") || false,
216
+ generatePdf: options.pdf || getConfig("autoscan_pdf") || false,
217
+ pollingInterval: options.pollingInterval || getConfig("autoscan_pollingInterval") || 1000,
218
+ startScanDelay: options.startScanDelay || getConfig("autoscan_startScanDelay") || 5000,
219
+ };
220
+ await adfAutoscanCmd(adfScanConfig, deviceUpPollingInterval);
221
+ });
222
+ commander_1.program.addCommand(cmdAdfAutoscan);
223
+ const cmdClearRegistrations = commander_1.program.createCommand("clear-registrations");
224
+ cmdClearRegistrations
225
+ .description("Clear the list or registered target on the device")
226
+ .action(async (options, cmd) => {
227
+ await clearRegistrationsCmd(cmd);
228
+ });
229
+ commander_1.program.addCommand(cmdClearRegistrations);
230
+ await commander_1.program.parseAsync(process.argv);
231
+ }
232
+ main().catch((err) => console.log(err));
631
233
  //# sourceMappingURL=index.js.map