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