enhanced-printer 1.0.2 → 1.0.3
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/lib/job-name-mapper.d.ts +16 -0
- package/lib/job-name-mapper.js +62 -0
- package/lib/job-tracker.js +19 -12
- package/lib/print-manager.js +7 -2
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Job name mapping to track custom names
|
|
3
|
+
* Maps job ID to custom job name provided by user
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Store custom job name mapping
|
|
7
|
+
*/
|
|
8
|
+
export declare function storeJobName(printerName: string, jobId: number, customName: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Get custom job name for a job
|
|
11
|
+
*/
|
|
12
|
+
export declare function getCustomJobName(printerName: string, jobId: number): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Clear all job name mappings
|
|
15
|
+
*/
|
|
16
|
+
export declare function clearJobNames(): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Job name mapping to track custom names
|
|
4
|
+
* Maps job ID to custom job name provided by user
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.storeJobName = storeJobName;
|
|
8
|
+
exports.getCustomJobName = getCustomJobName;
|
|
9
|
+
exports.clearJobNames = clearJobNames;
|
|
10
|
+
// In-memory storage for job name mappings
|
|
11
|
+
const jobNameMap = new Map();
|
|
12
|
+
// Max age for mappings (24 hours)
|
|
13
|
+
const MAX_MAPPING_AGE = 24 * 60 * 60 * 1000;
|
|
14
|
+
/**
|
|
15
|
+
* Store custom job name mapping
|
|
16
|
+
*/
|
|
17
|
+
function storeJobName(printerName, jobId, customName) {
|
|
18
|
+
const key = `${printerName}_${jobId}`;
|
|
19
|
+
jobNameMap.set(key, {
|
|
20
|
+
jobId,
|
|
21
|
+
customName,
|
|
22
|
+
printerName,
|
|
23
|
+
timestamp: Date.now()
|
|
24
|
+
});
|
|
25
|
+
// Clean old entries
|
|
26
|
+
cleanOldMappings();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get custom job name for a job
|
|
30
|
+
*/
|
|
31
|
+
function getCustomJobName(printerName, jobId) {
|
|
32
|
+
const key = `${printerName}_${jobId}`;
|
|
33
|
+
const mapping = jobNameMap.get(key);
|
|
34
|
+
if (!mapping) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
// Check if mapping is too old
|
|
38
|
+
if (Date.now() - mapping.timestamp > MAX_MAPPING_AGE) {
|
|
39
|
+
jobNameMap.delete(key);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return mapping.customName;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Clean mappings older than MAX_MAPPING_AGE
|
|
46
|
+
*/
|
|
47
|
+
function cleanOldMappings() {
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
const keysToDelete = [];
|
|
50
|
+
jobNameMap.forEach((mapping, key) => {
|
|
51
|
+
if (now - mapping.timestamp > MAX_MAPPING_AGE) {
|
|
52
|
+
keysToDelete.push(key);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
keysToDelete.forEach(key => jobNameMap.delete(key));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Clear all job name mappings
|
|
59
|
+
*/
|
|
60
|
+
function clearJobNames() {
|
|
61
|
+
jobNameMap.clear();
|
|
62
|
+
}
|
package/lib/job-tracker.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.getJobIdByName = getJobIdByName;
|
|
|
4
4
|
exports.getJobInfo = getJobInfo;
|
|
5
5
|
exports.getAllJobs = getAllJobs;
|
|
6
6
|
const child_process_1 = require("child_process");
|
|
7
|
+
const job_name_mapper_1 = require("./job-name-mapper");
|
|
7
8
|
/**
|
|
8
9
|
* Retrieves job ID by document name using PowerShell
|
|
9
10
|
*/
|
|
@@ -36,10 +37,12 @@ async function getJobInfo(printerName, jobId) {
|
|
|
36
37
|
if (!result || !result.Id) {
|
|
37
38
|
return null;
|
|
38
39
|
}
|
|
40
|
+
// Get custom job name from mapper
|
|
41
|
+
const customName = (0, job_name_mapper_1.getCustomJobName)(printerName, result.Id);
|
|
39
42
|
return {
|
|
40
43
|
jobId: result.Id,
|
|
41
44
|
jobName: result.DocumentName || '',
|
|
42
|
-
customJobName: result.DocumentName || '', //
|
|
45
|
+
customJobName: customName || result.DocumentName || '', // Use custom name if available
|
|
43
46
|
printerName: printerName,
|
|
44
47
|
status: result.JobStatus || 'Unknown',
|
|
45
48
|
pages: result.TotalPages || 0,
|
|
@@ -66,17 +69,21 @@ async function getAllJobs(printerName) {
|
|
|
66
69
|
const result = JSON.parse(output);
|
|
67
70
|
// Handle single result vs array
|
|
68
71
|
const jobs = Array.isArray(result) ? result : (result ? [result] : []);
|
|
69
|
-
return jobs.map((job) =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
return jobs.map((job) => {
|
|
73
|
+
// Get custom job name from mapper
|
|
74
|
+
const customName = (0, job_name_mapper_1.getCustomJobName)(printerName, job.Id);
|
|
75
|
+
return {
|
|
76
|
+
jobId: job.Id,
|
|
77
|
+
jobName: job.DocumentName || '',
|
|
78
|
+
customJobName: customName || job.DocumentName || '', // Use custom name if available
|
|
79
|
+
printerName: printerName,
|
|
80
|
+
status: job.JobStatus || 'Unknown',
|
|
81
|
+
pages: job.TotalPages || 0,
|
|
82
|
+
size: job.Size,
|
|
83
|
+
userName: job.UserName,
|
|
84
|
+
submittedTime: job.SubmittedTime
|
|
85
|
+
};
|
|
86
|
+
});
|
|
80
87
|
}
|
|
81
88
|
catch (error) {
|
|
82
89
|
return [];
|
package/lib/print-manager.js
CHANGED
|
@@ -11,6 +11,7 @@ const pdf_to_printer_1 = require("pdf-to-printer");
|
|
|
11
11
|
const uuid_1 = require("uuid");
|
|
12
12
|
const child_process_1 = require("child_process");
|
|
13
13
|
const job_tracker_1 = require("./job-tracker");
|
|
14
|
+
const job_name_mapper_1 = require("./job-name-mapper");
|
|
14
15
|
/**
|
|
15
16
|
* Prints a PDF file with the specified options
|
|
16
17
|
*/
|
|
@@ -64,11 +65,15 @@ async function print(options) {
|
|
|
64
65
|
printOptions.subset = options.subset;
|
|
65
66
|
}
|
|
66
67
|
// Set the document name for job tracking
|
|
67
|
-
printOptions.win32 = ['-print-settings', `${
|
|
68
|
+
printOptions.win32 = ['-print-settings', `${options.filePath}`];
|
|
68
69
|
// Print the document
|
|
69
70
|
await (0, pdf_to_printer_1.print)(options.filePath, printOptions);
|
|
70
71
|
// Try to retrieve job ID
|
|
71
|
-
const jobId = await (0, job_tracker_1.getJobIdByName)(options.printerName,
|
|
72
|
+
const jobId = await (0, job_tracker_1.getJobIdByName)(options.printerName, options.filePath);
|
|
73
|
+
// Store custom job name mapping if we got a job ID
|
|
74
|
+
if (jobId) {
|
|
75
|
+
(0, job_name_mapper_1.storeJobName)(options.printerName, jobId, jobName);
|
|
76
|
+
}
|
|
72
77
|
return {
|
|
73
78
|
success: true,
|
|
74
79
|
jobId: jobId || undefined,
|
package/package.json
CHANGED