@xuda.io/drive_module 1.1.992 → 1.1.993
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 +175 -29
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -644,6 +644,151 @@ exports.get_drive_file_info = async function (req, job_id, headers) {
|
|
|
644
644
|
};
|
|
645
645
|
}
|
|
646
646
|
};
|
|
647
|
+
// exports.delete_drive_files = async function (req) {
|
|
648
|
+
// try {
|
|
649
|
+
// const { drive_type, app_id, files_arr } = req;
|
|
650
|
+
// validate_drive_type(drive_type);
|
|
651
|
+
|
|
652
|
+
// if (!Array.isArray(files_arr)) {
|
|
653
|
+
// return {
|
|
654
|
+
// code: -400,
|
|
655
|
+
// data: "error - files_arr must be Array",
|
|
656
|
+
// };
|
|
657
|
+
// }
|
|
658
|
+
|
|
659
|
+
// let doc_ret;
|
|
660
|
+
// for await (const file of files_arr) {
|
|
661
|
+
|
|
662
|
+
// let doc = await get_drive_doc(
|
|
663
|
+
// "file",
|
|
664
|
+
// drive_type,
|
|
665
|
+
// app_id,
|
|
666
|
+
// uid,
|
|
667
|
+
// file.file_path,
|
|
668
|
+
// headers
|
|
669
|
+
// );
|
|
670
|
+
|
|
671
|
+
// switch (drive_type) {
|
|
672
|
+
// case "studio": {
|
|
673
|
+
// const app_id_master = await _common.get_project_app_id(app_id);
|
|
674
|
+
// doc_ret = await db_module.get_app_couch_doc(
|
|
675
|
+
// app_id_master,
|
|
676
|
+
// path.basename(file.path)
|
|
677
|
+
// );
|
|
678
|
+
|
|
679
|
+
// const ret = rimraf.sync(file.path); // delete the file
|
|
680
|
+
// if (doc_ret.code > -1) {
|
|
681
|
+
// if (doc_ret.data.type === "directory") {
|
|
682
|
+
// const docs = await get_folder_docs(
|
|
683
|
+
// path.basename(file.path),
|
|
684
|
+
// drive_type,
|
|
685
|
+
// app_id_master
|
|
686
|
+
// );
|
|
687
|
+
// for await (let doc of docs) {
|
|
688
|
+
// doc._deleted = true;
|
|
689
|
+
// await db_module.save_app_couch_doc(app_id_master, doc);
|
|
690
|
+
// }
|
|
691
|
+
// }
|
|
692
|
+
|
|
693
|
+
// doc_ret.data._deleted = true;
|
|
694
|
+
// save_ret = await db_module.save_app_couch_doc(
|
|
695
|
+
// app_id_master,
|
|
696
|
+
// doc_ret.data
|
|
697
|
+
// );
|
|
698
|
+
// }
|
|
699
|
+
|
|
700
|
+
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
701
|
+
// "studio",
|
|
702
|
+
// app_id_master
|
|
703
|
+
// );
|
|
704
|
+
// break;
|
|
705
|
+
// }
|
|
706
|
+
|
|
707
|
+
// case "workspace": {
|
|
708
|
+
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
709
|
+
|
|
710
|
+
// doc_ret = await db_module.get_app_couch_doc(
|
|
711
|
+
// app_id_reference,
|
|
712
|
+
// path.basename(file.path)
|
|
713
|
+
// );
|
|
714
|
+
|
|
715
|
+
// if (doc_ret.data.type === "file") {
|
|
716
|
+
// await module.exports.delete_file_from_bucket(doc_ret.data.bucket);
|
|
717
|
+
// }
|
|
718
|
+
// if (doc_ret.data.type === "directory") {
|
|
719
|
+
// const docs = await get_folder_docs(
|
|
720
|
+
// path.basename(file.path),
|
|
721
|
+
// drive_type,
|
|
722
|
+
// app_id_reference
|
|
723
|
+
// );
|
|
724
|
+
// for await (let doc of docs) {
|
|
725
|
+
// if (doc.type === "file") {
|
|
726
|
+
// await module.exports.delete_file_from_bucket(doc.bucket);
|
|
727
|
+
// }
|
|
728
|
+
// doc.ts = Date.now();
|
|
729
|
+
// doc.stat = 4;
|
|
730
|
+
// await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
731
|
+
// }
|
|
732
|
+
// }
|
|
733
|
+
|
|
734
|
+
// doc_ret.data.ts = Date.now();
|
|
735
|
+
// doc_ret.data.stat = 4;
|
|
736
|
+
// save_ret = await db_module.save_app_couch_doc(
|
|
737
|
+
// app_id_reference,
|
|
738
|
+
// doc_ret.data
|
|
739
|
+
// );
|
|
740
|
+
|
|
741
|
+
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
742
|
+
// "workspace",
|
|
743
|
+
// app_id_reference
|
|
744
|
+
// );
|
|
745
|
+
// break;
|
|
746
|
+
// }
|
|
747
|
+
|
|
748
|
+
// case "user": {
|
|
749
|
+
// doc_ret = await db_module.get_couch_doc("xuda_drive", file.name);
|
|
750
|
+
// if (doc_ret.data.type === "file") {
|
|
751
|
+
// await module.exports.delete_file_from_bucket(doc_ret.data.bucket);
|
|
752
|
+
// }
|
|
753
|
+
// if (doc_ret.data.type === "directory") {
|
|
754
|
+
// const docs = await get_folder_docs(
|
|
755
|
+
// path.basename(file.path),
|
|
756
|
+
// drive_type,
|
|
757
|
+
// null
|
|
758
|
+
// );
|
|
759
|
+
// for await (let doc of docs) {
|
|
760
|
+
// if (doc.type === "file") {
|
|
761
|
+
// await module.exports.delete_file_from_bucket(doc.bucket);
|
|
762
|
+
// }
|
|
763
|
+
// doc.ts = Date.now();
|
|
764
|
+
// doc.stat = 4;
|
|
765
|
+
// await db_module.save_couch_doc("xuda_drive", doc);
|
|
766
|
+
// }
|
|
767
|
+
// }
|
|
768
|
+
// doc_ret.data.ts = Date.now();
|
|
769
|
+
// doc_ret.data.stat = 4;
|
|
770
|
+
// save_ret = await db_module.save_couch_doc("xuda_drive", doc_ret.data);
|
|
771
|
+
|
|
772
|
+
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
773
|
+
// "user",
|
|
774
|
+
// doc_ret.data.uid
|
|
775
|
+
// );
|
|
776
|
+
// break;
|
|
777
|
+
// }
|
|
778
|
+
// default:
|
|
779
|
+
// break;
|
|
780
|
+
// }
|
|
781
|
+
// }
|
|
782
|
+
|
|
783
|
+
// return {
|
|
784
|
+
// code: 200,
|
|
785
|
+
// data: req.files_arr,
|
|
786
|
+
// };
|
|
787
|
+
// } catch (err) {
|
|
788
|
+
// return { code: -1, data: err.message };
|
|
789
|
+
// }
|
|
790
|
+
// };
|
|
791
|
+
|
|
647
792
|
exports.delete_drive_files = async function (req) {
|
|
648
793
|
try {
|
|
649
794
|
const { drive_type, app_id, files_arr } = req;
|
|
@@ -658,6 +803,15 @@ exports.delete_drive_files = async function (req) {
|
|
|
658
803
|
|
|
659
804
|
let doc_ret;
|
|
660
805
|
for await (const file of files_arr) {
|
|
806
|
+
let doc = await get_drive_doc(
|
|
807
|
+
"file",
|
|
808
|
+
drive_type,
|
|
809
|
+
app_id,
|
|
810
|
+
uid,
|
|
811
|
+
file.file_path,
|
|
812
|
+
headers
|
|
813
|
+
);
|
|
814
|
+
|
|
661
815
|
switch (drive_type) {
|
|
662
816
|
case "studio": {
|
|
663
817
|
const app_id_master = await _common.get_project_app_id(app_id);
|
|
@@ -697,36 +851,28 @@ exports.delete_drive_files = async function (req) {
|
|
|
697
851
|
case "workspace": {
|
|
698
852
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
699
853
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
path.basename(file.path)
|
|
703
|
-
);
|
|
704
|
-
|
|
705
|
-
if (doc_ret.data.type === "file") {
|
|
706
|
-
await module.exports.delete_file_from_bucket(doc_ret.data.bucket);
|
|
707
|
-
}
|
|
708
|
-
if (doc_ret.data.type === "directory") {
|
|
709
|
-
const docs = await get_folder_docs(
|
|
710
|
-
path.basename(file.path),
|
|
711
|
-
drive_type,
|
|
712
|
-
app_id_reference
|
|
713
|
-
);
|
|
714
|
-
for await (let doc of docs) {
|
|
715
|
-
if (doc.type === "file") {
|
|
716
|
-
await module.exports.delete_file_from_bucket(doc.bucket);
|
|
717
|
-
}
|
|
718
|
-
doc.ts = Date.now();
|
|
719
|
-
doc.stat = 4;
|
|
720
|
-
await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
721
|
-
}
|
|
854
|
+
if (doc.type === "file") {
|
|
855
|
+
await module.exports.delete_file_from_bucket(doc.bucket);
|
|
722
856
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
)
|
|
857
|
+
// if (doc_ret.data.type === "directory") {
|
|
858
|
+
// const docs = await get_folder_docs(
|
|
859
|
+
// path.basename(file.path),
|
|
860
|
+
// drive_type,
|
|
861
|
+
// app_id_reference
|
|
862
|
+
// );
|
|
863
|
+
// for await (let doc of docs) {
|
|
864
|
+
// if (doc.type === "file") {
|
|
865
|
+
// await module.exports.delete_file_from_bucket(doc.bucket);
|
|
866
|
+
// }
|
|
867
|
+
// doc.ts = Date.now();
|
|
868
|
+
// doc.stat = 4;
|
|
869
|
+
// await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
870
|
+
// }
|
|
871
|
+
// }
|
|
872
|
+
|
|
873
|
+
doc.ts = Date.now();
|
|
874
|
+
doc.stat = 4;
|
|
875
|
+
save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
730
876
|
|
|
731
877
|
misc_module.rsync_drive_resources_to_remote_servers(
|
|
732
878
|
"workspace",
|