lfp


Logs | Files | README | LICENSE | GitLab


1
commit fd2ffe9f158df11e6f4313d4e037b586375fbcb8
2
Author: Connor Etherington <[email protected]>
3
Date:   Wed Oct 25 10:50:41 2023 +0200
4
5
    Auto-Commit Update - 20231025
6
---
7
 lfp.install                    |  6 +++---
8
 usr/share/lfp/ocr/ocr.js       | 17 +++++++++++------
9
 usr/share/lfp/ocr/package.json |  2 +-
10
 usr/share/lfp/ocr/tesseract.js |  5 -----
11
 4 files changed, 15 insertions(+), 15 deletions(-)
12
13
diff --git a/lfp.install b/lfp.install
14
index dd88f47..628dbf3 100644
15
--- a/lfp.install
16
+++ b/lfp.install
17
@@ -1,7 +1,7 @@
18
 install(){
19
-  which yarn >/dev/null 2>&1 && yarn install /usr/share/lfp/ocr ||
20
-    which npm >/dev/null 2>&1 && npm install /usr/share/lfp/ocr ||
21
-    true
22
+  which npm >/dev/null 2>&1 && {
23
+    npm install -g /usr/share/lfp/ocr --unsafe-perm=true --allow-root ||
24
+    npm install /usr/share/lfp/ocr --user
25
 }
26
 
27
 post_install() {
28
diff --git a/usr/share/lfp/ocr/ocr.js b/usr/share/lfp/ocr/ocr.js
29
index e4af7b0..4604522 100755
30
--- a/usr/share/lfp/ocr/ocr.js
31
+++ b/usr/share/lfp/ocr/ocr.js
32
@@ -22,6 +22,8 @@ const sh = (cmd, opts) => new Promise((resolve, reject) => {
33
   });
34
 });
35
 
36
+let fail = false;
37
+
38
 const ocr = async (imagePath) => {
39
   const Type = await sh(`file -b --mime-type ${imagePath}`);
40
   if (await sh(`file -bL --mime-encoding ${imagePath}`) === 'utf-8') {
41
@@ -35,6 +37,7 @@ const ocr = async (imagePath) => {
42
     const image = await fsp.readFile(imagePath);
43
     return await tesseract.recognize(image, config);
44
   } else {
45
+    fail = true;
46
     throw new Error('Unknown image type');
47
   }
48
 }
49
@@ -68,14 +71,16 @@ const extractsDir = '/home/nvx1/.local/share/logs/ocrListener/extracts';
50
     resolve(writeFile(path.join(extractsDir, `${timestamp().replace(/:/g, '-').replace(/ /g, '_')}.txt`), combinedText));
51
   }).then(() => {
52
 
53
-    console.log(`\n${green}[+] ${reset}LFP OCR:\n`);
54
+    if (!fail) {
55
+      console.log(`\n${green}[+] ${reset}LFP OCR:\n`);
56
 
57
-    echo.stdout.pipe(xclip.stdin);
58
+      echo.stdout.pipe(xclip.stdin);
59
 
60
-    echo.on('close', () => {
61
-      console.log(combinedText);
62
-      process.exit(0);
63
-    });
64
+      echo.on('close', () => {
65
+        console.log(combinedText);
66
+        process.exit(0);
67
+      });
68
+    } else process.exit(1);
69
   })
70
 
71
 })();
72
diff --git a/usr/share/lfp/ocr/package.json b/usr/share/lfp/ocr/package.json
73
index 3d887b7..0b24c3c 100644
74
--- a/usr/share/lfp/ocr/package.json
75
+++ b/usr/share/lfp/ocr/package.json
76
@@ -1,6 +1,6 @@
77
 {
78
   "name": "lfp-ocr",
79
-  "version": "0.1.0",
80
+  "version": "0.2.0",
81
   "description": "",
82
   "main": "ocr.js",
83
   "scripts": {
84
diff --git a/usr/share/lfp/ocr/tesseract.js b/usr/share/lfp/ocr/tesseract.js
85
index ff8fd67..daa3c85 100644
86
--- a/usr/share/lfp/ocr/tesseract.js
87
+++ b/usr/share/lfp/ocr/tesseract.js
88
@@ -1,11 +1,6 @@
89
 const exec = require("child_process").exec
90
 const log = console.debug
91
 
92
-/**
93
- * @param input - URL, local image path or Buffer
94
- * @param config - any OCR options and control parameters
95
- * @returns default output format is text
96
- */
97
 function recognize(input, config = {}) {
98
   const options = getOptions(config)
99
   const binary = config.binary || "tesseract"