@xuda.io/drive_module 1.1.909 → 1.1.910

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.
Files changed (2) hide show
  1. package/index.js +125 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1694,6 +1694,7 @@ exports.check_drive_file = async function (req, job_id, headers, file_obj) {
1694
1694
  };
1695
1695
 
1696
1696
  const ocr_drive_file = async function (doc) {
1697
+ return;
1697
1698
  const { drive_type, target_file } = doc;
1698
1699
  var doc_ret;
1699
1700
  try {
@@ -1717,7 +1718,7 @@ const ocr_drive_file = async function (doc) {
1717
1718
  break;
1718
1719
  }
1719
1720
 
1720
- doc = doc_ret.data;
1721
+ doc = await get_drive_doc("file", drive_type); //doc_ret.data;
1721
1722
 
1722
1723
  var ocr = "";
1723
1724
 
@@ -1816,6 +1817,129 @@ const ocr_drive_file = async function (doc) {
1816
1817
  }
1817
1818
  };
1818
1819
 
1820
+ // const ocr_drive_file = async function (doc) {
1821
+ // const { drive_type, target_file } = doc;
1822
+ // var doc_ret;
1823
+ // try {
1824
+ // doc.ocr_stat = 2;
1825
+ // doc.ocr_stat_date = Date.now();
1826
+ // switch (drive_type) {
1827
+ // case "workspace":
1828
+ // case "studio":
1829
+ // const app_id_reference = await _common.get_project_app_id(doc.app_id);
1830
+ // await db_module.save_app_couch_doc(app_id_reference, doc);
1831
+ // doc_ret = await db_module.get_app_couch_doc(app_id_reference, doc._id);
1832
+ // break;
1833
+
1834
+ // case "user":
1835
+ // await db_module.save_couch_doc("xuda_drive", doc);
1836
+ // doc_ret = await db_module.get_couch_doc("xuda_drive", doc._id);
1837
+ // break;
1838
+
1839
+ // default:
1840
+ // throw new Error("drive_type error");
1841
+ // break;
1842
+ // }
1843
+
1844
+ // doc = await get_drive_doc("file",drive_type,)//doc_ret.data;
1845
+
1846
+ // var ocr = "";
1847
+
1848
+ // switch (doc.mime.split("/")[0]) {
1849
+ // case "image": {
1850
+ // const tesseract = require("node-tesseract-ocr");
1851
+ // ocr = await tesseract.recognize(target_file, {
1852
+ // lang: "eng",
1853
+ // oem: 1,
1854
+ // psm: 3,
1855
+ // });
1856
+
1857
+ // break;
1858
+ // }
1859
+
1860
+ // case "application": {
1861
+ // switch (doc.mime.split("/")[1]) {
1862
+ // case "pdf": {
1863
+ // const { convertPDF } = require("pdf2image");
1864
+ // const tesseract = require("node-tesseract-ocr");
1865
+
1866
+ // const images = await convertPDF(target_file);
1867
+ // for await (const imageData of images) {
1868
+ // ocr += await tesseract.recognize(imageData.path, {
1869
+ // lang: "eng",
1870
+ // oem: 1,
1871
+ // psm: 3,
1872
+ // });
1873
+ // }
1874
+ // break;
1875
+ // }
1876
+
1877
+ // case "vnd.openxmlformats-officedocument.wordprocessingml.document": {
1878
+ // const mammoth = require("mammoth");
1879
+ // ocr = (await mammoth.extractRawText({ path: target_file })).value;
1880
+ // break;
1881
+ // }
1882
+
1883
+ // case "nd.ms-excel":
1884
+ // case "vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
1885
+ // const xlsx = require("node-xlsx").default;
1886
+
1887
+ // const sheets = xlsx.parse(target_file);
1888
+ // sheets.forEach((sheet) => {
1889
+ // console.log(`Sheet: ${sheet.name}`);
1890
+ // sheet.data.forEach((row) => {
1891
+ // ocr += row.join(" "); // Join all cells in the row
1892
+ // });
1893
+ // });
1894
+ // break;
1895
+ // }
1896
+
1897
+ // case "vnd.ms-powerpoint":
1898
+ // case "vnd.openxmlformats-officedocument.presentationml.presentation":
1899
+ // // tbd
1900
+ // break;
1901
+
1902
+ // default:
1903
+ // ocr = (await fs_module.read_file(target_file)).data;
1904
+ // break;
1905
+ // }
1906
+ // break;
1907
+ // }
1908
+
1909
+ // case "text": {
1910
+ // ocr = (await fs_module.read_file(target_file)).data;
1911
+ // break;
1912
+ // }
1913
+
1914
+ // default:
1915
+ // break;
1916
+ // }
1917
+
1918
+ // doc.ocr = ocr.replace(/<\/?[^>]+(>|$)/g, "").replace(/[\n\t]/g, "");
1919
+ // doc.ocr_stat = 3;
1920
+ // } catch (err) {
1921
+ // doc.ocr_stat = 4;
1922
+ // } finally {
1923
+ // doc.ocr_stat_ts = Date.now();
1924
+
1925
+ // var save_ret;
1926
+ // switch (drive_type) {
1927
+ // case "workspace":
1928
+ // case "studio":
1929
+ // const app_id_reference = await _common.get_project_app_id(doc.app_id);
1930
+ // await db_module.save_app_couch_doc(app_id_reference, doc);
1931
+ // break;
1932
+
1933
+ // case "user":
1934
+ // await db_module.save_couch_doc("xuda_drive", doc);
1935
+ // break;
1936
+
1937
+ // default:
1938
+ // break;
1939
+ // }
1940
+ // }
1941
+ // };
1942
+
1819
1943
  const validate_drive_type = function (drive_type) {
1820
1944
  if (!["studio", "workspace", "user"].includes(drive_type)) {
1821
1945
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/drive_module",
3
- "version": "1.1.909",
3
+ "version": "1.1.910",
4
4
  "description": "Xuda Drive Server Module",
5
5
  "main": "index.js",
6
6
  "dependencies": {