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