@xuda.io/drive_module 1.1.951 → 1.1.953
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 +5 -137
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -25,7 +25,8 @@ const fse = require("fs-extra");
|
|
|
25
25
|
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
|
+
const franc = require("franc");
|
|
29
30
|
////////////////////////////////////////////
|
|
30
31
|
|
|
31
32
|
[
|
|
@@ -1722,16 +1723,11 @@ const ocr_drive_file = async function (app_id, doc) {
|
|
|
1722
1723
|
);
|
|
1723
1724
|
|
|
1724
1725
|
var ocr = "";
|
|
1726
|
+
const generalConfig = { lang: "eng", oem: 1, psm: 3 };
|
|
1725
1727
|
|
|
1726
1728
|
switch (doc.mime.split("/")[0]) {
|
|
1727
1729
|
case "image": {
|
|
1728
|
-
|
|
1729
|
-
ocr = await tesseract.recognize(target_file, {
|
|
1730
|
-
// lang: "eng",
|
|
1731
|
-
lang: "eng+heb",
|
|
1732
|
-
oem: 1,
|
|
1733
|
-
psm: 3,
|
|
1734
|
-
});
|
|
1730
|
+
ocr = await tesseract.recognize(target_file, generalConfig);
|
|
1735
1731
|
|
|
1736
1732
|
break;
|
|
1737
1733
|
}
|
|
@@ -1740,15 +1736,10 @@ const ocr_drive_file = async function (app_id, doc) {
|
|
|
1740
1736
|
switch (doc.mime.split("/")[1]) {
|
|
1741
1737
|
case "pdf": {
|
|
1742
1738
|
const { convertPDF } = require("pdf2image");
|
|
1743
|
-
const tesseract = require("node-tesseract-ocr");
|
|
1744
1739
|
|
|
1745
1740
|
const images = await convertPDF(target_file);
|
|
1746
1741
|
for await (const imageData of images) {
|
|
1747
|
-
ocr += await tesseract.recognize(imageData.path,
|
|
1748
|
-
// lang: "eng",
|
|
1749
|
-
oem: 1,
|
|
1750
|
-
psm: 3,
|
|
1751
|
-
});
|
|
1742
|
+
ocr += await tesseract.recognize(imageData.path, generalConfig);
|
|
1752
1743
|
}
|
|
1753
1744
|
break;
|
|
1754
1745
|
}
|
|
@@ -1806,129 +1797,6 @@ const ocr_drive_file = async function (app_id, doc) {
|
|
|
1806
1797
|
}
|
|
1807
1798
|
};
|
|
1808
1799
|
|
|
1809
|
-
// const ocr_drive_file = async function (doc) {
|
|
1810
|
-
// const { drive_type, target_file } = doc;
|
|
1811
|
-
// var doc_ret;
|
|
1812
|
-
// try {
|
|
1813
|
-
// doc.ocr_stat = 2;
|
|
1814
|
-
// doc.ocr_stat_date = Date.now();
|
|
1815
|
-
// switch (drive_type) {
|
|
1816
|
-
// case "workspace":
|
|
1817
|
-
// case "studio":
|
|
1818
|
-
// const app_id_reference = await _common.get_project_app_id(doc.app_id);
|
|
1819
|
-
// await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
1820
|
-
// doc_ret = await db_module.get_app_couch_doc(app_id_reference, doc._id);
|
|
1821
|
-
// break;
|
|
1822
|
-
|
|
1823
|
-
// case "user":
|
|
1824
|
-
// await db_module.save_couch_doc("xuda_drive", doc);
|
|
1825
|
-
// doc_ret = await db_module.get_couch_doc("xuda_drive", doc._id);
|
|
1826
|
-
// break;
|
|
1827
|
-
|
|
1828
|
-
// default:
|
|
1829
|
-
// throw new Error("drive_type error");
|
|
1830
|
-
// break;
|
|
1831
|
-
// }
|
|
1832
|
-
|
|
1833
|
-
// doc = await get_drive_doc("file",drive_type,)//doc_ret.data;
|
|
1834
|
-
|
|
1835
|
-
// var ocr = "";
|
|
1836
|
-
|
|
1837
|
-
// switch (doc.mime.split("/")[0]) {
|
|
1838
|
-
// case "image": {
|
|
1839
|
-
// const tesseract = require("node-tesseract-ocr");
|
|
1840
|
-
// ocr = await tesseract.recognize(target_file, {
|
|
1841
|
-
// lang: "eng",
|
|
1842
|
-
// oem: 1,
|
|
1843
|
-
// psm: 3,
|
|
1844
|
-
// });
|
|
1845
|
-
|
|
1846
|
-
// break;
|
|
1847
|
-
// }
|
|
1848
|
-
|
|
1849
|
-
// case "application": {
|
|
1850
|
-
// switch (doc.mime.split("/")[1]) {
|
|
1851
|
-
// case "pdf": {
|
|
1852
|
-
// const { convertPDF } = require("pdf2image");
|
|
1853
|
-
// const tesseract = require("node-tesseract-ocr");
|
|
1854
|
-
|
|
1855
|
-
// const images = await convertPDF(target_file);
|
|
1856
|
-
// for await (const imageData of images) {
|
|
1857
|
-
// ocr += await tesseract.recognize(imageData.path, {
|
|
1858
|
-
// lang: "eng",
|
|
1859
|
-
// oem: 1,
|
|
1860
|
-
// psm: 3,
|
|
1861
|
-
// });
|
|
1862
|
-
// }
|
|
1863
|
-
// break;
|
|
1864
|
-
// }
|
|
1865
|
-
|
|
1866
|
-
// case "vnd.openxmlformats-officedocument.wordprocessingml.document": {
|
|
1867
|
-
// const mammoth = require("mammoth");
|
|
1868
|
-
// ocr = (await mammoth.extractRawText({ path: target_file })).value;
|
|
1869
|
-
// break;
|
|
1870
|
-
// }
|
|
1871
|
-
|
|
1872
|
-
// case "nd.ms-excel":
|
|
1873
|
-
// case "vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
|
|
1874
|
-
// const xlsx = require("node-xlsx").default;
|
|
1875
|
-
|
|
1876
|
-
// const sheets = xlsx.parse(target_file);
|
|
1877
|
-
// sheets.forEach((sheet) => {
|
|
1878
|
-
// console.log(`Sheet: ${sheet.name}`);
|
|
1879
|
-
// sheet.data.forEach((row) => {
|
|
1880
|
-
// ocr += row.join(" "); // Join all cells in the row
|
|
1881
|
-
// });
|
|
1882
|
-
// });
|
|
1883
|
-
// break;
|
|
1884
|
-
// }
|
|
1885
|
-
|
|
1886
|
-
// case "vnd.ms-powerpoint":
|
|
1887
|
-
// case "vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
1888
|
-
// // tbd
|
|
1889
|
-
// break;
|
|
1890
|
-
|
|
1891
|
-
// default:
|
|
1892
|
-
// ocr = (await fs_module.read_file(target_file)).data;
|
|
1893
|
-
// break;
|
|
1894
|
-
// }
|
|
1895
|
-
// break;
|
|
1896
|
-
// }
|
|
1897
|
-
|
|
1898
|
-
// case "text": {
|
|
1899
|
-
// ocr = (await fs_module.read_file(target_file)).data;
|
|
1900
|
-
// break;
|
|
1901
|
-
// }
|
|
1902
|
-
|
|
1903
|
-
// default:
|
|
1904
|
-
// break;
|
|
1905
|
-
// }
|
|
1906
|
-
|
|
1907
|
-
// doc.ocr = ocr.replace(/<\/?[^>]+(>|$)/g, "").replace(/[\n\t]/g, "");
|
|
1908
|
-
// doc.ocr_stat = 3;
|
|
1909
|
-
// } catch (err) {
|
|
1910
|
-
// doc.ocr_stat = 4;
|
|
1911
|
-
// } finally {
|
|
1912
|
-
// doc.ocr_stat_ts = Date.now();
|
|
1913
|
-
|
|
1914
|
-
// var save_ret;
|
|
1915
|
-
// switch (drive_type) {
|
|
1916
|
-
// case "workspace":
|
|
1917
|
-
// case "studio":
|
|
1918
|
-
// const app_id_reference = await _common.get_project_app_id(doc.app_id);
|
|
1919
|
-
// await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
1920
|
-
// break;
|
|
1921
|
-
|
|
1922
|
-
// case "user":
|
|
1923
|
-
// await db_module.save_couch_doc("xuda_drive", doc);
|
|
1924
|
-
// break;
|
|
1925
|
-
|
|
1926
|
-
// default:
|
|
1927
|
-
// break;
|
|
1928
|
-
// }
|
|
1929
|
-
// }
|
|
1930
|
-
// };
|
|
1931
|
-
|
|
1932
1800
|
const validate_drive_type = function (drive_type) {
|
|
1933
1801
|
if (!["studio", "workspace", "user"].includes(drive_type)) {
|
|
1934
1802
|
throw new Error(
|