@xuda.io/drive_module 1.1.1013 → 1.1.1015
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 +15 -437
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -158,21 +158,22 @@ exports.get_drive_files = async function (req) {
|
|
|
158
158
|
.filter((e) => !e.includes(":"))
|
|
159
159
|
.filter((e) => e)
|
|
160
160
|
.join(" ");
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
if (mix_conditions) {
|
|
162
|
+
tags_query.$or = [
|
|
163
|
+
...tags_query.$or,
|
|
164
|
+
{
|
|
165
|
+
ocr: {
|
|
166
|
+
$regex: `(?i)${new_search}`,
|
|
167
|
+
},
|
|
167
168
|
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
{
|
|
170
|
+
originalname: {
|
|
171
|
+
$regex: `(?i)${new_search}`,
|
|
172
|
+
},
|
|
172
173
|
},
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
];
|
|
175
|
+
opt.selector = { ...opt.selector, ...tags_query };
|
|
176
|
+
}
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
if (tags?.length) {
|
|
@@ -646,150 +647,6 @@ exports.get_drive_file_info = async function (req, job_id, headers) {
|
|
|
646
647
|
};
|
|
647
648
|
}
|
|
648
649
|
};
|
|
649
|
-
// exports.delete_drive_files = async function (req) {
|
|
650
|
-
// try {
|
|
651
|
-
// const { drive_type, app_id, files_arr } = req;
|
|
652
|
-
// validate_drive_type(drive_type);
|
|
653
|
-
|
|
654
|
-
// if (!Array.isArray(files_arr)) {
|
|
655
|
-
// return {
|
|
656
|
-
// code: -400,
|
|
657
|
-
// data: "error - files_arr must be Array",
|
|
658
|
-
// };
|
|
659
|
-
// }
|
|
660
|
-
|
|
661
|
-
// let doc_ret;
|
|
662
|
-
// for await (const file of files_arr) {
|
|
663
|
-
|
|
664
|
-
// let doc = await get_drive_doc(
|
|
665
|
-
// "file",
|
|
666
|
-
// drive_type,
|
|
667
|
-
// app_id,
|
|
668
|
-
// uid,
|
|
669
|
-
// file.file_path,
|
|
670
|
-
// headers
|
|
671
|
-
// );
|
|
672
|
-
|
|
673
|
-
// switch (drive_type) {
|
|
674
|
-
// case "studio": {
|
|
675
|
-
// const app_id_master = await _common.get_project_app_id(app_id);
|
|
676
|
-
// doc_ret = await db_module.get_app_couch_doc(
|
|
677
|
-
// app_id_master,
|
|
678
|
-
// path.basename(file.path)
|
|
679
|
-
// );
|
|
680
|
-
|
|
681
|
-
// const ret = rimraf.sync(file.path); // delete the file
|
|
682
|
-
// if (doc_ret.code > -1) {
|
|
683
|
-
// if (doc_ret.data.type === "directory") {
|
|
684
|
-
// const docs = await get_folder_docs(
|
|
685
|
-
// path.basename(file.path),
|
|
686
|
-
// drive_type,
|
|
687
|
-
// app_id_master
|
|
688
|
-
// );
|
|
689
|
-
// for await (let doc of docs) {
|
|
690
|
-
// doc._deleted = true;
|
|
691
|
-
// await db_module.save_app_couch_doc(app_id_master, doc);
|
|
692
|
-
// }
|
|
693
|
-
// }
|
|
694
|
-
|
|
695
|
-
// doc_ret.data._deleted = true;
|
|
696
|
-
// save_ret = await db_module.save_app_couch_doc(
|
|
697
|
-
// app_id_master,
|
|
698
|
-
// doc_ret.data
|
|
699
|
-
// );
|
|
700
|
-
// }
|
|
701
|
-
|
|
702
|
-
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
703
|
-
// "studio",
|
|
704
|
-
// app_id_master
|
|
705
|
-
// );
|
|
706
|
-
// break;
|
|
707
|
-
// }
|
|
708
|
-
|
|
709
|
-
// case "workspace": {
|
|
710
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
711
|
-
|
|
712
|
-
// doc_ret = await db_module.get_app_couch_doc(
|
|
713
|
-
// app_id_reference,
|
|
714
|
-
// path.basename(file.path)
|
|
715
|
-
// );
|
|
716
|
-
|
|
717
|
-
// if (doc_ret.data.type === "file") {
|
|
718
|
-
// await module.exports.delete_file_from_bucket(doc_ret.data.bucket);
|
|
719
|
-
// }
|
|
720
|
-
// if (doc_ret.data.type === "directory") {
|
|
721
|
-
// const docs = await get_folder_docs(
|
|
722
|
-
// path.basename(file.path),
|
|
723
|
-
// drive_type,
|
|
724
|
-
// app_id_reference
|
|
725
|
-
// );
|
|
726
|
-
// for await (let doc of docs) {
|
|
727
|
-
// if (doc.type === "file") {
|
|
728
|
-
// await module.exports.delete_file_from_bucket(doc.bucket);
|
|
729
|
-
// }
|
|
730
|
-
// doc.ts = Date.now();
|
|
731
|
-
// doc.stat = 4;
|
|
732
|
-
// await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
733
|
-
// }
|
|
734
|
-
// }
|
|
735
|
-
|
|
736
|
-
// doc_ret.data.ts = Date.now();
|
|
737
|
-
// doc_ret.data.stat = 4;
|
|
738
|
-
// save_ret = await db_module.save_app_couch_doc(
|
|
739
|
-
// app_id_reference,
|
|
740
|
-
// doc_ret.data
|
|
741
|
-
// );
|
|
742
|
-
|
|
743
|
-
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
744
|
-
// "workspace",
|
|
745
|
-
// app_id_reference
|
|
746
|
-
// );
|
|
747
|
-
// break;
|
|
748
|
-
// }
|
|
749
|
-
|
|
750
|
-
// case "user": {
|
|
751
|
-
// doc_ret = await db_module.get_couch_doc("xuda_drive", file.name);
|
|
752
|
-
// if (doc_ret.data.type === "file") {
|
|
753
|
-
// await module.exports.delete_file_from_bucket(doc_ret.data.bucket);
|
|
754
|
-
// }
|
|
755
|
-
// if (doc_ret.data.type === "directory") {
|
|
756
|
-
// const docs = await get_folder_docs(
|
|
757
|
-
// path.basename(file.path),
|
|
758
|
-
// drive_type,
|
|
759
|
-
// null
|
|
760
|
-
// );
|
|
761
|
-
// for await (let doc of docs) {
|
|
762
|
-
// if (doc.type === "file") {
|
|
763
|
-
// await module.exports.delete_file_from_bucket(doc.bucket);
|
|
764
|
-
// }
|
|
765
|
-
// doc.ts = Date.now();
|
|
766
|
-
// doc.stat = 4;
|
|
767
|
-
// await db_module.save_couch_doc("xuda_drive", doc);
|
|
768
|
-
// }
|
|
769
|
-
// }
|
|
770
|
-
// doc_ret.data.ts = Date.now();
|
|
771
|
-
// doc_ret.data.stat = 4;
|
|
772
|
-
// save_ret = await db_module.save_couch_doc("xuda_drive", doc_ret.data);
|
|
773
|
-
|
|
774
|
-
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
775
|
-
// "user",
|
|
776
|
-
// doc_ret.data.uid
|
|
777
|
-
// );
|
|
778
|
-
// break;
|
|
779
|
-
// }
|
|
780
|
-
// default:
|
|
781
|
-
// break;
|
|
782
|
-
// }
|
|
783
|
-
// }
|
|
784
|
-
|
|
785
|
-
// return {
|
|
786
|
-
// code: 200,
|
|
787
|
-
// data: req.files_arr,
|
|
788
|
-
// };
|
|
789
|
-
// } catch (err) {
|
|
790
|
-
// return { code: -1, data: err.message };
|
|
791
|
-
// }
|
|
792
|
-
// };
|
|
793
650
|
|
|
794
651
|
exports.delete_drive_files = async function (req, job_id, headers) {
|
|
795
652
|
try {
|
|
@@ -2021,291 +1878,12 @@ exports.run_drive_pending_ocr = async function (req) {
|
|
|
2021
1878
|
}
|
|
2022
1879
|
};
|
|
2023
1880
|
|
|
2024
|
-
// exports.search_drive_files = async function (req) {
|
|
2025
|
-
// const {
|
|
2026
|
-
// drive_type,
|
|
2027
|
-
// app_id,
|
|
2028
|
-
// search_name,
|
|
2029
|
-
// search_string,
|
|
2030
|
-
// date_from,
|
|
2031
|
-
// date_to,
|
|
2032
|
-
// mime_type,
|
|
2033
|
-
// file_ext,
|
|
2034
|
-
// type,
|
|
2035
|
-
|
|
2036
|
-
// sort_by = "name",
|
|
2037
|
-
// sort_dir = "desc",
|
|
2038
|
-
// path = "/",
|
|
2039
|
-
// } = req;
|
|
2040
|
-
|
|
2041
|
-
// let { tags = [] } = req;
|
|
2042
|
-
|
|
2043
|
-
// let { limit = 100 } = req;
|
|
2044
|
-
// let tags_query = {};
|
|
2045
|
-
// const sort_by_obj = { name: "originalname", date: "date_created" };
|
|
2046
|
-
|
|
2047
|
-
// // const protected_tags = ["tag:", "name:"];
|
|
2048
|
-
|
|
2049
|
-
// if (search_string) {
|
|
2050
|
-
// // var og_search = ""
|
|
2051
|
-
// tags_query = search_string
|
|
2052
|
-
// .split(" ")
|
|
2053
|
-
// .filter((e) => e.includes(":"))
|
|
2054
|
-
// .reduce(
|
|
2055
|
-
// (ret, val) => {
|
|
2056
|
-
// var tagKey = val.split(":")[0];
|
|
2057
|
-
// var tagVal = val.split(":")[1];
|
|
2058
|
-
|
|
2059
|
-
// if (tagKey === "tag") {
|
|
2060
|
-
// tags.push(tagVal);
|
|
2061
|
-
// }
|
|
2062
|
-
|
|
2063
|
-
// if (tagKey === "name") {
|
|
2064
|
-
// // ret.$or.push(
|
|
2065
|
-
// // {
|
|
2066
|
-
// // ocr: {
|
|
2067
|
-
// // $regex: `(?i)${new_search}`,
|
|
2068
|
-
// // },
|
|
2069
|
-
// // },
|
|
2070
|
-
// // {
|
|
2071
|
-
// // originalname: {
|
|
2072
|
-
// // $regex: `(?i)${new_search}`,
|
|
2073
|
-
// // },
|
|
2074
|
-
// // }
|
|
2075
|
-
// // );
|
|
2076
|
-
// ret.$or.push({ originalname: { $regex: `(?i)${tagVal}` } });
|
|
2077
|
-
// }
|
|
2078
|
-
|
|
2079
|
-
// return ret;
|
|
2080
|
-
// },
|
|
2081
|
-
// {
|
|
2082
|
-
// $or: [],
|
|
2083
|
-
// }
|
|
2084
|
-
// );
|
|
2085
|
-
|
|
2086
|
-
// var new_search = search_string
|
|
2087
|
-
// .split(" ")
|
|
2088
|
-
// .filter((e) => !e.includes(":"))
|
|
2089
|
-
// .filter((e) => e)
|
|
2090
|
-
// .join(" ");
|
|
2091
|
-
|
|
2092
|
-
// tags_query.$or = [
|
|
2093
|
-
// ...tags_query.$or,
|
|
2094
|
-
// {
|
|
2095
|
-
// ocr: {
|
|
2096
|
-
// $regex: `(?i)${new_search}`,
|
|
2097
|
-
// },
|
|
2098
|
-
// },
|
|
2099
|
-
// {
|
|
2100
|
-
// originalname: {
|
|
2101
|
-
// $regex: `(?i)${new_search}`,
|
|
2102
|
-
// },
|
|
2103
|
-
// },
|
|
2104
|
-
// ];
|
|
2105
|
-
// }
|
|
2106
|
-
// try {
|
|
2107
|
-
// validate_drive_type(drive_type);
|
|
2108
|
-
|
|
2109
|
-
// if (!search_name && !search_string && !tags?.length) {
|
|
2110
|
-
// // throw new Error("search too broad");
|
|
2111
|
-
// limit = 25;
|
|
2112
|
-
// }
|
|
2113
|
-
|
|
2114
|
-
// var search_results = [];
|
|
2115
|
-
|
|
2116
|
-
// let selector = {
|
|
2117
|
-
// docType: `${drive_type}_drive`,
|
|
2118
|
-
// stat: 3,
|
|
2119
|
-
// $and: [],
|
|
2120
|
-
// file_path: path,
|
|
2121
|
-
// ...tags_query,
|
|
2122
|
-
// };
|
|
2123
|
-
|
|
2124
|
-
// if (type) {
|
|
2125
|
-
// selector.type = type;
|
|
2126
|
-
// }
|
|
2127
|
-
|
|
2128
|
-
// if (date_from || date_to) {
|
|
2129
|
-
// if (date_to < date_from) {
|
|
2130
|
-
// throw new Error("invalid date_from and date_to range");
|
|
2131
|
-
// }
|
|
2132
|
-
|
|
2133
|
-
// selector.$and.push({
|
|
2134
|
-
// date_created: {
|
|
2135
|
-
// $lte: date_to,
|
|
2136
|
-
// $gte: date_from,
|
|
2137
|
-
// },
|
|
2138
|
-
// });
|
|
2139
|
-
// }
|
|
2140
|
-
|
|
2141
|
-
// if (search_name) {
|
|
2142
|
-
// selector.originalname = {
|
|
2143
|
-
// $regex: `(i)^${req.search_string}`,
|
|
2144
|
-
// };
|
|
2145
|
-
// }
|
|
2146
|
-
|
|
2147
|
-
// if (mime_type) {
|
|
2148
|
-
// selector.mime = mime_type;
|
|
2149
|
-
// }
|
|
2150
|
-
|
|
2151
|
-
// if (file_ext) {
|
|
2152
|
-
// selector.file_ext = file_ext;
|
|
2153
|
-
// }
|
|
2154
|
-
|
|
2155
|
-
// // if (req.search_string) {
|
|
2156
|
-
// // selector = {
|
|
2157
|
-
// // ...selector,
|
|
2158
|
-
// // $or: [
|
|
2159
|
-
// // {
|
|
2160
|
-
// // ocr: {
|
|
2161
|
-
// // $regex: `(?i)${req.search_string}`,
|
|
2162
|
-
// // },
|
|
2163
|
-
// // },
|
|
2164
|
-
// // {
|
|
2165
|
-
// // originalname: {
|
|
2166
|
-
// // $regex: `(?i)${req.search_string}`,
|
|
2167
|
-
// // },
|
|
2168
|
-
// // },
|
|
2169
|
-
// // ],
|
|
2170
|
-
// // };
|
|
2171
|
-
// // }
|
|
2172
|
-
|
|
2173
|
-
// if (tags?.length) {
|
|
2174
|
-
// selector.tags = {
|
|
2175
|
-
// $in: tags,
|
|
2176
|
-
// };
|
|
2177
|
-
// }
|
|
2178
|
-
|
|
2179
|
-
// var opt = {
|
|
2180
|
-
// selector,
|
|
2181
|
-
// limit,
|
|
2182
|
-
// fields: [
|
|
2183
|
-
// "originalname",
|
|
2184
|
-
// "date_created",
|
|
2185
|
-
// "server_file_name",
|
|
2186
|
-
// "is_folder",
|
|
2187
|
-
// "file_ext",
|
|
2188
|
-
// "mime",
|
|
2189
|
-
// "size",
|
|
2190
|
-
// ],
|
|
2191
|
-
// sort: [{ [sort_by_obj[sort_by]]: sort_dir }],
|
|
2192
|
-
// };
|
|
2193
|
-
|
|
2194
|
-
// console.log("opt", opt);
|
|
2195
|
-
|
|
2196
|
-
// const alias_results = (docs) => {
|
|
2197
|
-
// return docs.map((doc) => {
|
|
2198
|
-
// return {
|
|
2199
|
-
// name: doc.originalname,
|
|
2200
|
-
// path: doc.server_file_name,
|
|
2201
|
-
// type: doc.is_folder ? "directory" : "file", //type ||
|
|
2202
|
-
// file_url: get_file_url(drive_type, doc.server_file_name, ref),
|
|
2203
|
-
// mime: doc.mime,
|
|
2204
|
-
// file_ext: doc?.file_ext?.substr(1),
|
|
2205
|
-
// size: doc.size,
|
|
2206
|
-
// date: doc.date_created,
|
|
2207
|
-
// };
|
|
2208
|
-
// });
|
|
2209
|
-
// };
|
|
2210
|
-
|
|
2211
|
-
// var ref;
|
|
2212
|
-
// switch (drive_type) {
|
|
2213
|
-
// case "workspace": {
|
|
2214
|
-
// ref = app_id;
|
|
2215
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
2216
|
-
// search_results = alias_results(
|
|
2217
|
-
// (await db_module.find_app_couch_query(app_id_reference, opt)).docs
|
|
2218
|
-
// );
|
|
2219
|
-
// break;
|
|
2220
|
-
// }
|
|
2221
|
-
|
|
2222
|
-
// case "user": {
|
|
2223
|
-
// ref = uid;
|
|
2224
|
-
// search_results = alias_results(
|
|
2225
|
-
// (await db_module.find_couch_query("xuda_drive", opt)).docs
|
|
2226
|
-
// );
|
|
2227
|
-
// break;
|
|
2228
|
-
// }
|
|
2229
|
-
|
|
2230
|
-
// case "studio": {
|
|
2231
|
-
// ref = app_id;
|
|
2232
|
-
// const directoryPath = path.join(_conf[`studio_drive_path`], app_id);
|
|
2233
|
-
|
|
2234
|
-
// const options = {
|
|
2235
|
-
// stat: false,
|
|
2236
|
-
// symbolicLinks: false,
|
|
2237
|
-
// size: true,
|
|
2238
|
-
// hash: false,
|
|
2239
|
-
// };
|
|
2240
|
-
// const dree_ret = await fs_module.dree_scan(directoryPath, options);
|
|
2241
|
-
// var tree = dree_ret.data;
|
|
2242
|
-
|
|
2243
|
-
// function findInName(obj, maxResults = limit) {
|
|
2244
|
-
// let results = [];
|
|
2245
|
-
|
|
2246
|
-
// // Function to search within an individual object
|
|
2247
|
-
// function searchInObject(o) {
|
|
2248
|
-
// // Stop the recursion if we already have maxResults
|
|
2249
|
-
// if (results.length >= maxResults) {
|
|
2250
|
-
// return;
|
|
2251
|
-
// }
|
|
2252
|
-
// if (
|
|
2253
|
-
// o.name &&
|
|
2254
|
-
// ((search_string && o.name.includes(search_string)) ||
|
|
2255
|
-
// (search_name && o.name.startsWith(search_name)))
|
|
2256
|
-
// ) {
|
|
2257
|
-
// results.push({ name: o.name, path: o.path, type: o.type });
|
|
2258
|
-
// }
|
|
2259
|
-
// if (o.children) {
|
|
2260
|
-
// if (Array.isArray(o.children)) {
|
|
2261
|
-
// o.children.forEach((child) => searchInObject(child));
|
|
2262
|
-
// } else {
|
|
2263
|
-
// searchInObject(o.children);
|
|
2264
|
-
// }
|
|
2265
|
-
// }
|
|
2266
|
-
// }
|
|
2267
|
-
|
|
2268
|
-
// searchInObject(obj);
|
|
2269
|
-
// return results;
|
|
2270
|
-
// }
|
|
2271
|
-
|
|
2272
|
-
// search_results = findInName(tree);
|
|
2273
|
-
|
|
2274
|
-
// break;
|
|
2275
|
-
// }
|
|
2276
|
-
|
|
2277
|
-
// default:
|
|
2278
|
-
// throw new Error("drive_type error");
|
|
2279
|
-
// break;
|
|
2280
|
-
// // }
|
|
2281
|
-
// }
|
|
2282
|
-
// // console.log(search_results);
|
|
2283
|
-
// return {
|
|
2284
|
-
// code: 200,
|
|
2285
|
-
// data: search_results,
|
|
2286
|
-
// };
|
|
2287
|
-
// } catch (err) {
|
|
2288
|
-
// // return err.message;
|
|
2289
|
-
// return {
|
|
2290
|
-
// code: -200,
|
|
2291
|
-
// data: err.message,
|
|
2292
|
-
// };
|
|
2293
|
-
// }
|
|
2294
|
-
// };
|
|
2295
|
-
|
|
2296
1881
|
exports.get_drive_size = async function (req) {
|
|
2297
1882
|
try {
|
|
2298
1883
|
const { drive_type, app_id, uid } = req;
|
|
2299
1884
|
let size = 0;
|
|
2300
1885
|
// validate_drive_type(drive_type);
|
|
2301
1886
|
|
|
2302
|
-
// var ref;
|
|
2303
|
-
// if (drive_type === "user") {
|
|
2304
|
-
// ref = uid;
|
|
2305
|
-
// } else {
|
|
2306
|
-
// ref = await _common.get_project_app_id(app_id, true);
|
|
2307
|
-
// }
|
|
2308
|
-
|
|
2309
1887
|
let app_id_master, directoryPath;
|
|
2310
1888
|
switch (drive_type) {
|
|
2311
1889
|
case "user":
|
|
@@ -2556,7 +2134,7 @@ const get_folder_docs = async function (dir, drive_type, app_id) {
|
|
|
2556
2134
|
exports.update_drive_file_tags = async function (req, job_id, headers) {
|
|
2557
2135
|
try {
|
|
2558
2136
|
const { type, drive_type, app_id, uid, file_path, tags = [] } = req;
|
|
2559
|
-
|
|
2137
|
+
|
|
2560
2138
|
validate_drive_type(drive_type);
|
|
2561
2139
|
|
|
2562
2140
|
let doc = await get_drive_doc(
|