@xuda.io/drive_module 1.1.838 → 1.1.840
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 +1 -373
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -413,98 +413,6 @@ exports.get_drive_files = async function (req) {
|
|
|
413
413
|
return err.message;
|
|
414
414
|
}
|
|
415
415
|
};
|
|
416
|
-
// exports.get_drive_file_info = async function (req) {
|
|
417
|
-
// try {
|
|
418
|
-
// const { type, drive_type, app_id, file_name } = req;
|
|
419
|
-
// var { file_path } = req;
|
|
420
|
-
|
|
421
|
-
// let doc_ret,
|
|
422
|
-
// doc_id,
|
|
423
|
-
// doc = {};
|
|
424
|
-
|
|
425
|
-
// const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
426
|
-
|
|
427
|
-
// switch (drive_type) {
|
|
428
|
-
// case "studio": {
|
|
429
|
-
// const target_dir = path.join(_conf[`studio_drive_path`], app_id_master);
|
|
430
|
-
// doc_id = file_path.replace(target_dir, "");
|
|
431
|
-
// doc_ret = await db_module.get_app_couch_doc(app_id_master, doc_id);
|
|
432
|
-
// break;
|
|
433
|
-
// }
|
|
434
|
-
|
|
435
|
-
// case "workspace": {
|
|
436
|
-
// if (
|
|
437
|
-
// type === "file" &&
|
|
438
|
-
// !file_path.includes(app_id) &&
|
|
439
|
-
// !file_path.includes(app_id_master)
|
|
440
|
-
// ) {
|
|
441
|
-
// throw new Error("file_path unauthorized");
|
|
442
|
-
// }
|
|
443
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
444
|
-
// doc_id = path.basename(file_path);
|
|
445
|
-
// doc_ret = await db_module.get_app_couch_doc(app_id_reference, doc_id);
|
|
446
|
-
// break;
|
|
447
|
-
// }
|
|
448
|
-
|
|
449
|
-
// case "user": {
|
|
450
|
-
// doc_id = path.basename(file_path);
|
|
451
|
-
// doc_ret = await db_module.get_couch_doc("xuda_drive", doc_id);
|
|
452
|
-
// break;
|
|
453
|
-
// }
|
|
454
|
-
// default:
|
|
455
|
-
// break;
|
|
456
|
-
// }
|
|
457
|
-
|
|
458
|
-
// var statsObj = {};
|
|
459
|
-
// if (doc_ret.code > -1) {
|
|
460
|
-
// doc = doc_ret.data;
|
|
461
|
-
|
|
462
|
-
// delete doc._id;
|
|
463
|
-
// delete doc._rev;
|
|
464
|
-
|
|
465
|
-
// delete doc.docType;
|
|
466
|
-
// delete doc.stat;
|
|
467
|
-
// if (doc.bucket) {
|
|
468
|
-
// doc.regions = Object.entries(doc.bucket).length;
|
|
469
|
-
// }
|
|
470
|
-
|
|
471
|
-
// delete doc.bucket;
|
|
472
|
-
// if (doc.uid) {
|
|
473
|
-
// let ret = await db_module.get_couch_doc("xuda_accounts", doc.uid);
|
|
474
|
-
// doc.account_info = ret.data.account_info;
|
|
475
|
-
// }
|
|
476
|
-
// if (req.drive_type === "workspace") {
|
|
477
|
-
// const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
478
|
-
// const ret = await db_module.get_app_obj(app_id_master);
|
|
479
|
-
|
|
480
|
-
// if (ret.code < 0) {
|
|
481
|
-
// return ret;
|
|
482
|
-
// }
|
|
483
|
-
// const app_obj = ret.data;
|
|
484
|
-
// doc.app_name = app_obj.app_name;
|
|
485
|
-
// }
|
|
486
|
-
// } else if (drive_type === "studio") {
|
|
487
|
-
// statsObj = fs.statSync(file_path);
|
|
488
|
-
// }
|
|
489
|
-
|
|
490
|
-
// return {
|
|
491
|
-
// code: 200,
|
|
492
|
-
// data: {
|
|
493
|
-
// name: doc_ret.code < 0 ? file_name : doc.originalname,
|
|
494
|
-
// cy_data:
|
|
495
|
-
// doc_ret.code < 0
|
|
496
|
-
// ? { date_created: new Date(statsObj.birthtime).valueOf() }
|
|
497
|
-
// : doc,
|
|
498
|
-
// exif_data: doc.exif_data,
|
|
499
|
-
// },
|
|
500
|
-
// };
|
|
501
|
-
// } catch (err) {
|
|
502
|
-
// return {
|
|
503
|
-
// code: -200,
|
|
504
|
-
// data: err.message,
|
|
505
|
-
// };
|
|
506
|
-
// }
|
|
507
|
-
// };
|
|
508
416
|
|
|
509
417
|
exports.get_drive_file_info = async function (req, job_id, headers) {
|
|
510
418
|
try {
|
|
@@ -695,165 +603,6 @@ exports.delete_drive_files = async function (req) {
|
|
|
695
603
|
}
|
|
696
604
|
};
|
|
697
605
|
|
|
698
|
-
// exports.update_drive_file = async function (req, job_id, headers, file_obj) {
|
|
699
|
-
// try {
|
|
700
|
-
// const { drive_type, app_id, file_path, uid } = req;
|
|
701
|
-
// validate_drive_type(drive_type);
|
|
702
|
-
|
|
703
|
-
// const originalname = file_obj?.["originalname"];
|
|
704
|
-
|
|
705
|
-
// const file_name = path.basename(file_path);
|
|
706
|
-
|
|
707
|
-
// if (!originalname) {
|
|
708
|
-
// return { code: -4, data: "file data missing" };
|
|
709
|
-
// }
|
|
710
|
-
|
|
711
|
-
// let check_req = {
|
|
712
|
-
// app_id,
|
|
713
|
-
// uid,
|
|
714
|
-
// drive_type,
|
|
715
|
-
|
|
716
|
-
// file_path,
|
|
717
|
-
// };
|
|
718
|
-
// const check_existing_file_ret = await module.exports.check_drive_file(
|
|
719
|
-
// check_req
|
|
720
|
-
// );
|
|
721
|
-
|
|
722
|
-
// if (check_existing_file_ret.code > -1) {
|
|
723
|
-
// return { code: -5, data: "file not exit" };
|
|
724
|
-
// }
|
|
725
|
-
|
|
726
|
-
// var target_file = file_path;
|
|
727
|
-
// const master_id = await _common.get_project_app_id(app_id, true);
|
|
728
|
-
// const tempPath = file_obj.path;
|
|
729
|
-
// if (drive_type === "studio") {
|
|
730
|
-
// const target_dir = path.join(
|
|
731
|
-
// _conf[`studio_drive_path`],
|
|
732
|
-
// master_id,
|
|
733
|
-
// target_file
|
|
734
|
-
// );
|
|
735
|
-
// try {
|
|
736
|
-
// fse.unlinkSync(target_dir);
|
|
737
|
-
// } catch (error) {}
|
|
738
|
-
|
|
739
|
-
// fse.copyFileSync(tempPath, target_dir);
|
|
740
|
-
// }
|
|
741
|
-
|
|
742
|
-
// let doc_ret;
|
|
743
|
-
|
|
744
|
-
// switch (drive_type) {
|
|
745
|
-
// case "studio": {
|
|
746
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
747
|
-
// doc_ret = await db_module.get_app_couch_doc(
|
|
748
|
-
// app_id_reference,
|
|
749
|
-
// target_file
|
|
750
|
-
// );
|
|
751
|
-
// break;
|
|
752
|
-
// }
|
|
753
|
-
// case "workspace": {
|
|
754
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
755
|
-
// doc_ret = await db_module.get_app_couch_doc(
|
|
756
|
-
// app_id_reference,
|
|
757
|
-
// check_existing_file_ret.duplicates[0]._id
|
|
758
|
-
// );
|
|
759
|
-
// break;
|
|
760
|
-
// }
|
|
761
|
-
// case "user":
|
|
762
|
-
// doc_ret = await db_module.get_couch_doc(
|
|
763
|
-
// "xuda_drive",
|
|
764
|
-
// check_existing_file_ret.duplicates[0]._id
|
|
765
|
-
// );
|
|
766
|
-
// break;
|
|
767
|
-
|
|
768
|
-
// default:
|
|
769
|
-
// break;
|
|
770
|
-
// }
|
|
771
|
-
|
|
772
|
-
// if (doc_ret.code > -1) {
|
|
773
|
-
// var doc = doc_ret.data;
|
|
774
|
-
// doc.date_modified = Date.now();
|
|
775
|
-
|
|
776
|
-
// const fs = require("fs").promises;
|
|
777
|
-
// const stat = await fs.stat(tempPath);
|
|
778
|
-
// if (stat.isFile()) {
|
|
779
|
-
// doc.size = stat.size;
|
|
780
|
-
// }
|
|
781
|
-
|
|
782
|
-
// doc = { ...doc, ...(await get_file_info(tempPath)) };
|
|
783
|
-
|
|
784
|
-
// let save_ret;
|
|
785
|
-
|
|
786
|
-
// switch (drive_type) {
|
|
787
|
-
// case "studio": {
|
|
788
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
789
|
-
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
790
|
-
|
|
791
|
-
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
792
|
-
// "studio",
|
|
793
|
-
// app_id_reference
|
|
794
|
-
// );
|
|
795
|
-
// break;
|
|
796
|
-
// }
|
|
797
|
-
// case "workspace": {
|
|
798
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
799
|
-
// const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
800
|
-
|
|
801
|
-
// doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
802
|
-
// await upload_file_to_spaces(
|
|
803
|
-
// tempPath,
|
|
804
|
-
// app_id_master,
|
|
805
|
-
// drive_type,
|
|
806
|
-
// file_name
|
|
807
|
-
// );
|
|
808
|
-
|
|
809
|
-
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
810
|
-
// misc_module.rsync_drive_resources_to_remote_servers(
|
|
811
|
-
// "workspace",
|
|
812
|
-
// app_id_master
|
|
813
|
-
// );
|
|
814
|
-
// break;
|
|
815
|
-
// }
|
|
816
|
-
// case "user": {
|
|
817
|
-
// doc.bucket[`${process.env.XUDA_HOSTNAME}`] =
|
|
818
|
-
// await upload_file_to_spaces(tempPath, uid, drive_type, file_name);
|
|
819
|
-
// save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
820
|
-
// misc_module.rsync_drive_resources_to_remote_servers("user", doc.uid);
|
|
821
|
-
// break;
|
|
822
|
-
// }
|
|
823
|
-
// default:
|
|
824
|
-
// break;
|
|
825
|
-
// }
|
|
826
|
-
|
|
827
|
-
// fse.unlinkSync(tempPath);
|
|
828
|
-
|
|
829
|
-
// if (save_ret.code < 0) {
|
|
830
|
-
// return save_ret;
|
|
831
|
-
// }
|
|
832
|
-
// const server_file_name = `https://${
|
|
833
|
-
// process.env.XUDA_HOSTNAME
|
|
834
|
-
// }/${drive_type}-drive${
|
|
835
|
-
// drive_type === "studio" ? `/${master_id}/${target_file}` : file_name
|
|
836
|
-
// }`;
|
|
837
|
-
|
|
838
|
-
// misc_module.purge_cloudflare_cache(false, server_file_name);
|
|
839
|
-
// return {
|
|
840
|
-
// code: 760,
|
|
841
|
-
// data: {
|
|
842
|
-
// server_file_name,
|
|
843
|
-
// filename: file_obj.originalname,
|
|
844
|
-
// },
|
|
845
|
-
// };
|
|
846
|
-
// } else {
|
|
847
|
-
// return {
|
|
848
|
-
// code: -760,
|
|
849
|
-
// data: "file not found",
|
|
850
|
-
// };
|
|
851
|
-
// }
|
|
852
|
-
// } catch (err) {
|
|
853
|
-
// return { code: -400, data: err };
|
|
854
|
-
// }
|
|
855
|
-
// };
|
|
856
|
-
|
|
857
606
|
exports.update_drive_file = async function (req, job_id, headers, file_obj) {
|
|
858
607
|
try {
|
|
859
608
|
const { drive_type, app_id, file_path, uid } = req;
|
|
@@ -1302,126 +1051,6 @@ exports.update_drive_file_sharing_mode = async function (req, job_id, headers) {
|
|
|
1302
1051
|
return err.message;
|
|
1303
1052
|
}
|
|
1304
1053
|
};
|
|
1305
|
-
// exports.update_drive_file_sharing_mode = async function (req, job_id, headers) {
|
|
1306
|
-
// try {
|
|
1307
|
-
// const { drive_type, uid, app_id, file_path, is_public } = req;
|
|
1308
|
-
|
|
1309
|
-
// validate_drive_type(drive_type);
|
|
1310
|
-
|
|
1311
|
-
// const file_name = path.basename(file_path);
|
|
1312
|
-
|
|
1313
|
-
// let check_req = {
|
|
1314
|
-
// app_id,
|
|
1315
|
-
// uid,
|
|
1316
|
-
// drive_type,
|
|
1317
|
-
// file_path,
|
|
1318
|
-
// };
|
|
1319
|
-
// const check_existing_file_ret = await module.exports.check_drive_file(
|
|
1320
|
-
// check_req
|
|
1321
|
-
// );
|
|
1322
|
-
|
|
1323
|
-
// let doc_ret;
|
|
1324
|
-
|
|
1325
|
-
// switch (drive_type) {
|
|
1326
|
-
// case "studio": {
|
|
1327
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1328
|
-
// doc_ret = await db_module.get_app_couch_doc(
|
|
1329
|
-
// app_id_reference,
|
|
1330
|
-
// file_path
|
|
1331
|
-
// );
|
|
1332
|
-
// break;
|
|
1333
|
-
// }
|
|
1334
|
-
// case "user":
|
|
1335
|
-
// doc_ret = await db_module.get_couch_doc(
|
|
1336
|
-
// "xuda_drive",
|
|
1337
|
-
// check_existing_file_ret.duplicates[0]._id
|
|
1338
|
-
// );
|
|
1339
|
-
// break;
|
|
1340
|
-
|
|
1341
|
-
// case "workspace": {
|
|
1342
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1343
|
-
// doc_ret = await db_module.get_app_couch_doc(
|
|
1344
|
-
// app_id_reference,
|
|
1345
|
-
// check_existing_file_ret.duplicates[0]._id
|
|
1346
|
-
// );
|
|
1347
|
-
|
|
1348
|
-
// break;
|
|
1349
|
-
// }
|
|
1350
|
-
// default:
|
|
1351
|
-
// break;
|
|
1352
|
-
// }
|
|
1353
|
-
|
|
1354
|
-
// var doc = doc_ret.data;
|
|
1355
|
-
|
|
1356
|
-
// if (doc_ret.code < 0 && drive_type === "studio") {
|
|
1357
|
-
// const ext = path.extname(file_name).toLowerCase();
|
|
1358
|
-
// doc = {
|
|
1359
|
-
// _id: file_name,
|
|
1360
|
-
// docType: `${drive_type}_drive`,
|
|
1361
|
-
// stat: 3,
|
|
1362
|
-
// server_file_name: file_name,
|
|
1363
|
-
// originalname: file_name,
|
|
1364
|
-
// uid,
|
|
1365
|
-
// date_created: Date.now(),
|
|
1366
|
-
// ip: headers["cf-connecting-ip"],
|
|
1367
|
-
// country: headers["cf-ipcountry"],
|
|
1368
|
-
// file_ext: ext,
|
|
1369
|
-
// is_archive: _conf.archive_drive_ext.includes(ext) ? true : false,
|
|
1370
|
-
// drive_type,
|
|
1371
|
-
// };
|
|
1372
|
-
|
|
1373
|
-
// // if (drive_type === "studio" || drive_type === "workspace") {
|
|
1374
|
-
// doc.app_id = await _common.get_project_app_id(app_id);
|
|
1375
|
-
// doc.app_id_reference = await _common.get_project_app_id(app_id, true);
|
|
1376
|
-
// // }
|
|
1377
|
-
|
|
1378
|
-
// // let save_ret;
|
|
1379
|
-
|
|
1380
|
-
// // const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1381
|
-
// // save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
1382
|
-
|
|
1383
|
-
// // switch (drive_type) {
|
|
1384
|
-
// // case "workspace":
|
|
1385
|
-
// // case "studio":
|
|
1386
|
-
// // const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1387
|
-
// // save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
1388
|
-
// // break;
|
|
1389
|
-
|
|
1390
|
-
// // case "user":
|
|
1391
|
-
// // save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
1392
|
-
// // break;
|
|
1393
|
-
|
|
1394
|
-
// // default:
|
|
1395
|
-
// // break;
|
|
1396
|
-
// // }
|
|
1397
|
-
// // return save_ret;
|
|
1398
|
-
// }
|
|
1399
|
-
|
|
1400
|
-
// doc.ts = Date.now();
|
|
1401
|
-
// doc.public = is_public;
|
|
1402
|
-
|
|
1403
|
-
// let save_ret;
|
|
1404
|
-
|
|
1405
|
-
// switch (drive_type) {
|
|
1406
|
-
// case "workspace":
|
|
1407
|
-
// case "studio":
|
|
1408
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1409
|
-
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
1410
|
-
// break;
|
|
1411
|
-
|
|
1412
|
-
// case "user":
|
|
1413
|
-
// save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
1414
|
-
// break;
|
|
1415
|
-
|
|
1416
|
-
// default:
|
|
1417
|
-
// break;
|
|
1418
|
-
// }
|
|
1419
|
-
|
|
1420
|
-
// return save_ret;
|
|
1421
|
-
// } catch (err) {
|
|
1422
|
-
// return err.message;
|
|
1423
|
-
// }
|
|
1424
|
-
// };
|
|
1425
1054
|
|
|
1426
1055
|
exports.extract_drive_file = async function (req, job_id, headers) {
|
|
1427
1056
|
const { app_id, file_path, uid } = req;
|
|
@@ -1811,7 +1440,7 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
1811
1440
|
}
|
|
1812
1441
|
};
|
|
1813
1442
|
exports.check_drive_file = async function (req, job_id, headers, file_obj) {
|
|
1814
|
-
const { type, drive_type, app_id, uid, file_path } = req;
|
|
1443
|
+
const { type = "file", drive_type, app_id, uid, file_path } = req;
|
|
1815
1444
|
|
|
1816
1445
|
var master_app_id;
|
|
1817
1446
|
|
|
@@ -2596,7 +2225,6 @@ const get_drive_doc = async function (
|
|
|
2596
2225
|
app_id,
|
|
2597
2226
|
uid,
|
|
2598
2227
|
file_path,
|
|
2599
|
-
|
|
2600
2228
|
headers
|
|
2601
2229
|
) {
|
|
2602
2230
|
let check_req = {
|