@xuda.io/drive_module 1.1.1249 → 1.1.1250
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.mjs +16 -15
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -58,7 +58,7 @@ const get_studio_path = (raw_path, ref, file_name) => {
|
|
|
58
58
|
|
|
59
59
|
export const get_drive_files = async (req) => {
|
|
60
60
|
try {
|
|
61
|
-
const { from = 0, to = 99999, drive_type, app_id, uid, type, date, search_string, sort_by = 'name', sort_dir = 'desc' } = req;
|
|
61
|
+
const { from = 0, to = 99999, drive_type, app_id, uid, type, date, search_string, sort_by = 'name', sort_dir = 'desc', path: file_path } = req;
|
|
62
62
|
|
|
63
63
|
let { tags = [] } = req;
|
|
64
64
|
|
|
@@ -92,8 +92,8 @@ export const get_drive_files = async (req) => {
|
|
|
92
92
|
sort,
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
if (
|
|
96
|
-
opt.selector.file_path =
|
|
95
|
+
if (file_path) {
|
|
96
|
+
opt.selector.file_path = file_path;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
if (search_string) {
|
|
@@ -191,11 +191,12 @@ export const get_drive_files = async (req) => {
|
|
|
191
191
|
|
|
192
192
|
const fetch_drive_files = async (ret, file_doc, app_id_reference, uid, datasource_id, domain = process.env.XUDA_HOSTNAME, app_obj) => {
|
|
193
193
|
let files = {
|
|
194
|
-
path:
|
|
194
|
+
path: file_path || '/',
|
|
195
195
|
name: file_doc?.data?.folder_name || '/',
|
|
196
|
-
file_path:
|
|
196
|
+
file_path: file_path || '/',
|
|
197
197
|
sizeInBytes: 0,
|
|
198
198
|
children: [],
|
|
199
|
+
path: file_path,
|
|
199
200
|
};
|
|
200
201
|
|
|
201
202
|
for await (let doc of ret.docs) {
|
|
@@ -230,7 +231,7 @@ export const get_drive_files = async (req) => {
|
|
|
230
231
|
}
|
|
231
232
|
if (doc.type === 'directory') {
|
|
232
233
|
try {
|
|
233
|
-
const sizeInBytes = await get_folder_size(
|
|
234
|
+
const sizeInBytes = await get_folder_size(file_path, drive_type, app_id_reference, uid);
|
|
234
235
|
files.sizeInBytes += sizeInBytes;
|
|
235
236
|
files.children.push({
|
|
236
237
|
sizeInBytes,
|
|
@@ -259,7 +260,7 @@ export const get_drive_files = async (req) => {
|
|
|
259
260
|
|
|
260
261
|
const ret = await db_module.find_app_couch_query(app_id, opt);
|
|
261
262
|
|
|
262
|
-
const file_doc = await db_module.get_app_couch_doc(app_id, path.basename(
|
|
263
|
+
const file_doc = await db_module.get_app_couch_doc(app_id, path.basename(file_path) || '/');
|
|
263
264
|
|
|
264
265
|
const { data: app_obj } = await db_module.get_app_obj(app_id);
|
|
265
266
|
|
|
@@ -273,7 +274,7 @@ export const get_drive_files = async (req) => {
|
|
|
273
274
|
opt.selector.docType = 'user_drive';
|
|
274
275
|
opt.selector.uid = uid;
|
|
275
276
|
const ret = await db_module.find_couch_query('xuda_drive', opt);
|
|
276
|
-
const file_doc = await db_module.get_couch_doc('xuda_drive', path.basename(
|
|
277
|
+
const file_doc = await db_module.get_couch_doc('xuda_drive', path.basename(file_path) || '/');
|
|
277
278
|
return {
|
|
278
279
|
code: 1,
|
|
279
280
|
data: await fetch_drive_files(ret, file_doc, null, uid),
|
|
@@ -285,7 +286,7 @@ export const get_drive_files = async (req) => {
|
|
|
285
286
|
opt.selector.docType = 'studio_drive';
|
|
286
287
|
const ret = await db_module.find_app_couch_query(app_id, opt);
|
|
287
288
|
|
|
288
|
-
const file_doc = await db_module.get_app_couch_doc(app_id, path.basename(
|
|
289
|
+
const file_doc = await db_module.get_app_couch_doc(app_id, path.basename(file_path) || '/');
|
|
289
290
|
|
|
290
291
|
return {
|
|
291
292
|
code: 1,
|
|
@@ -295,7 +296,7 @@ export const get_drive_files = async (req) => {
|
|
|
295
296
|
|
|
296
297
|
const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
297
298
|
|
|
298
|
-
let directoryPath = path.join(_conf.studio_drive_path, app_id_master,
|
|
299
|
+
let directoryPath = path.join(_conf.studio_drive_path, app_id_master, file_path || '/');
|
|
299
300
|
|
|
300
301
|
const options = {
|
|
301
302
|
stat: true,
|
|
@@ -682,13 +683,13 @@ export const create_drive_folder = async (req, job_id, headers) => {
|
|
|
682
683
|
case 'studio': {
|
|
683
684
|
folder_id = req.folder_name;
|
|
684
685
|
const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
685
|
-
if (!
|
|
686
|
+
if (!file_path.includes(app_id_master)) {
|
|
686
687
|
return {
|
|
687
688
|
code: -1,
|
|
688
689
|
data: 'error - file path unauthorized',
|
|
689
690
|
};
|
|
690
691
|
}
|
|
691
|
-
target_dir =
|
|
692
|
+
target_dir = file_path + '/' + folder_id;
|
|
692
693
|
folder_exist = await file_exists(target_dir);
|
|
693
694
|
if (folder_exist) {
|
|
694
695
|
throw new Error('folder exist');
|
|
@@ -1011,7 +1012,7 @@ export const delete_file_bulk = async (req) => {
|
|
|
1011
1012
|
|
|
1012
1013
|
export const upload_drive_file = async (req, job_id, headers, file_obj) => {
|
|
1013
1014
|
try {
|
|
1014
|
-
const { drive_type, app_id, uid, make_public, tags = '', reserve } = req;
|
|
1015
|
+
const { drive_type, app_id, uid, make_public, tags = '', reserve, path: file_path } = req;
|
|
1015
1016
|
|
|
1016
1017
|
/// validations
|
|
1017
1018
|
validate_drive_type(drive_type);
|
|
@@ -1054,7 +1055,7 @@ export const upload_drive_file = async (req, job_id, headers, file_obj) => {
|
|
|
1054
1055
|
mime: file_obj.mimetype,
|
|
1055
1056
|
ocr_stat: ['image', 'application', 'text'].includes(file_obj.mimetype.split('/')[0]) ? 1 : 0,
|
|
1056
1057
|
target_file,
|
|
1057
|
-
file_path:
|
|
1058
|
+
file_path: file_path || '/',
|
|
1058
1059
|
size: stat.isFile() ? stat.size : 0,
|
|
1059
1060
|
public: make_public,
|
|
1060
1061
|
tags: tags_arr,
|
|
@@ -1103,7 +1104,7 @@ export const upload_drive_file = async (req, job_id, headers, file_obj) => {
|
|
|
1103
1104
|
case 'studio': {
|
|
1104
1105
|
ref = await _common.get_project_app_id(req.app_id, true);
|
|
1105
1106
|
const target_dir = path.join(_conf[`studio_drive_path`], ref);
|
|
1106
|
-
file_name = path.join(
|
|
1107
|
+
file_name = path.join(file_path, doc.originalname);
|
|
1107
1108
|
|
|
1108
1109
|
target_file = path.join(target_dir, file_name);
|
|
1109
1110
|
|