@xuda.io/drive_module 1.1.975 → 1.1.976
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 +22 -3
- 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 countryLanguage = require("country-language");
|
|
30
30
|
////////////////////////////////////////////
|
|
31
31
|
|
|
32
32
|
[
|
|
@@ -1723,9 +1723,28 @@ const ocr_drive_file = async function (app_id, doc) {
|
|
|
1723
1723
|
);
|
|
1724
1724
|
|
|
1725
1725
|
var ocr = "";
|
|
1726
|
-
const generalConfig = { oem: 1, psm: 3 };
|
|
1727
|
-
const { franc } = await import("franc");
|
|
1728
1726
|
|
|
1727
|
+
function detectLanguageByCountry(cfCountry) {
|
|
1728
|
+
const countryData = countryLanguage.getCountry(cfCountry);
|
|
1729
|
+
|
|
1730
|
+
// Check if the country data is available
|
|
1731
|
+
if (
|
|
1732
|
+
countryData &&
|
|
1733
|
+
countryData.languages &&
|
|
1734
|
+
countryData.languages.length > 0
|
|
1735
|
+
) {
|
|
1736
|
+
// Return the first official language of the country
|
|
1737
|
+
return countryData.languages[0].iso639_1;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// Default to English if no language found
|
|
1741
|
+
return "en";
|
|
1742
|
+
}
|
|
1743
|
+
let lang = detectLanguageByCountry(doc.country);
|
|
1744
|
+
if (lang !== "en") {
|
|
1745
|
+
lang += "+en";
|
|
1746
|
+
}
|
|
1747
|
+
const generalConfig = { oem: 1, psm: 3, lang };
|
|
1729
1748
|
switch (doc.mime.split("/")[0]) {
|
|
1730
1749
|
case "image": {
|
|
1731
1750
|
const initialText = await tesseract.recognize(
|