@xuda.io/drive_module 1.1.1406 → 1.1.1407
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 +48 -48
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -31,7 +31,7 @@ const { get_account_default_project_id } = await import(path.join(process.env.XU
|
|
|
31
31
|
|
|
32
32
|
const module_path = path.join(process.env.XUDA_HOME, 'cpi') + (!_conf.is_debug ? '/node_modules/@xuda.io' : '');
|
|
33
33
|
const fs_module = await import(`${module_path}/fs_module/index.mjs`);
|
|
34
|
-
const
|
|
34
|
+
const db_ms = await import(`${module_path}/db_module/index_ms.mjs`);
|
|
35
35
|
|
|
36
36
|
const account_ms = await import(`${module_path}/account_module/index_ms.mjs`);
|
|
37
37
|
|
|
@@ -266,11 +266,11 @@ export const get_drive_files = async (req) => {
|
|
|
266
266
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
267
267
|
opt.selector.docType = 'workspace_drive';
|
|
268
268
|
|
|
269
|
-
const ret = await
|
|
269
|
+
const ret = await db_ms.find_app_couch_query(app_id, opt);
|
|
270
270
|
|
|
271
|
-
const file_doc = await
|
|
271
|
+
const file_doc = await db_ms.get_app_couch_doc(app_id, path.basename(file_path) || '/');
|
|
272
272
|
|
|
273
|
-
const { data: app_obj } = await
|
|
273
|
+
const { data: app_obj } = await db_ms.get_app_obj(app_id);
|
|
274
274
|
|
|
275
275
|
const ret_fetch_drive_files = await fetch_drive_files(ret, file_doc, app_id_reference, null, app_obj.app_datacenter_id, app_obj.is_deployment ? app_obj.app_access_url : undefined, app_obj);
|
|
276
276
|
return {
|
|
@@ -292,9 +292,9 @@ export const get_drive_files = async (req) => {
|
|
|
292
292
|
if (search_string) {
|
|
293
293
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
294
294
|
opt.selector.docType = 'studio_drive';
|
|
295
|
-
const ret = await
|
|
295
|
+
const ret = await db_ms.find_app_couch_query(app_id, opt);
|
|
296
296
|
|
|
297
|
-
const file_doc = await
|
|
297
|
+
const file_doc = await db_ms.get_app_couch_doc(app_id, path.basename(file_path) || '/');
|
|
298
298
|
|
|
299
299
|
return {
|
|
300
300
|
code: 1,
|
|
@@ -344,7 +344,7 @@ export const get_drive_files = async (req) => {
|
|
|
344
344
|
const directory_path = get_studio_path(val.path, app_id_master, val.relativePath);
|
|
345
345
|
const file_path = path.join(directory_path, val.name);
|
|
346
346
|
|
|
347
|
-
let ret = await
|
|
347
|
+
let ret = await db_ms.get_app_couch_doc(app_id_master, file_path);
|
|
348
348
|
|
|
349
349
|
if (ret.code > -1) {
|
|
350
350
|
if (val.type === 'file') {
|
|
@@ -439,12 +439,12 @@ export const get_drive_file_info = async (req, job_id, headers) => {
|
|
|
439
439
|
delete doc.bucket;
|
|
440
440
|
|
|
441
441
|
if (doc.uid) {
|
|
442
|
-
let ret = await
|
|
442
|
+
let ret = await db_ms.get_couch_doc('xuda_accounts', doc.uid);
|
|
443
443
|
doc.account_info = ret.data.account_info;
|
|
444
444
|
}
|
|
445
445
|
if (req.drive_type === 'workspace') {
|
|
446
446
|
const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
447
|
-
const ret = await
|
|
447
|
+
const ret = await db_ms.get_app_obj(app_id_master);
|
|
448
448
|
|
|
449
449
|
if (ret.code < 0) {
|
|
450
450
|
return ret;
|
|
@@ -513,7 +513,7 @@ export const delete_drive_files = async (req, job_id, headers) => {
|
|
|
513
513
|
if (doc.type === 'file') {
|
|
514
514
|
doc.ts = Date.now();
|
|
515
515
|
doc.stat = 4;
|
|
516
|
-
save_ret = await
|
|
516
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
misc_ms.rsync_drive_resources_to_remote_servers('studio', app_id_reference);
|
|
@@ -527,12 +527,12 @@ export const delete_drive_files = async (req, job_id, headers) => {
|
|
|
527
527
|
if (doc.bucket) {
|
|
528
528
|
await delete_file_from_bucket(doc.bucket);
|
|
529
529
|
} else {
|
|
530
|
-
const { data: app_obj } = await
|
|
530
|
+
const { data: app_obj } = await db_ms.get_app_obj(app_id);
|
|
531
531
|
if (app_obj?.app_type === 'datacenter') {
|
|
532
532
|
const host = `root@${app_obj.app_hosting_server.ip}`;
|
|
533
533
|
await _utils.run_ssh_script(`ssh ${host} "rm /var/xuda/workspace_drive/${doc.server_file_name};" `);
|
|
534
534
|
} else if (app_obj?.is_deployment) {
|
|
535
|
-
const { data: datacenter_obj } = await
|
|
535
|
+
const { data: datacenter_obj } = await db_ms.get_app_obj(app_obj.app_datacenter_id);
|
|
536
536
|
const host = `root@${datacenter_obj.app_hosting_server.ip}`;
|
|
537
537
|
await _utils.run_ssh_script(`ssh ${host} "rm /var/xuda/workspace_drive/${doc.server_file_name};" `);
|
|
538
538
|
}
|
|
@@ -613,7 +613,7 @@ export const update_drive_file = async (req, job_id, headers, file_obj) => {
|
|
|
613
613
|
case 'studio': {
|
|
614
614
|
ref = await _common.get_project_app_id(app_id, true);
|
|
615
615
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
616
|
-
save_ret = await
|
|
616
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
617
617
|
|
|
618
618
|
misc_ms.rsync_drive_resources_to_remote_servers('studio', app_id_reference);
|
|
619
619
|
break;
|
|
@@ -623,19 +623,19 @@ export const update_drive_file = async (req, job_id, headers, file_obj) => {
|
|
|
623
623
|
const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
624
624
|
ref = app_id_master;
|
|
625
625
|
|
|
626
|
-
const { data: app_obj } = await
|
|
626
|
+
const { data: app_obj } = await db_ms.get_app_obj(app_id);
|
|
627
627
|
if (app_obj?.app_type === 'datacenter') {
|
|
628
628
|
const host = `root@${app_obj.app_hosting_server.ip}`;
|
|
629
629
|
await _utils.run_ssh_script(`scp ${tempPath} ${host}:/var/xuda/workspace_drive/${doc.server_file_name}; `);
|
|
630
630
|
} else if (app_obj?.is_deployment) {
|
|
631
|
-
const { data: datacenter_obj } = await
|
|
631
|
+
const { data: datacenter_obj } = await db_ms.get_app_obj(app_obj.app_datacenter_id);
|
|
632
632
|
const host = `root@${datacenter_obj.app_hosting_server.ip}`;
|
|
633
633
|
await _utils.run_ssh_script(`scp ${tempPath} ${host}:/var/xuda/workspace_drive/${doc.server_file_name}; `);
|
|
634
634
|
} else {
|
|
635
635
|
doc.bucket[`${process.env.XUDA_HOSTNAME}`] = await upload_file_to_spaces(tempPath, app_id_master, drive_type, doc.server_file_name);
|
|
636
636
|
}
|
|
637
637
|
|
|
638
|
-
save_ret = await
|
|
638
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
639
639
|
break;
|
|
640
640
|
}
|
|
641
641
|
case 'user': {
|
|
@@ -741,7 +741,7 @@ export const create_drive_folder = async (req, job_id, headers) => {
|
|
|
741
741
|
}
|
|
742
742
|
await create_directory(fs_target_dir, 0o775, true);
|
|
743
743
|
doc._id = target_dir;
|
|
744
|
-
save_ret = await
|
|
744
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_master, doc);
|
|
745
745
|
misc_ms.rsync_drive_resources_to_remote_servers('studio', app_id_master);
|
|
746
746
|
break;
|
|
747
747
|
}
|
|
@@ -750,7 +750,7 @@ export const create_drive_folder = async (req, job_id, headers) => {
|
|
|
750
750
|
folder_id = 'drive_folder_' + _utils.UUID();
|
|
751
751
|
let app_id_reference = await _common.get_project_app_id(app_id);
|
|
752
752
|
doc._id = folder_id;
|
|
753
|
-
save_ret = await
|
|
753
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
754
754
|
break;
|
|
755
755
|
}
|
|
756
756
|
|
|
@@ -792,7 +792,7 @@ export const rename_drive_file = async (req, job_id, headers) => {
|
|
|
792
792
|
let app_id_master = await _common.get_project_app_id(app_id, true);
|
|
793
793
|
|
|
794
794
|
doc._delete = true;
|
|
795
|
-
await
|
|
795
|
+
await db_ms.save_app_couch_doc(app_id_master, doc);
|
|
796
796
|
|
|
797
797
|
doc._id = file_name_to;
|
|
798
798
|
delete doc._rev;
|
|
@@ -806,7 +806,7 @@ export const rename_drive_file = async (req, job_id, headers) => {
|
|
|
806
806
|
case 'workspace':
|
|
807
807
|
case 'studio':
|
|
808
808
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
809
|
-
save_ret = await
|
|
809
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
810
810
|
break;
|
|
811
811
|
|
|
812
812
|
case 'user':
|
|
@@ -853,10 +853,10 @@ export const rename_drive_folder = async (req) => {
|
|
|
853
853
|
throw new Error('error - new_path unauthorized');
|
|
854
854
|
}
|
|
855
855
|
|
|
856
|
-
doc_ret = await
|
|
856
|
+
doc_ret = await db_ms.get_app_couch_doc(app_id_reference, curr_path);
|
|
857
857
|
await fs_module.rename(curr_path, new_path);
|
|
858
858
|
doc_ret.data._delete = true;
|
|
859
|
-
await
|
|
859
|
+
await db_ms.save_app_couch_doc(app_id_reference, doc_ret.data);
|
|
860
860
|
|
|
861
861
|
doc_ret.data._id = new_path;
|
|
862
862
|
delete doc_ret.data._rev;
|
|
@@ -866,7 +866,7 @@ export const rename_drive_folder = async (req) => {
|
|
|
866
866
|
}
|
|
867
867
|
case 'workspace': {
|
|
868
868
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
869
|
-
doc_ret = await
|
|
869
|
+
doc_ret = await db_ms.get_app_couch_doc(app_id_reference, curr_path);
|
|
870
870
|
if (doc_ret.code < 0) {
|
|
871
871
|
throw new Error(doc_ret.data);
|
|
872
872
|
}
|
|
@@ -896,7 +896,7 @@ export const rename_drive_folder = async (req) => {
|
|
|
896
896
|
case 'workspace':
|
|
897
897
|
case 'studio':
|
|
898
898
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
899
|
-
save_ret = await
|
|
899
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
900
900
|
break;
|
|
901
901
|
|
|
902
902
|
case 'user':
|
|
@@ -1026,7 +1026,7 @@ export const extract_drive_file = async (req, job_id, headers) => {
|
|
|
1026
1026
|
}
|
|
1027
1027
|
|
|
1028
1028
|
try {
|
|
1029
|
-
await
|
|
1029
|
+
await db_ms.save_app_couch_doc(app_id_reference, file_doc);
|
|
1030
1030
|
} catch (error) {}
|
|
1031
1031
|
})
|
|
1032
1032
|
.on('close', () => {
|
|
@@ -1196,7 +1196,7 @@ export const upload_drive_file = async (req, job_id, headers = {}, file_obj) =>
|
|
|
1196
1196
|
|
|
1197
1197
|
doc._id = file_name;
|
|
1198
1198
|
|
|
1199
|
-
save_ret = await
|
|
1199
|
+
save_ret = await db_ms.save_app_couch_doc(ref, doc);
|
|
1200
1200
|
misc_ms.rsync_drive_resources_to_remote_servers('studio', app_id);
|
|
1201
1201
|
break;
|
|
1202
1202
|
}
|
|
@@ -1213,12 +1213,12 @@ export const upload_drive_file = async (req, job_id, headers = {}, file_obj) =>
|
|
|
1213
1213
|
doc.app_id = app_id;
|
|
1214
1214
|
doc.app_id_reference = ref;
|
|
1215
1215
|
|
|
1216
|
-
const { data: app_obj } = await
|
|
1216
|
+
const { data: app_obj } = await db_ms.get_app_obj(app_id);
|
|
1217
1217
|
if (app_obj?.app_type === 'datacenter') {
|
|
1218
1218
|
const host = `root@${app_obj.app_hosting_server.ip}`;
|
|
1219
1219
|
await _utils.run_ssh_script(`scp ${tempPath} ${host}:/var/xuda/workspace_drive/${file_name}; `);
|
|
1220
1220
|
} else if (app_obj?.is_deployment) {
|
|
1221
|
-
const { data: datacenter_obj } = await
|
|
1221
|
+
const { data: datacenter_obj } = await db_ms.get_app_obj(app_obj.app_datacenter_id);
|
|
1222
1222
|
const host = `root@${datacenter_obj.app_hosting_server.ip}`;
|
|
1223
1223
|
await _utils.run_ssh_script(`scp ${tempPath} ${host}:/var/xuda/workspace_drive/${file_name}; `);
|
|
1224
1224
|
} else {
|
|
@@ -1227,7 +1227,7 @@ export const upload_drive_file = async (req, job_id, headers = {}, file_obj) =>
|
|
|
1227
1227
|
};
|
|
1228
1228
|
}
|
|
1229
1229
|
doc._id = file_name;
|
|
1230
|
-
save_ret = await
|
|
1230
|
+
save_ret = await db_ms.save_app_couch_doc(await _common.get_project_app_id(req.app_id), doc);
|
|
1231
1231
|
break;
|
|
1232
1232
|
}
|
|
1233
1233
|
case 'user': {
|
|
@@ -1310,7 +1310,7 @@ export const check_drive_file = async (req, job_id, headers, file_obj) => {
|
|
|
1310
1310
|
}
|
|
1311
1311
|
case 'workspace': {
|
|
1312
1312
|
selector.docType = 'workspace_drive';
|
|
1313
|
-
const workspace_drive_res = await
|
|
1313
|
+
const workspace_drive_res = await db_ms.find_app_couch_query(app_id, {
|
|
1314
1314
|
selector,
|
|
1315
1315
|
limit: 99,
|
|
1316
1316
|
});
|
|
@@ -1505,7 +1505,7 @@ export const run_drive_pending_ocr = async () => {
|
|
|
1505
1505
|
limit: 99999,
|
|
1506
1506
|
};
|
|
1507
1507
|
|
|
1508
|
-
let app_res = await
|
|
1508
|
+
let app_res = await db_ms.find_couch_query('xuda_master', app_opt);
|
|
1509
1509
|
|
|
1510
1510
|
for (let app of app_res.docs) {
|
|
1511
1511
|
let opt = {
|
|
@@ -1513,13 +1513,13 @@ export const run_drive_pending_ocr = async () => {
|
|
|
1513
1513
|
limit: 1,
|
|
1514
1514
|
};
|
|
1515
1515
|
|
|
1516
|
-
const user_drive_res = await
|
|
1516
|
+
const user_drive_res = await db_ms.find_app_couch_query(app._id, opt);
|
|
1517
1517
|
for await (let doc of user_drive_res.docs) {
|
|
1518
1518
|
await ocr_drive_file(null, doc);
|
|
1519
1519
|
}
|
|
1520
1520
|
|
|
1521
1521
|
opt.selector.docType = 'workspace_drive';
|
|
1522
|
-
const app_drive_res = await
|
|
1522
|
+
const app_drive_res = await db_ms.find_app_couch_query(app._id, opt);
|
|
1523
1523
|
for await (let doc of app_drive_res.docs) {
|
|
1524
1524
|
await ocr_drive_file(app._id, doc);
|
|
1525
1525
|
}
|
|
@@ -1688,9 +1688,9 @@ const get_folder_size = async (dir, drive_type, app_id, uid) => {
|
|
|
1688
1688
|
// opt.selector.uid = uid;
|
|
1689
1689
|
|
|
1690
1690
|
const app_id = await get_account_default_project_id(uid);
|
|
1691
|
-
ret = await
|
|
1691
|
+
ret = await db_ms.find_app_couch_query(app_id, opt);
|
|
1692
1692
|
} else {
|
|
1693
|
-
ret = await
|
|
1693
|
+
ret = await db_ms.find_app_couch_query(app_id, opt);
|
|
1694
1694
|
}
|
|
1695
1695
|
|
|
1696
1696
|
for await (let doc of ret.docs) {
|
|
@@ -1785,7 +1785,7 @@ const get_drive_doc = async (type, drive_type, app_id, uid, file_path, headers)
|
|
|
1785
1785
|
switch (drive_type) {
|
|
1786
1786
|
case 'studio': {
|
|
1787
1787
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1788
|
-
doc_ret = await
|
|
1788
|
+
doc_ret = await db_ms.get_app_couch_doc(app_id_reference, file_path);
|
|
1789
1789
|
break;
|
|
1790
1790
|
}
|
|
1791
1791
|
case 'user':
|
|
@@ -1796,7 +1796,7 @@ const get_drive_doc = async (type, drive_type, app_id, uid, file_path, headers)
|
|
|
1796
1796
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1797
1797
|
const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
1798
1798
|
|
|
1799
|
-
doc_ret = await
|
|
1799
|
+
doc_ret = await db_ms.get_app_couch_doc(app_id_reference, check_existing_file_ret.duplicates[0]._id);
|
|
1800
1800
|
|
|
1801
1801
|
if (doc_ret?.data?.type === 'file' && !doc_ret?.data?._id.includes(app_id) && !doc_ret?.data?._id.includes(app_id_master)) {
|
|
1802
1802
|
throw new Error('file_path unauthorized');
|
|
@@ -1834,7 +1834,7 @@ const get_drive_doc = async (type, drive_type, app_id, uid, file_path, headers)
|
|
|
1834
1834
|
app_id_reference: await _common.get_project_app_id(app_id, true),
|
|
1835
1835
|
uid,
|
|
1836
1836
|
};
|
|
1837
|
-
const save_ret = await
|
|
1837
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
1838
1838
|
if (save_ret.code < 0) {
|
|
1839
1839
|
throw new Error('studio file doc save error');
|
|
1840
1840
|
}
|
|
@@ -1856,7 +1856,7 @@ const save_drive_doc = async (drive_type, uid, app_id, doc) => {
|
|
|
1856
1856
|
case 'workspace':
|
|
1857
1857
|
case 'studio':
|
|
1858
1858
|
const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1859
|
-
save_ret = await
|
|
1859
|
+
save_ret = await db_ms.save_app_couch_doc(app_id_reference, doc);
|
|
1860
1860
|
break;
|
|
1861
1861
|
|
|
1862
1862
|
case 'user':
|
|
@@ -2044,7 +2044,7 @@ export default {
|
|
|
2044
2044
|
doc.vite_build_res = vite_build_res;
|
|
2045
2045
|
doc.scriptData.dependencies = devDependencies;
|
|
2046
2046
|
|
|
2047
|
-
|
|
2047
|
+
db_ms.save_app_couch_doc(app_id, doc);
|
|
2048
2048
|
} catch (err) {
|
|
2049
2049
|
doc.vite_build_res = {
|
|
2050
2050
|
code: -1,
|
|
@@ -2054,7 +2054,7 @@ export default {
|
|
|
2054
2054
|
if (job_id) {
|
|
2055
2055
|
return doc.vite_build_res;
|
|
2056
2056
|
}
|
|
2057
|
-
|
|
2057
|
+
db_ms.save_app_couch_doc(app_id, doc);
|
|
2058
2058
|
}
|
|
2059
2059
|
};
|
|
2060
2060
|
|
|
@@ -2087,21 +2087,21 @@ export const update_drive_addons = async (req, job_id) => {
|
|
|
2087
2087
|
let save_ret;
|
|
2088
2088
|
if (drive_type === 'workspace' || drive_type === 'studio') {
|
|
2089
2089
|
const master_id = await _common.get_project_app_id(app_id, true);
|
|
2090
|
-
let app_obj_ret = await
|
|
2090
|
+
let app_obj_ret = await db_ms.get_app_obj(master_id);
|
|
2091
2091
|
if (app_obj_ret.data.drive_addons) {
|
|
2092
2092
|
drive_addons = app_obj_ret.data.drive_addons;
|
|
2093
2093
|
}
|
|
2094
2094
|
set_drive_addons(drive_addons);
|
|
2095
|
-
save_ret = await
|
|
2095
|
+
save_ret = await db_ms.save_app_couch_doc2(master_id, app_obj_ret.data);
|
|
2096
2096
|
}
|
|
2097
2097
|
if (drive_type === 'user') {
|
|
2098
|
-
let account_ret = await
|
|
2098
|
+
let account_ret = await db_ms.get_couch_doc('xuda_accounts', uid);
|
|
2099
2099
|
|
|
2100
2100
|
if (account_ret.data.drive_addons) {
|
|
2101
2101
|
drive_addons = account_ret.data.drive_addons;
|
|
2102
2102
|
}
|
|
2103
2103
|
set_drive_addons(drive_addons);
|
|
2104
|
-
save_ret = await
|
|
2104
|
+
save_ret = await db_ms.save_couch_doc('xuda_accounts', account_ret.data);
|
|
2105
2105
|
}
|
|
2106
2106
|
return save_ret;
|
|
2107
2107
|
};
|
|
@@ -2125,19 +2125,19 @@ export const getExtensionFromUrl = function (imageUrl) {
|
|
|
2125
2125
|
|
|
2126
2126
|
export const get_user_drive_file = async function (uid, filename) {
|
|
2127
2127
|
const app_id = await get_account_default_project_id(uid);
|
|
2128
|
-
const drive_ret = await
|
|
2128
|
+
const drive_ret = await db_ms.get_app_couch_doc(app_id, filename);
|
|
2129
2129
|
return drive_ret;
|
|
2130
2130
|
};
|
|
2131
2131
|
|
|
2132
2132
|
export const save_user_drive_file = async function (uid, drive_doc) {
|
|
2133
2133
|
const app_id = await get_account_default_project_id(uid);
|
|
2134
|
-
const save_ret = await
|
|
2134
|
+
const save_ret = await db_ms.save_app_couch_doc(app_id, drive_doc);
|
|
2135
2135
|
return save_ret;
|
|
2136
2136
|
};
|
|
2137
2137
|
|
|
2138
2138
|
export const find_contact_query = async function (uid, opt) {
|
|
2139
2139
|
const app_id = await get_account_default_project_id(uid);
|
|
2140
|
-
const ret = await
|
|
2140
|
+
const ret = await db_ms.find_app_couch_query(app_id, opt);
|
|
2141
2141
|
return ret;
|
|
2142
2142
|
};
|
|
2143
2143
|
|