@xuda.io/drive_module 1.1.1418 → 1.1.1420
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 +109 -5
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -476,6 +476,104 @@ const get_folder_files = async function (uid, app_id, drive_type, path) {
|
|
|
476
476
|
return [...(files_ret.data.children || []), ...(directory_ret.data.children || [])];
|
|
477
477
|
};
|
|
478
478
|
|
|
479
|
+
// export const delete_drive_files = async (req, job_id, headers) => {
|
|
480
|
+
// try {
|
|
481
|
+
// const { drive_type, app_id, files_arr, uid } = req;
|
|
482
|
+
// validate_drive_type(drive_type);
|
|
483
|
+
|
|
484
|
+
// if (!Array.isArray(files_arr)) {
|
|
485
|
+
// return {
|
|
486
|
+
// code: -400,
|
|
487
|
+
// data: 'error - files_arr must be Array',
|
|
488
|
+
// };
|
|
489
|
+
// }
|
|
490
|
+
|
|
491
|
+
// for await (const file of files_arr) {
|
|
492
|
+
// let doc = await get_drive_doc(file.type, drive_type, app_id, uid, file.file_path, headers);
|
|
493
|
+
|
|
494
|
+
// // if (doc.is_system) {
|
|
495
|
+
// // throw new Error(`${doc.type} protected`);
|
|
496
|
+
// // }
|
|
497
|
+
|
|
498
|
+
// if (doc.type === 'directory') {
|
|
499
|
+
// const files_in_directory = await get_folder_files(uid, app_id, drive_type, path.join(doc.file_path, doc.folder_name));
|
|
500
|
+
// if (files_in_directory?.length) {
|
|
501
|
+
// throw new Error(`Directory is not empty`);
|
|
502
|
+
// }
|
|
503
|
+
// }
|
|
504
|
+
|
|
505
|
+
// let save_ret;
|
|
506
|
+
// switch (drive_type) {
|
|
507
|
+
// case 'studio': {
|
|
508
|
+
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
509
|
+
// const target_dir = path.join(_conf[`studio_drive_path`], app_id_reference, file.file_path);
|
|
510
|
+
// console.log('target_dir', target_dir);
|
|
511
|
+
// rimraf.sync(target_dir);
|
|
512
|
+
|
|
513
|
+
// if (doc.type === 'file') {
|
|
514
|
+
// doc.ts = Date.now();
|
|
515
|
+
// doc.stat = 4;
|
|
516
|
+
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
517
|
+
// }
|
|
518
|
+
|
|
519
|
+
// misc_msa.rsync_drive_resources_to_remote_servers('studio', app_id_reference);
|
|
520
|
+
// break;
|
|
521
|
+
// }
|
|
522
|
+
|
|
523
|
+
// case 'workspace': {
|
|
524
|
+
// // const app_id_reference = await _common.get_project_app_id(app_id);
|
|
525
|
+
|
|
526
|
+
// if (doc.type === 'file') {
|
|
527
|
+
// try {
|
|
528
|
+
// if (doc.bucket) {
|
|
529
|
+
// await delete_file_from_bucket(doc.bucket);
|
|
530
|
+
// } else {
|
|
531
|
+
// const { data: app_obj } = await db_module.get_app_obj(app_id);
|
|
532
|
+
// if (app_obj?.app_type === 'datacenter') {
|
|
533
|
+
// const host = `root@${app_obj.app_hosting_server.ip}`;
|
|
534
|
+
// await _utils.run_ssh_script(`ssh ${host} "mv /var/xuda/workspace_drive/${doc.server_file_name} /tmp/;" `);
|
|
535
|
+
// } else if (app_obj?.is_deployment) {
|
|
536
|
+
// const { data: datacenter_obj } = await db_module.get_app_obj(app_obj.app_datacenter_id);
|
|
537
|
+
// const host = `root@${datacenter_obj.app_hosting_server.ip}`;
|
|
538
|
+
// await _utils.run_ssh_script(`ssh ${host} "mv /var/xuda/workspace_drive/${doc.server_file_name} /tmp/;" `);
|
|
539
|
+
// }
|
|
540
|
+
// }
|
|
541
|
+
// } catch (error) {}
|
|
542
|
+
// }
|
|
543
|
+
|
|
544
|
+
// doc.ts = Date.now();
|
|
545
|
+
// doc.stat = 4;
|
|
546
|
+
// save_ret = await save_drive_doc(drive_type, uid, app_id, doc);
|
|
547
|
+
|
|
548
|
+
// break;
|
|
549
|
+
// }
|
|
550
|
+
|
|
551
|
+
// case 'user': {
|
|
552
|
+
// if (doc.type === 'file') {
|
|
553
|
+
// try {
|
|
554
|
+
// await delete_file_from_bucket(doc.bucket);
|
|
555
|
+
// } catch (error) {}
|
|
556
|
+
// }
|
|
557
|
+
// doc.ts = Date.now();
|
|
558
|
+
// doc.stat = 4;
|
|
559
|
+
// save_ret = await save_drive_doc(drive_type, uid, app_id, doc);
|
|
560
|
+
|
|
561
|
+
// break;
|
|
562
|
+
// }
|
|
563
|
+
// default:
|
|
564
|
+
// break;
|
|
565
|
+
// }
|
|
566
|
+
// }
|
|
567
|
+
|
|
568
|
+
// return {
|
|
569
|
+
// code: 200,
|
|
570
|
+
// data: req.files_arr,
|
|
571
|
+
// };
|
|
572
|
+
// } catch (err) {
|
|
573
|
+
// return { code: -1, data: err.message };
|
|
574
|
+
// }
|
|
575
|
+
// };
|
|
576
|
+
|
|
479
577
|
export const delete_drive_files = async (req, job_id, headers) => {
|
|
480
578
|
try {
|
|
481
579
|
const { drive_type, app_id, files_arr, uid } = req;
|
|
@@ -488,12 +586,16 @@ export const delete_drive_files = async (req, job_id, headers) => {
|
|
|
488
586
|
};
|
|
489
587
|
}
|
|
490
588
|
|
|
589
|
+
// get docs
|
|
590
|
+
let docs = [];
|
|
491
591
|
for await (const file of files_arr) {
|
|
492
|
-
|
|
592
|
+
try {
|
|
593
|
+
docs.push(await get_drive_doc(file.type, drive_type, app_id, uid, file.file_path, headers));
|
|
594
|
+
} catch (error) {}
|
|
595
|
+
}
|
|
493
596
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
// }
|
|
597
|
+
for await (const file of files_arr) {
|
|
598
|
+
let doc = await get_drive_doc(file.type, drive_type, app_id, uid, file.file_path, headers);
|
|
497
599
|
|
|
498
600
|
if (doc.type === 'directory') {
|
|
499
601
|
const files_in_directory = await get_folder_files(uid, app_id, drive_type, path.join(doc.file_path, doc.folder_name));
|
|
@@ -550,7 +652,9 @@ export const delete_drive_files = async (req, job_id, headers) => {
|
|
|
550
652
|
|
|
551
653
|
case 'user': {
|
|
552
654
|
if (doc.type === 'file') {
|
|
553
|
-
|
|
655
|
+
try {
|
|
656
|
+
await delete_file_from_bucket(doc.bucket);
|
|
657
|
+
} catch (error) {}
|
|
554
658
|
}
|
|
555
659
|
doc.ts = Date.now();
|
|
556
660
|
doc.stat = 4;
|