@xuda.io/drive_module 1.1.922 → 1.1.923
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 +254 -254
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -40,7 +40,7 @@ const fs = require("fs");
|
|
|
40
40
|
"rename_drive_folder",
|
|
41
41
|
"update_drive_file_sharing_mode",
|
|
42
42
|
"delete_file_bulk",
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
"check_drive_file",
|
|
45
45
|
"update_drive_file_tags",
|
|
46
46
|
].forEach((method) => {
|
|
@@ -58,7 +58,7 @@ const fs = require("fs");
|
|
|
58
58
|
![
|
|
59
59
|
"get_drive_files",
|
|
60
60
|
"get_drive_file_info",
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
"check_drive_file",
|
|
63
63
|
].includes(method)
|
|
64
64
|
) {
|
|
@@ -1984,277 +1984,277 @@ exports.run_drive_pending_ocr = async function (req) {
|
|
|
1984
1984
|
}
|
|
1985
1985
|
};
|
|
1986
1986
|
|
|
1987
|
-
exports.search_drive_files = async function (req) {
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
if (tagKey === "name") {
|
|
2027
|
-
// ret.$or.push(
|
|
2028
|
-
// {
|
|
2029
|
-
// ocr: {
|
|
2030
|
-
// $regex: `(?i)${new_search}`,
|
|
2031
|
-
// },
|
|
2032
|
-
// },
|
|
2033
|
-
// {
|
|
2034
|
-
// originalname: {
|
|
2035
|
-
// $regex: `(?i)${new_search}`,
|
|
2036
|
-
// },
|
|
2037
|
-
// }
|
|
2038
|
-
// );
|
|
2039
|
-
ret.$or.push({ originalname: { $regex: `(?i)${tagVal}` } });
|
|
2040
|
-
}
|
|
2041
|
-
|
|
2042
|
-
return ret;
|
|
2043
|
-
},
|
|
2044
|
-
{
|
|
2045
|
-
$or: [],
|
|
2046
|
-
}
|
|
2047
|
-
);
|
|
2048
|
-
|
|
2049
|
-
var new_search = search_string
|
|
2050
|
-
.split(" ")
|
|
2051
|
-
.filter((e) => !e.includes(":"))
|
|
2052
|
-
.filter((e) => e)
|
|
2053
|
-
.join(" ");
|
|
2054
|
-
|
|
2055
|
-
tags_query.$or = [
|
|
2056
|
-
...tags_query.$or,
|
|
2057
|
-
{
|
|
2058
|
-
ocr: {
|
|
2059
|
-
$regex: `(?i)${new_search}`,
|
|
2060
|
-
},
|
|
2061
|
-
},
|
|
2062
|
-
{
|
|
2063
|
-
originalname: {
|
|
2064
|
-
$regex: `(?i)${new_search}`,
|
|
2065
|
-
},
|
|
2066
|
-
},
|
|
2067
|
-
];
|
|
2068
|
-
}
|
|
2069
|
-
try {
|
|
2070
|
-
validate_drive_type(drive_type);
|
|
2071
|
-
|
|
2072
|
-
if (!search_name && !search_string && !tags?.length) {
|
|
2073
|
-
// throw new Error("search too broad");
|
|
2074
|
-
limit = 25;
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
var search_results = [];
|
|
2078
|
-
|
|
2079
|
-
let selector = {
|
|
2080
|
-
docType: `${drive_type}_drive`,
|
|
2081
|
-
stat: 3,
|
|
2082
|
-
$and: [],
|
|
2083
|
-
file_path: path,
|
|
2084
|
-
...tags_query,
|
|
2085
|
-
};
|
|
2086
|
-
|
|
2087
|
-
if (type) {
|
|
2088
|
-
selector.type = type;
|
|
2089
|
-
}
|
|
1987
|
+
// exports.search_drive_files = async function (req) {
|
|
1988
|
+
// const {
|
|
1989
|
+
// drive_type,
|
|
1990
|
+
// app_id,
|
|
1991
|
+
// search_name,
|
|
1992
|
+
// search_string,
|
|
1993
|
+
// date_from,
|
|
1994
|
+
// date_to,
|
|
1995
|
+
// mime_type,
|
|
1996
|
+
// file_ext,
|
|
1997
|
+
// type,
|
|
1998
|
+
|
|
1999
|
+
// sort_by = "name",
|
|
2000
|
+
// sort_dir = "desc",
|
|
2001
|
+
// path = "/",
|
|
2002
|
+
// } = req;
|
|
2003
|
+
|
|
2004
|
+
// let { tags = [] } = req;
|
|
2005
|
+
|
|
2006
|
+
// let { limit = 100 } = req;
|
|
2007
|
+
// let tags_query = {};
|
|
2008
|
+
// const sort_by_obj = { name: "originalname", date: "date_created" };
|
|
2009
|
+
|
|
2010
|
+
// // const protected_tags = ["tag:", "name:"];
|
|
2011
|
+
|
|
2012
|
+
// if (search_string) {
|
|
2013
|
+
// // var og_search = ""
|
|
2014
|
+
// tags_query = search_string
|
|
2015
|
+
// .split(" ")
|
|
2016
|
+
// .filter((e) => e.includes(":"))
|
|
2017
|
+
// .reduce(
|
|
2018
|
+
// (ret, val) => {
|
|
2019
|
+
// var tagKey = val.split(":")[0];
|
|
2020
|
+
// var tagVal = val.split(":")[1];
|
|
2021
|
+
|
|
2022
|
+
// if (tagKey === "tag") {
|
|
2023
|
+
// tags.push(tagVal);
|
|
2024
|
+
// }
|
|
2090
2025
|
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2026
|
+
// if (tagKey === "name") {
|
|
2027
|
+
// // ret.$or.push(
|
|
2028
|
+
// // {
|
|
2029
|
+
// // ocr: {
|
|
2030
|
+
// // $regex: `(?i)${new_search}`,
|
|
2031
|
+
// // },
|
|
2032
|
+
// // },
|
|
2033
|
+
// // {
|
|
2034
|
+
// // originalname: {
|
|
2035
|
+
// // $regex: `(?i)${new_search}`,
|
|
2036
|
+
// // },
|
|
2037
|
+
// // }
|
|
2038
|
+
// // );
|
|
2039
|
+
// ret.$or.push({ originalname: { $regex: `(?i)${tagVal}` } });
|
|
2040
|
+
// }
|
|
2095
2041
|
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2042
|
+
// return ret;
|
|
2043
|
+
// },
|
|
2044
|
+
// {
|
|
2045
|
+
// $or: [],
|
|
2046
|
+
// }
|
|
2047
|
+
// );
|
|
2048
|
+
|
|
2049
|
+
// var new_search = search_string
|
|
2050
|
+
// .split(" ")
|
|
2051
|
+
// .filter((e) => !e.includes(":"))
|
|
2052
|
+
// .filter((e) => e)
|
|
2053
|
+
// .join(" ");
|
|
2054
|
+
|
|
2055
|
+
// tags_query.$or = [
|
|
2056
|
+
// ...tags_query.$or,
|
|
2057
|
+
// {
|
|
2058
|
+
// ocr: {
|
|
2059
|
+
// $regex: `(?i)${new_search}`,
|
|
2060
|
+
// },
|
|
2061
|
+
// },
|
|
2062
|
+
// {
|
|
2063
|
+
// originalname: {
|
|
2064
|
+
// $regex: `(?i)${new_search}`,
|
|
2065
|
+
// },
|
|
2066
|
+
// },
|
|
2067
|
+
// ];
|
|
2068
|
+
// }
|
|
2069
|
+
// try {
|
|
2070
|
+
// validate_drive_type(drive_type);
|
|
2103
2071
|
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
}
|
|
2072
|
+
// if (!search_name && !search_string && !tags?.length) {
|
|
2073
|
+
// // throw new Error("search too broad");
|
|
2074
|
+
// limit = 25;
|
|
2075
|
+
// }
|
|
2109
2076
|
|
|
2110
|
-
|
|
2111
|
-
selector.mime = mime_type;
|
|
2112
|
-
}
|
|
2077
|
+
// var search_results = [];
|
|
2113
2078
|
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2079
|
+
// let selector = {
|
|
2080
|
+
// docType: `${drive_type}_drive`,
|
|
2081
|
+
// stat: 3,
|
|
2082
|
+
// $and: [],
|
|
2083
|
+
// file_path: path,
|
|
2084
|
+
// ...tags_query,
|
|
2085
|
+
// };
|
|
2117
2086
|
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
// $or: [
|
|
2122
|
-
// {
|
|
2123
|
-
// ocr: {
|
|
2124
|
-
// $regex: `(?i)${req.search_string}`,
|
|
2125
|
-
// },
|
|
2126
|
-
// },
|
|
2127
|
-
// {
|
|
2128
|
-
// originalname: {
|
|
2129
|
-
// $regex: `(?i)${req.search_string}`,
|
|
2130
|
-
// },
|
|
2131
|
-
// },
|
|
2132
|
-
// ],
|
|
2133
|
-
// };
|
|
2134
|
-
// }
|
|
2087
|
+
// if (type) {
|
|
2088
|
+
// selector.type = type;
|
|
2089
|
+
// }
|
|
2135
2090
|
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
}
|
|
2091
|
+
// if (date_from || date_to) {
|
|
2092
|
+
// if (date_to < date_from) {
|
|
2093
|
+
// throw new Error("invalid date_from and date_to range");
|
|
2094
|
+
// }
|
|
2141
2095
|
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
"is_folder",
|
|
2150
|
-
"file_ext",
|
|
2151
|
-
"mime",
|
|
2152
|
-
"size",
|
|
2153
|
-
],
|
|
2154
|
-
sort: [{ [sort_by_obj[sort_by]]: sort_dir }],
|
|
2155
|
-
};
|
|
2096
|
+
// selector.$and.push({
|
|
2097
|
+
// date_created: {
|
|
2098
|
+
// $lte: date_to,
|
|
2099
|
+
// $gte: date_from,
|
|
2100
|
+
// },
|
|
2101
|
+
// });
|
|
2102
|
+
// }
|
|
2156
2103
|
|
|
2157
|
-
|
|
2104
|
+
// if (search_name) {
|
|
2105
|
+
// selector.originalname = {
|
|
2106
|
+
// $regex: `(i)^${req.search_string}`,
|
|
2107
|
+
// };
|
|
2108
|
+
// }
|
|
2158
2109
|
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
name: doc.originalname,
|
|
2163
|
-
path: doc.server_file_name,
|
|
2164
|
-
type: doc.is_folder ? "directory" : "file", //type ||
|
|
2165
|
-
file_url: get_file_url(drive_type, doc.server_file_name, ref),
|
|
2166
|
-
mime: doc.mime,
|
|
2167
|
-
file_ext: doc?.file_ext?.substr(1),
|
|
2168
|
-
size: doc.size,
|
|
2169
|
-
date: doc.date_created,
|
|
2170
|
-
};
|
|
2171
|
-
});
|
|
2172
|
-
};
|
|
2110
|
+
// if (mime_type) {
|
|
2111
|
+
// selector.mime = mime_type;
|
|
2112
|
+
// }
|
|
2173
2113
|
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
ref = app_id;
|
|
2178
|
-
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
2179
|
-
search_results = alias_results(
|
|
2180
|
-
(await db_module.find_app_couch_query(app_id_reference, opt)).docs
|
|
2181
|
-
);
|
|
2182
|
-
break;
|
|
2183
|
-
}
|
|
2114
|
+
// if (file_ext) {
|
|
2115
|
+
// selector.file_ext = file_ext;
|
|
2116
|
+
// }
|
|
2184
2117
|
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2118
|
+
// // if (req.search_string) {
|
|
2119
|
+
// // selector = {
|
|
2120
|
+
// // ...selector,
|
|
2121
|
+
// // $or: [
|
|
2122
|
+
// // {
|
|
2123
|
+
// // ocr: {
|
|
2124
|
+
// // $regex: `(?i)${req.search_string}`,
|
|
2125
|
+
// // },
|
|
2126
|
+
// // },
|
|
2127
|
+
// // {
|
|
2128
|
+
// // originalname: {
|
|
2129
|
+
// // $regex: `(?i)${req.search_string}`,
|
|
2130
|
+
// // },
|
|
2131
|
+
// // },
|
|
2132
|
+
// // ],
|
|
2133
|
+
// // };
|
|
2134
|
+
// // }
|
|
2135
|
+
|
|
2136
|
+
// if (tags?.length) {
|
|
2137
|
+
// selector.tags = {
|
|
2138
|
+
// $in: tags,
|
|
2139
|
+
// };
|
|
2140
|
+
// }
|
|
2192
2141
|
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2142
|
+
// var opt = {
|
|
2143
|
+
// selector,
|
|
2144
|
+
// limit,
|
|
2145
|
+
// fields: [
|
|
2146
|
+
// "originalname",
|
|
2147
|
+
// "date_created",
|
|
2148
|
+
// "server_file_name",
|
|
2149
|
+
// "is_folder",
|
|
2150
|
+
// "file_ext",
|
|
2151
|
+
// "mime",
|
|
2152
|
+
// "size",
|
|
2153
|
+
// ],
|
|
2154
|
+
// sort: [{ [sort_by_obj[sort_by]]: sort_dir }],
|
|
2155
|
+
// };
|
|
2156
|
+
|
|
2157
|
+
// console.log("opt", opt);
|
|
2158
|
+
|
|
2159
|
+
// const alias_results = (docs) => {
|
|
2160
|
+
// return docs.map((doc) => {
|
|
2161
|
+
// return {
|
|
2162
|
+
// name: doc.originalname,
|
|
2163
|
+
// path: doc.server_file_name,
|
|
2164
|
+
// type: doc.is_folder ? "directory" : "file", //type ||
|
|
2165
|
+
// file_url: get_file_url(drive_type, doc.server_file_name, ref),
|
|
2166
|
+
// mime: doc.mime,
|
|
2167
|
+
// file_ext: doc?.file_ext?.substr(1),
|
|
2168
|
+
// size: doc.size,
|
|
2169
|
+
// date: doc.date_created,
|
|
2170
|
+
// };
|
|
2171
|
+
// });
|
|
2172
|
+
// };
|
|
2173
|
+
|
|
2174
|
+
// var ref;
|
|
2175
|
+
// switch (drive_type) {
|
|
2176
|
+
// case "workspace": {
|
|
2177
|
+
// ref = app_id;
|
|
2178
|
+
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
2179
|
+
// search_results = alias_results(
|
|
2180
|
+
// (await db_module.find_app_couch_query(app_id_reference, opt)).docs
|
|
2181
|
+
// );
|
|
2182
|
+
// break;
|
|
2183
|
+
// }
|
|
2205
2184
|
|
|
2206
|
-
|
|
2207
|
-
|
|
2185
|
+
// case "user": {
|
|
2186
|
+
// ref = uid;
|
|
2187
|
+
// search_results = alias_results(
|
|
2188
|
+
// (await db_module.find_couch_query("xuda_drive", opt)).docs
|
|
2189
|
+
// );
|
|
2190
|
+
// break;
|
|
2191
|
+
// }
|
|
2208
2192
|
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2193
|
+
// case "studio": {
|
|
2194
|
+
// ref = app_id;
|
|
2195
|
+
// const directoryPath = path.join(_conf[`studio_drive_path`], app_id);
|
|
2196
|
+
|
|
2197
|
+
// const options = {
|
|
2198
|
+
// stat: false,
|
|
2199
|
+
// symbolicLinks: false,
|
|
2200
|
+
// size: true,
|
|
2201
|
+
// hash: false,
|
|
2202
|
+
// };
|
|
2203
|
+
// const dree_ret = await fs_module.dree_scan(directoryPath, options);
|
|
2204
|
+
// var tree = dree_ret.data;
|
|
2205
|
+
|
|
2206
|
+
// function findInName(obj, maxResults = limit) {
|
|
2207
|
+
// let results = [];
|
|
2208
|
+
|
|
2209
|
+
// // Function to search within an individual object
|
|
2210
|
+
// function searchInObject(o) {
|
|
2211
|
+
// // Stop the recursion if we already have maxResults
|
|
2212
|
+
// if (results.length >= maxResults) {
|
|
2213
|
+
// return;
|
|
2214
|
+
// }
|
|
2215
|
+
// if (
|
|
2216
|
+
// o.name &&
|
|
2217
|
+
// ((search_string && o.name.includes(search_string)) ||
|
|
2218
|
+
// (search_name && o.name.startsWith(search_name)))
|
|
2219
|
+
// ) {
|
|
2220
|
+
// results.push({ name: o.name, path: o.path, type: o.type });
|
|
2221
|
+
// }
|
|
2222
|
+
// if (o.children) {
|
|
2223
|
+
// if (Array.isArray(o.children)) {
|
|
2224
|
+
// o.children.forEach((child) => searchInObject(child));
|
|
2225
|
+
// } else {
|
|
2226
|
+
// searchInObject(o.children);
|
|
2227
|
+
// }
|
|
2228
|
+
// }
|
|
2229
|
+
// }
|
|
2230
2230
|
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2231
|
+
// searchInObject(obj);
|
|
2232
|
+
// return results;
|
|
2233
|
+
// }
|
|
2234
2234
|
|
|
2235
|
-
|
|
2235
|
+
// search_results = findInName(tree);
|
|
2236
2236
|
|
|
2237
|
-
|
|
2238
|
-
|
|
2237
|
+
// break;
|
|
2238
|
+
// }
|
|
2239
2239
|
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
};
|
|
2240
|
+
// default:
|
|
2241
|
+
// throw new Error("drive_type error");
|
|
2242
|
+
// break;
|
|
2243
|
+
// // }
|
|
2244
|
+
// }
|
|
2245
|
+
// // console.log(search_results);
|
|
2246
|
+
// return {
|
|
2247
|
+
// code: 200,
|
|
2248
|
+
// data: search_results,
|
|
2249
|
+
// };
|
|
2250
|
+
// } catch (err) {
|
|
2251
|
+
// // return err.message;
|
|
2252
|
+
// return {
|
|
2253
|
+
// code: -200,
|
|
2254
|
+
// data: err.message,
|
|
2255
|
+
// };
|
|
2256
|
+
// }
|
|
2257
|
+
// };
|
|
2258
2258
|
|
|
2259
2259
|
exports.get_drive_size = async function (req) {
|
|
2260
2260
|
try {
|