@xuda.io/drive_module 1.1.991 → 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 +176 -29
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ global._conf = require(path.join(
|
|
|
3
3
|
process.env.XUDA_HOME,
|
|
4
4
|
process.env.XUDA_CONFIG
|
|
5
5
|
));
|
|
6
|
+
console.log("drive module loaded..");
|
|
6
7
|
|
|
7
8
|
const _common = require(path.join(
|
|
8
9
|
process.env.XUDA_HOME,
|
|
@@ -643,6 +644,151 @@ exports.get_drive_file_info = async function (req, job_id, headers) {
|
|
|
643
644
|
};
|
|
644
645
|
}
|
|
645
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
|
+
|
|
646
792
|
exports.delete_drive_files = async function (req) {
|
|
647
793
|
try {
|
|
648
794
|
const { drive_type, app_id, files_arr } = req;
|
|
@@ -657,6 +803,15 @@ exports.delete_drive_files = async function (req) {
|
|
|
657
803
|
|
|
658
804
|
let doc_ret;
|
|
659
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
|
+
|
|
660
815
|
switch (drive_type) {
|
|
661
816
|
case "studio": {
|
|
662
817
|
const app_id_master = await _common.get_project_app_id(app_id);
|
|
@@ -696,36 +851,28 @@ exports.delete_drive_files = async function (req) {
|
|
|
696
851
|
case "workspace": {
|
|
697
852
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
698
853
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
path.basename(file.path)
|
|
702
|
-
);
|
|
703
|
-
|
|
704
|
-
if (doc_ret.data.type === "file") {
|
|
705
|
-
await module.exports.delete_file_from_bucket(doc_ret.data.bucket);
|
|
706
|
-
}
|
|
707
|
-
if (doc_ret.data.type === "directory") {
|
|
708
|
-
const docs = await get_folder_docs(
|
|
709
|
-
path.basename(file.path),
|
|
710
|
-
drive_type,
|
|
711
|
-
app_id_reference
|
|
712
|
-
);
|
|
713
|
-
for await (let doc of docs) {
|
|
714
|
-
if (doc.type === "file") {
|
|
715
|
-
await module.exports.delete_file_from_bucket(doc.bucket);
|
|
716
|
-
}
|
|
717
|
-
doc.ts = Date.now();
|
|
718
|
-
doc.stat = 4;
|
|
719
|
-
await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
720
|
-
}
|
|
854
|
+
if (doc.type === "file") {
|
|
855
|
+
await module.exports.delete_file_from_bucket(doc.bucket);
|
|
721
856
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
)
|
|
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);
|
|
729
876
|
|
|
730
877
|
misc_module.rsync_drive_resources_to_remote_servers(
|
|
731
878
|
"workspace",
|