scan2form 1.0.0 → 1.1.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 CHANGED
@@ -19,7 +19,7 @@ import { Scan2Form } from 'scan2form';
19
19
 
20
20
  const scanner = new Scan2Form();
21
21
 
22
- // Triggers the scan and puts the file into <input type="file" id="my-input" />
22
+ // Triggers the scan and puts the file into <input type="file" id="my-input" style="display: none;"/>
23
23
  await scanner.scanToInput('my-input');
24
24
  ```
25
25
 
@@ -91,7 +91,9 @@ app.post('/scan', async (req, res) => {
91
91
  (0, child_process_1.exec)(cmd, (error, stdout, stderr) => {
92
92
  if (error) {
93
93
  console.error(`NAPS2 Error: ${error.message}`);
94
- return res.status(500).json({ error: "Scan failed", details: stderr });
94
+ // Return the actual error details to the client
95
+ const errorDetail = stderr || error.message;
96
+ return res.status(500).json({ error: "Scan failed", details: errorDetail });
95
97
  }
96
98
  if (fs_1.default.existsSync(finalPdfPath)) {
97
99
  res.sendFile(finalPdfPath, () => {
@@ -100,7 +102,7 @@ app.post('/scan', async (req, res) => {
100
102
  });
101
103
  }
102
104
  else {
103
- res.status(500).json({ error: "Scan completed but PDF not found." });
105
+ res.status(500).json({ error: "Scan completed but PDF not found.", details: "Output file missing." });
104
106
  }
105
107
  });
106
108
  }
@@ -115,7 +117,8 @@ app.post('/scan', async (req, res) => {
115
117
  // scanimage writes progress to stderr, so it might not be a real error unless exit code != 0.
116
118
  // But exec gives error on non-zero exit.
117
119
  console.error(`SANE Error: ${error.message}`);
118
- return res.status(500).json({ error: "Scan failed", details: stderr });
120
+ const errorDetail = stderr || error.message;
121
+ return res.status(500).json({ error: "Scan failed", details: errorDetail });
119
122
  }
120
123
  // Convert TIFF to PDF using Mac's 'sips' or ImageMagick 'convert'
121
124
  // Since we are targeting Mac fallback, we use 'sips'
@@ -6,10 +6,10 @@ export class Scan2Form {
6
6
  async isAvailable() {
7
7
  try {
8
8
  const res = await fetch(`${this.bridgeUrl}/health`);
9
- return res.ok;
9
+ return { success: res.ok };
10
10
  }
11
11
  catch (e) {
12
- return false;
12
+ return { success: false, error: e.message || "Network Error" };
13
13
  }
14
14
  }
15
15
  // List available scanners
@@ -48,7 +48,7 @@ export class Scan2Form {
48
48
  console.error("Scan2Form Error:", error);
49
49
  // Alerting might be annoying in a library, maybe optional? Leaving as is for now but usually libraries shouldn't alert.
50
50
  // alert("Ensure Scan2Form Bridge is running!");
51
- return { success: false, error: error };
51
+ return { success: false, error: error.message || "An unknown error occurred during scan." };
52
52
  }
53
53
  }
54
54
  }
@@ -9,10 +9,10 @@ class Scan2Form {
9
9
  async isAvailable() {
10
10
  try {
11
11
  const res = await fetch(`${this.bridgeUrl}/health`);
12
- return res.ok;
12
+ return { success: res.ok };
13
13
  }
14
14
  catch (e) {
15
- return false;
15
+ return { success: false, error: e.message || "Network Error" };
16
16
  }
17
17
  }
18
18
  // List available scanners
@@ -51,7 +51,7 @@ class Scan2Form {
51
51
  console.error("Scan2Form Error:", error);
52
52
  // Alerting might be annoying in a library, maybe optional? Leaving as is for now but usually libraries shouldn't alert.
53
53
  // alert("Ensure Scan2Form Bridge is running!");
54
- return { success: false, error: error };
54
+ return { success: false, error: error.message || "An unknown error occurred during scan." };
55
55
  }
56
56
  }
57
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scan2form",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Local offline bridge allowing web browsers to access physical scanners (WIA, TWAIN, SANE).",
5
5
  "main": "dist/scanner-client.js",
6
6
  "scripts": {