@xuda.io/drive_module 1.1.796 → 1.1.798
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 +218 -106
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -679,6 +679,165 @@ exports.delete_drive_files = async function (req) {
|
|
|
679
679
|
}
|
|
680
680
|
};
|
|
681
681
|
|
|
682
|
+
// exports.update_drive_file = async function (req, job_id, headers, file_obj) {
|
|
683
|
+
// try {
|
|
684
|
+
// const { drive_type, app_id, file_path, uid } = req;
|
|
685
|
+
// validate_drive_type(drive_type);
|
|
686
|
+
|
|
687
|
+
// const originalname = file_obj?.["originalname"];
|
|
688
|
+
|
|
689
|
+
// const file_name = path.basename(file_path);
|
|
690
|
+
|
|
691
|
+
// if (!originalname) {
|
|
692
|
+
// return { code: -4, data: "file data missing" };
|
|
693
|
+
// }
|
|
694
|
+
|
|
695
|
+
// let check_req = {
|
|
696
|
+
// app_id,
|
|
697
|
+
// uid,
|
|
698
|
+
// drive_type,
|
|
699
|
+
|
|
700
|
+
// file_path,
|
|
701
|
+
// };
|
|
702
|
+
// const check_existing_file_ret = await module.exports.check_drive_file(
|
|
703
|
+
// check_req
|
|
704
|
+
// );
|
|
705
|
+
|
|
706
|
+
// if (check_existing_file_ret.code > -1) {
|
|
707
|
+
// return { code: -5, data: "file not exit" };
|
|
708
|
+
// }
|
|
709
|
+
|
|
710
|
+
// var target_file = file_path;
|
|
711
|
+
// const master_id = await _common.get_project_app_id(app_id, true);
|
|
712
|
+
// const tempPath = file_obj.path;
|
|
713
|
+
// if (drive_type === "studio") {
|
|
714
|
+
// const target_dir = path.join(
|
|
715
|
+
// _conf[`studio_drive_path`],
|
|
716
|
+
// master_id,
|
|
717
|
+
// target_file
|
|
718
|
+
// );
|
|
719
|
+
// try {
|
|
720
|
+
// fse.unlinkSync(target_dir);
|
|
721
|
+
// } catch (error) {}
|
|
722
|
+
|
|
723
|
+
// fse.copyFileSync(tempPath, target_dir);
|
|
724
|
+
// }
|
|
725
|
+
|
|
726
|
+
// let doc_ret;
|
|
727
|
+
|
|
728
|
+
// switch (drive_type) {
|
|
729
|
+
// case "studio": {
|
|
730
|
+
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
731
|
+
// doc_ret = await db_module.get_app_couch_doc(
|
|
732
|
+
// app_id_reference,
|
|
733
|
+
// target_file
|
|
734
|
+
// );
|
|
735
|
+
// break;
|
|
736
|
+
// }
|
|
737
|
+
// case "workspace": {
|
|
738
|
+
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
739
|
+
// doc_ret = await db_module.get_app_couch_doc(
|
|
740
|
+
// app_id_reference,
|
|
741
|
+
// check_existing_file_ret.duplicates[0]._id
|
|
742
|
+
// );
|
|
743
|
+
// break;
|
|
744
|
+
// }
|
|
745
|
+
// case "user":
|
|
746
|
+
// doc_ret = await db_module.get_couch_doc(
|
|
747
|
+
// "xuda_drive",
|
|
748
|
+
// check_existing_file_ret.duplicates[0]._id
|
|
749
|
+
// );
|
|
750
|
+
// break;
|
|
751
|
+
|
|
752
|
+
// default:
|
|
753
|
+
// break;
|
|
754
|
+
// }
|
|
755
|
+
|
|
756
|
+
// if (doc_ret.code > -1) {
|
|
757
|
+
// var doc = doc_ret.data;
|
|
758
|
+
// doc.date_modified = Date.now();
|
|
759
|
+
|
|
760
|
+
// const fs = require("fs").promises;
|
|
761
|
+
// const stat = await fs.stat(tempPath);
|
|
762
|
+
// if (stat.isFile()) {
|
|
763
|
+
// doc.size = stat.size;
|
|
764
|
+
// }
|
|
765
|
+
|
|
766
|
+
// doc = { ...doc, ...(await get_file_info(tempPath)) };
|
|
767
|
+
|
|
768
|
+
// let save_ret;
|
|
769
|
+
|
|
770
|
+
// switch (drive_type) {
|
|
771
|
+
// case "studio": {
|
|
772
|
+
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
773
|
+
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
774
|
+
|
|
775
|
+
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
776
|
+
// "studio",
|
|
777
|
+
// app_id_reference
|
|
778
|
+
// );
|
|
779
|
+
// break;
|
|
780
|
+
// }
|
|
781
|
+
// case "workspace": {
|
|
782
|
+
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
783
|
+
// const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
784
|
+
|
|
785
|
+
// doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
786
|
+
// await upload_file_to_spaces(
|
|
787
|
+
// tempPath,
|
|
788
|
+
// app_id_master,
|
|
789
|
+
// drive_type,
|
|
790
|
+
// file_name
|
|
791
|
+
// );
|
|
792
|
+
|
|
793
|
+
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
794
|
+
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
795
|
+
// "workspace",
|
|
796
|
+
// app_id_master
|
|
797
|
+
// );
|
|
798
|
+
// break;
|
|
799
|
+
// }
|
|
800
|
+
// case "user": {
|
|
801
|
+
// doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
802
|
+
// await upload_file_to_spaces(tempPath, uid, drive_type, file_name);
|
|
803
|
+
// save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
804
|
+
// misc_module.rsync_drive_resources_to_remote_servers("user", doc.uid);
|
|
805
|
+
// break;
|
|
806
|
+
// }
|
|
807
|
+
// default:
|
|
808
|
+
// break;
|
|
809
|
+
// }
|
|
810
|
+
|
|
811
|
+
// fse.unlinkSync(tempPath);
|
|
812
|
+
|
|
813
|
+
// if (save_ret.code < 0) {
|
|
814
|
+
// return save_ret;
|
|
815
|
+
// }
|
|
816
|
+
// const server_file_name = `https://${
|
|
817
|
+
// process.env.XUDA_HOSTNAME
|
|
818
|
+
// }/${drive_type}-drive${
|
|
819
|
+
// drive_type === "studio" ? `/${master_id}/${target_file}` : file_name
|
|
820
|
+
// }`;
|
|
821
|
+
|
|
822
|
+
// misc_module.purge_cloudflare_cache(false, server_file_name);
|
|
823
|
+
// return {
|
|
824
|
+
// code: 760,
|
|
825
|
+
// data: {
|
|
826
|
+
// server_file_name,
|
|
827
|
+
// filename: file_obj.originalname,
|
|
828
|
+
// },
|
|
829
|
+
// };
|
|
830
|
+
// } else {
|
|
831
|
+
// return {
|
|
832
|
+
// code: -760,
|
|
833
|
+
// data: "file not found",
|
|
834
|
+
// };
|
|
835
|
+
// }
|
|
836
|
+
// } catch (err) {
|
|
837
|
+
// return { code: -400, data: err };
|
|
838
|
+
// }
|
|
839
|
+
// };
|
|
840
|
+
|
|
682
841
|
exports.update_drive_file = async function (req, job_id, headers, file_obj) {
|
|
683
842
|
try {
|
|
684
843
|
const { drive_type, app_id, file_path, uid } = req;
|
|
@@ -692,20 +851,7 @@ exports.update_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
692
851
|
return { code: -4, data: "file data missing" };
|
|
693
852
|
}
|
|
694
853
|
|
|
695
|
-
let
|
|
696
|
-
app_id,
|
|
697
|
-
uid,
|
|
698
|
-
drive_type,
|
|
699
|
-
|
|
700
|
-
file_path,
|
|
701
|
-
};
|
|
702
|
-
const check_existing_file_ret = await module.exports.check_drive_file(
|
|
703
|
-
check_req
|
|
704
|
-
);
|
|
705
|
-
|
|
706
|
-
if (check_existing_file_ret.code > -1) {
|
|
707
|
-
return { code: -5, data: "file not exit" };
|
|
708
|
-
}
|
|
854
|
+
let doc = await get_drive_doc(drive_type, app_id, uid, file_path, headers);
|
|
709
855
|
|
|
710
856
|
var target_file = file_path;
|
|
711
857
|
const master_id = await _common.get_project_app_id(app_id, true);
|
|
@@ -714,7 +860,7 @@ exports.update_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
714
860
|
const target_dir = path.join(
|
|
715
861
|
_conf[`studio_drive_path`],
|
|
716
862
|
master_id,
|
|
717
|
-
|
|
863
|
+
file_path
|
|
718
864
|
);
|
|
719
865
|
try {
|
|
720
866
|
fse.unlinkSync(target_dir);
|
|
@@ -725,114 +871,78 @@ exports.update_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
725
871
|
|
|
726
872
|
let doc_ret;
|
|
727
873
|
|
|
874
|
+
doc.date_modified = Date.now();
|
|
875
|
+
|
|
876
|
+
const fs = require("fs").promises;
|
|
877
|
+
const stat = await fs.stat(tempPath);
|
|
878
|
+
if (stat.isFile()) {
|
|
879
|
+
doc.size = stat.size;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
doc = { ...doc, ...(await get_file_info(tempPath)) };
|
|
883
|
+
|
|
884
|
+
let save_ret;
|
|
885
|
+
|
|
728
886
|
switch (drive_type) {
|
|
729
887
|
case "studio": {
|
|
730
888
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
889
|
+
save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
890
|
+
|
|
891
|
+
misc_module.rsync_drive_resources_to_remote_servers(
|
|
892
|
+
"studio",
|
|
893
|
+
app_id_reference
|
|
734
894
|
);
|
|
735
895
|
break;
|
|
736
896
|
}
|
|
737
897
|
case "workspace": {
|
|
738
898
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
899
|
+
const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
900
|
+
|
|
901
|
+
doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
902
|
+
await upload_file_to_spaces(
|
|
903
|
+
tempPath,
|
|
904
|
+
app_id_master,
|
|
905
|
+
drive_type,
|
|
906
|
+
file_name
|
|
907
|
+
);
|
|
908
|
+
|
|
909
|
+
save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
910
|
+
misc_module.rsync_drive_resources_to_remote_servers(
|
|
911
|
+
"workspace",
|
|
912
|
+
app_id_master
|
|
742
913
|
);
|
|
743
914
|
break;
|
|
744
915
|
}
|
|
745
|
-
case "user":
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
);
|
|
916
|
+
case "user": {
|
|
917
|
+
doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
918
|
+
await upload_file_to_spaces(tempPath, uid, drive_type, file_name);
|
|
919
|
+
save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
920
|
+
misc_module.rsync_drive_resources_to_remote_servers("user", doc.uid);
|
|
750
921
|
break;
|
|
751
|
-
|
|
922
|
+
}
|
|
752
923
|
default:
|
|
753
924
|
break;
|
|
754
925
|
}
|
|
755
926
|
|
|
756
|
-
|
|
757
|
-
var doc = doc_ret.data;
|
|
758
|
-
doc.date_modified = Date.now();
|
|
759
|
-
|
|
760
|
-
const fs = require("fs").promises;
|
|
761
|
-
const stat = await fs.stat(tempPath);
|
|
762
|
-
if (stat.isFile()) {
|
|
763
|
-
doc.size = stat.size;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
doc = { ...doc, ...(await get_file_info(tempPath)) };
|
|
767
|
-
|
|
768
|
-
let save_ret;
|
|
769
|
-
|
|
770
|
-
switch (drive_type) {
|
|
771
|
-
case "studio": {
|
|
772
|
-
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
773
|
-
save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
774
|
-
|
|
775
|
-
misc_module.rsync_drive_resources_to_remote_servers(
|
|
776
|
-
"studio",
|
|
777
|
-
app_id_reference
|
|
778
|
-
);
|
|
779
|
-
break;
|
|
780
|
-
}
|
|
781
|
-
case "workspace": {
|
|
782
|
-
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
783
|
-
const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
784
|
-
|
|
785
|
-
doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
786
|
-
await upload_file_to_spaces(
|
|
787
|
-
tempPath,
|
|
788
|
-
app_id_master,
|
|
789
|
-
drive_type,
|
|
790
|
-
file_name
|
|
791
|
-
);
|
|
792
|
-
|
|
793
|
-
save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
794
|
-
misc_module.rsync_drive_resources_to_remote_servers(
|
|
795
|
-
"workspace",
|
|
796
|
-
app_id_master
|
|
797
|
-
);
|
|
798
|
-
break;
|
|
799
|
-
}
|
|
800
|
-
case "user": {
|
|
801
|
-
doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
802
|
-
await upload_file_to_spaces(tempPath, uid, drive_type, file_name);
|
|
803
|
-
save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
804
|
-
misc_module.rsync_drive_resources_to_remote_servers("user", doc.uid);
|
|
805
|
-
break;
|
|
806
|
-
}
|
|
807
|
-
default:
|
|
808
|
-
break;
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
fse.unlinkSync(tempPath);
|
|
927
|
+
fse.unlinkSync(tempPath);
|
|
812
928
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
const server_file_name = `https://${
|
|
817
|
-
process.env.XUDA_HOSTNAME
|
|
818
|
-
}/${drive_type}-drive${
|
|
819
|
-
drive_type === "studio" ? `/${master_id}/${target_file}` : file_name
|
|
820
|
-
}`;
|
|
821
|
-
|
|
822
|
-
misc_module.purge_cloudflare_cache(false, server_file_name);
|
|
823
|
-
return {
|
|
824
|
-
code: 760,
|
|
825
|
-
data: {
|
|
826
|
-
server_file_name,
|
|
827
|
-
filename: file_obj.originalname,
|
|
828
|
-
},
|
|
829
|
-
};
|
|
830
|
-
} else {
|
|
831
|
-
return {
|
|
832
|
-
code: -760,
|
|
833
|
-
data: "file not found",
|
|
834
|
-
};
|
|
929
|
+
if (save_ret.code < 0) {
|
|
930
|
+
return save_ret;
|
|
835
931
|
}
|
|
932
|
+
const server_file_name = `https://${
|
|
933
|
+
process.env.XUDA_HOSTNAME
|
|
934
|
+
}/${drive_type}-drive${
|
|
935
|
+
drive_type === "studio" ? `/${master_id}/${target_file}` : file_name
|
|
936
|
+
}`;
|
|
937
|
+
|
|
938
|
+
misc_module.purge_cloudflare_cache(false, server_file_name);
|
|
939
|
+
return {
|
|
940
|
+
code: 760,
|
|
941
|
+
data: {
|
|
942
|
+
server_file_name,
|
|
943
|
+
filename: file_obj.originalname,
|
|
944
|
+
},
|
|
945
|
+
};
|
|
836
946
|
} catch (err) {
|
|
837
947
|
return { code: -400, data: err };
|
|
838
948
|
}
|
|
@@ -980,11 +1090,13 @@ exports.create_drive_folder = async function (req, job_id, headers) {
|
|
|
980
1090
|
};
|
|
981
1091
|
}
|
|
982
1092
|
};
|
|
983
|
-
exports.rename_drive_file = async function (req) {
|
|
1093
|
+
exports.rename_drive_file = async function (req, job_id, headers) {
|
|
984
1094
|
try {
|
|
985
1095
|
const { drive_type, app_id, file_name_to, file_path } = req;
|
|
986
1096
|
validate_drive_type(drive_type);
|
|
987
1097
|
|
|
1098
|
+
let doc = await get_drive_doc(drive_type, app_id, uid, file_path, headers);
|
|
1099
|
+
|
|
988
1100
|
let check_req = {
|
|
989
1101
|
app_id,
|
|
990
1102
|
uid,
|