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