@xuda.io/drive_module 1.1.952 → 1.1.954
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/index.js +18 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const crypto = require("node:crypto");
|
|
|
26
26
|
const unzipper = require("unzipper");
|
|
27
27
|
const fs = require("fs");
|
|
28
28
|
const tesseract = require("node-tesseract-ocr");
|
|
29
|
-
|
|
29
|
+
const franc = require("franc");
|
|
30
30
|
////////////////////////////////////////////
|
|
31
31
|
|
|
32
32
|
[
|
|
@@ -1723,15 +1723,18 @@ const ocr_drive_file = async function (app_id, doc) {
|
|
|
1723
1723
|
);
|
|
1724
1724
|
|
|
1725
1725
|
var ocr = "";
|
|
1726
|
+
const generalConfig = { lang: "eng", oem: 1, psm: 3 };
|
|
1726
1727
|
|
|
1727
1728
|
switch (doc.mime.split("/")[0]) {
|
|
1728
1729
|
case "image": {
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1730
|
+
const initialText = await tesseract.recognize(
|
|
1731
|
+
target_file,
|
|
1732
|
+
generalConfig
|
|
1733
|
+
);
|
|
1734
|
+
|
|
1735
|
+
// Detect the language from the extracted text
|
|
1736
|
+
const detectedLang = franc(initialText);
|
|
1737
|
+
ocr = await tesseract.recognize(target_file, generalConfig);
|
|
1735
1738
|
|
|
1736
1739
|
break;
|
|
1737
1740
|
}
|
|
@@ -1743,11 +1746,14 @@ const ocr_drive_file = async function (app_id, doc) {
|
|
|
1743
1746
|
|
|
1744
1747
|
const images = await convertPDF(target_file);
|
|
1745
1748
|
for await (const imageData of images) {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1749
|
+
const initialText = await tesseract.recognize(
|
|
1750
|
+
target_file,
|
|
1751
|
+
generalConfig
|
|
1752
|
+
);
|
|
1753
|
+
|
|
1754
|
+
// Detect the language from the extracted text
|
|
1755
|
+
const detectedLang = franc(initialText);
|
|
1756
|
+
ocr += await tesseract.recognize(imageData.path, generalConfig);
|
|
1751
1757
|
}
|
|
1752
1758
|
break;
|
|
1753
1759
|
}
|