@xuda.io/drive_module 1.1.1467 → 1.1.1469
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 +66 -100
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -482,104 +482,6 @@ const get_folder_files = async function (uid, app_id, drive_type, path) {
|
|
|
482
482
|
return [...(files_ret.data.children || []), ...(directory_ret.data.children || [])];
|
|
483
483
|
};
|
|
484
484
|
|
|
485
|
-
// export const delete_drive_files = async (req, job_id, headers) => {
|
|
486
|
-
// try {
|
|
487
|
-
// const { drive_type, app_id, files_arr, uid } = req;
|
|
488
|
-
// validate_drive_type(drive_type);
|
|
489
|
-
|
|
490
|
-
// if (!Array.isArray(files_arr)) {
|
|
491
|
-
// return {
|
|
492
|
-
// code: -400,
|
|
493
|
-
// data: 'error - files_arr must be Array',
|
|
494
|
-
// };
|
|
495
|
-
// }
|
|
496
|
-
|
|
497
|
-
// for await (const file of files_arr) {
|
|
498
|
-
// let doc = await get_drive_doc(file.type, drive_type, app_id, uid, file.file_path, headers);
|
|
499
|
-
|
|
500
|
-
// // if (doc.is_system) {
|
|
501
|
-
// // throw new Error(`${doc.type} protected`);
|
|
502
|
-
// // }
|
|
503
|
-
|
|
504
|
-
// if (doc.type === 'directory') {
|
|
505
|
-
// const files_in_directory = await get_folder_files(uid, app_id, drive_type, path.join(doc.file_path, doc.folder_name));
|
|
506
|
-
// if (files_in_directory?.length) {
|
|
507
|
-
// throw new Error(`Directory is not empty`);
|
|
508
|
-
// }
|
|
509
|
-
// }
|
|
510
|
-
|
|
511
|
-
// let save_ret;
|
|
512
|
-
// switch (drive_type) {
|
|
513
|
-
// case 'studio': {
|
|
514
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
515
|
-
// const target_dir = path.join(_conf[`studio_drive_path`], app_id_reference, file.file_path);
|
|
516
|
-
// console.log('target_dir', target_dir);
|
|
517
|
-
// rimraf.sync(target_dir);
|
|
518
|
-
|
|
519
|
-
// if (doc.type === 'file') {
|
|
520
|
-
// doc.ts = Date.now();
|
|
521
|
-
// doc.stat = 4;
|
|
522
|
-
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
523
|
-
// }
|
|
524
|
-
|
|
525
|
-
// misc_msa.rsync_drive_resources_to_remote_servers('studio', app_id_reference);
|
|
526
|
-
// break;
|
|
527
|
-
// }
|
|
528
|
-
|
|
529
|
-
// case 'workspace': {
|
|
530
|
-
// // const app_id_reference = await _common.get_project_app_id(app_id);
|
|
531
|
-
|
|
532
|
-
// if (doc.type === 'file') {
|
|
533
|
-
// try {
|
|
534
|
-
// if (doc.bucket) {
|
|
535
|
-
// await delete_file_from_bucket(doc.bucket);
|
|
536
|
-
// } else {
|
|
537
|
-
// const { data: app_obj } = await db_module.get_app_obj(app_id);
|
|
538
|
-
// if (app_obj?.app_type === 'datacenter') {
|
|
539
|
-
// const host = `root@${app_obj.app_hosting_server.ip}`;
|
|
540
|
-
// await _utils.run_ssh_script(`ssh ${host} "mv /var/xuda/workspace_drive/${doc.server_file_name} /tmp/;" `);
|
|
541
|
-
// } else if (app_obj?.is_deployment) {
|
|
542
|
-
// const { data: datacenter_obj } = await db_module.get_app_obj(app_obj.app_datacenter_id);
|
|
543
|
-
// const host = `root@${datacenter_obj.app_hosting_server.ip}`;
|
|
544
|
-
// await _utils.run_ssh_script(`ssh ${host} "mv /var/xuda/workspace_drive/${doc.server_file_name} /tmp/;" `);
|
|
545
|
-
// }
|
|
546
|
-
// }
|
|
547
|
-
// } catch (error) {}
|
|
548
|
-
// }
|
|
549
|
-
|
|
550
|
-
// doc.ts = Date.now();
|
|
551
|
-
// doc.stat = 4;
|
|
552
|
-
// save_ret = await save_drive_doc(drive_type, uid, app_id, doc);
|
|
553
|
-
|
|
554
|
-
// break;
|
|
555
|
-
// }
|
|
556
|
-
|
|
557
|
-
// case 'user': {
|
|
558
|
-
// if (doc.type === 'file') {
|
|
559
|
-
// try {
|
|
560
|
-
// await delete_file_from_bucket(doc.bucket);
|
|
561
|
-
// } catch (error) {}
|
|
562
|
-
// }
|
|
563
|
-
// doc.ts = Date.now();
|
|
564
|
-
// doc.stat = 4;
|
|
565
|
-
// save_ret = await save_drive_doc(drive_type, uid, app_id, doc);
|
|
566
|
-
|
|
567
|
-
// break;
|
|
568
|
-
// }
|
|
569
|
-
// default:
|
|
570
|
-
// break;
|
|
571
|
-
// }
|
|
572
|
-
// }
|
|
573
|
-
|
|
574
|
-
// return {
|
|
575
|
-
// code: 200,
|
|
576
|
-
// data: req.files_arr,
|
|
577
|
-
// };
|
|
578
|
-
// } catch (err) {
|
|
579
|
-
// return { code: -1, data: err.message };
|
|
580
|
-
// }
|
|
581
|
-
// };
|
|
582
|
-
|
|
583
485
|
export const delete_drive_files = async (req, job_id, headers) => {
|
|
584
486
|
let ret = [];
|
|
585
487
|
try {
|
|
@@ -1386,7 +1288,7 @@ export const upload_drive_file = async (req, job_id, headers = {}, file_obj) =>
|
|
|
1386
1288
|
return { code: -400, data: err.message };
|
|
1387
1289
|
}
|
|
1388
1290
|
};
|
|
1389
|
-
|
|
1291
|
+
const check_single_drive_file = async (req, job_id, headers, file_obj) => {
|
|
1390
1292
|
const { type = 'file', drive_type, app_id, uid, file_path, folder_name } = req;
|
|
1391
1293
|
|
|
1392
1294
|
let master_app_id;
|
|
@@ -1399,7 +1301,6 @@ export const check_drive_file = async (req, job_id, headers, file_obj) => {
|
|
|
1399
1301
|
type,
|
|
1400
1302
|
file_path: path.dirname(file_path),
|
|
1401
1303
|
stat: 3,
|
|
1402
|
-
// uid,
|
|
1403
1304
|
};
|
|
1404
1305
|
|
|
1405
1306
|
if (type === 'file') {
|
|
@@ -1481,6 +1382,59 @@ export const check_drive_file = async (req, job_id, headers, file_obj) => {
|
|
|
1481
1382
|
};
|
|
1482
1383
|
};
|
|
1483
1384
|
|
|
1385
|
+
export const check_drive_files = async (req, job_id, headers, file_obj) => {
|
|
1386
|
+
const files = req.files ||
|
|
1387
|
+
req.file_paths?.map((curr_file_path) => ({
|
|
1388
|
+
file_path: curr_file_path,
|
|
1389
|
+
})) || [
|
|
1390
|
+
{
|
|
1391
|
+
file_path: req.file_path,
|
|
1392
|
+
folder_name: req.folder_name,
|
|
1393
|
+
type: req.type,
|
|
1394
|
+
},
|
|
1395
|
+
];
|
|
1396
|
+
|
|
1397
|
+
const results = [];
|
|
1398
|
+
|
|
1399
|
+
for (const item of files) {
|
|
1400
|
+
results.push(
|
|
1401
|
+
await check_single_drive_file(
|
|
1402
|
+
{
|
|
1403
|
+
...req,
|
|
1404
|
+
...item,
|
|
1405
|
+
},
|
|
1406
|
+
job_id,
|
|
1407
|
+
headers,
|
|
1408
|
+
file_obj,
|
|
1409
|
+
),
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
const duplicates = results.flatMap((item) => item?.duplicates || []);
|
|
1414
|
+
const has_duplicates = results.some((item) => item?.code < 0);
|
|
1415
|
+
|
|
1416
|
+
return {
|
|
1417
|
+
code: has_duplicates ? -764 : 764,
|
|
1418
|
+
data: has_duplicates ? 'one or more files exist' : 'ok',
|
|
1419
|
+
files: results,
|
|
1420
|
+
duplicates,
|
|
1421
|
+
};
|
|
1422
|
+
};
|
|
1423
|
+
|
|
1424
|
+
export const check_drive_file = async (req, job_id, headers, file_obj) => {
|
|
1425
|
+
const ret = await check_drive_files(req, job_id, headers, file_obj);
|
|
1426
|
+
|
|
1427
|
+
if (!ret.files?.length) {
|
|
1428
|
+
return {
|
|
1429
|
+
code: -764,
|
|
1430
|
+
data: 'no files to check',
|
|
1431
|
+
duplicates: [],
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
return ret.files[0];
|
|
1436
|
+
};
|
|
1437
|
+
|
|
1484
1438
|
const ocr_drive_file = async (app_id, doc) => {
|
|
1485
1439
|
const { drive_type, uid, file_path, originalname } = doc;
|
|
1486
1440
|
|
|
@@ -2410,14 +2364,26 @@ export const check_drive_file_workspace = async (req, job_id, headers, file_obj)
|
|
|
2410
2364
|
req.drive_type = 'workspace';
|
|
2411
2365
|
return await check_drive_file(req, job_id, headers, file_obj);
|
|
2412
2366
|
};
|
|
2367
|
+
export const check_drive_files_workspace = async (req, job_id, headers, file_obj) => {
|
|
2368
|
+
req.drive_type = 'workspace';
|
|
2369
|
+
return await check_drive_files(req, job_id, headers, file_obj);
|
|
2370
|
+
};
|
|
2413
2371
|
export const check_drive_file_studio = async (req, job_id, headers, file_obj) => {
|
|
2414
2372
|
req.drive_type = 'studio';
|
|
2415
2373
|
return await check_drive_file(req, job_id, headers, file_obj);
|
|
2416
2374
|
};
|
|
2375
|
+
export const check_drive_files_studio = async (req, job_id, headers, file_obj) => {
|
|
2376
|
+
req.drive_type = 'studio';
|
|
2377
|
+
return await check_drive_files(req, job_id, headers, file_obj);
|
|
2378
|
+
};
|
|
2417
2379
|
export const check_drive_file_user = async (req, job_id, headers, file_obj) => {
|
|
2418
2380
|
req.drive_type = 'user';
|
|
2419
2381
|
return await check_drive_file(req, job_id, headers, file_obj);
|
|
2420
2382
|
};
|
|
2383
|
+
export const check_drive_files_user = async (req, job_id, headers, file_obj) => {
|
|
2384
|
+
req.drive_type = 'user';
|
|
2385
|
+
return await check_drive_files(req, job_id, headers, file_obj);
|
|
2386
|
+
};
|
|
2421
2387
|
|
|
2422
2388
|
export const update_drive_file_tags_workspace = async (req, job_id, headers, file_obj) => {
|
|
2423
2389
|
req.drive_type = 'workspace';
|