@xuda.io/drive_module 1.1.559 → 1.1.561
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 +125 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1407,10 +1407,6 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
1407
1407
|
};
|
|
1408
1408
|
}
|
|
1409
1409
|
|
|
1410
|
-
// if (await fs_module.file_exists(target_file)) {
|
|
1411
|
-
// await fs_module.unlink(target_file);
|
|
1412
|
-
// }
|
|
1413
|
-
|
|
1414
1410
|
await fs_module.copy(tempPath, target_file);
|
|
1415
1411
|
doc.server_file_name = file_name;
|
|
1416
1412
|
|
|
@@ -1538,6 +1534,131 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
1538
1534
|
return { code: -400, data: err.message };
|
|
1539
1535
|
}
|
|
1540
1536
|
};
|
|
1537
|
+
exports.check_drive_file = async function (req, job_id, headers, file_obj) {
|
|
1538
|
+
const { drive_type, app_id, uid, make_public, check_exist } = req;
|
|
1539
|
+
var file_name;
|
|
1540
|
+
switch (drive_type) {
|
|
1541
|
+
case "studio": {
|
|
1542
|
+
ref = await _common.get_project_app_id(req.app_id, true);
|
|
1543
|
+
const target_dir = path.join(_conf[`studio_drive_path`], ref);
|
|
1544
|
+
file_name = path.join(
|
|
1545
|
+
req.path.replace(target_dir, ""),
|
|
1546
|
+
file_obj.originalname
|
|
1547
|
+
);
|
|
1548
|
+
target_file = path.join(
|
|
1549
|
+
req.path !== "/" ? req.path : target_dir,
|
|
1550
|
+
originalname
|
|
1551
|
+
);
|
|
1552
|
+
|
|
1553
|
+
if (!(await fs_module.file_exists(target_dir))) {
|
|
1554
|
+
await fs_module.mkdir(target_dir, 0o775, true);
|
|
1555
|
+
}
|
|
1556
|
+
if (await fs_module.file_exists(target_file)) {
|
|
1557
|
+
return {
|
|
1558
|
+
code: -762,
|
|
1559
|
+
data: "file already exist",
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
await fs_module.copy(tempPath, target_file);
|
|
1564
|
+
doc.server_file_name = file_name;
|
|
1565
|
+
|
|
1566
|
+
doc.app_id = app_id;
|
|
1567
|
+
doc.app_id_reference = ref;
|
|
1568
|
+
|
|
1569
|
+
doc._id = file_name;
|
|
1570
|
+
|
|
1571
|
+
save_ret = await db_module.save_app_couch_doc(ref, doc);
|
|
1572
|
+
misc_module.rsync_drive_resources_to_remote_servers("studio", app_id);
|
|
1573
|
+
break;
|
|
1574
|
+
}
|
|
1575
|
+
case "workspace": {
|
|
1576
|
+
ref = await _common.get_project_app_id(req.app_id, true);
|
|
1577
|
+
file_name =
|
|
1578
|
+
"drv_" + ref + "_" + (await _common.xuda_get_uuid(drive_type)) + ext;
|
|
1579
|
+
|
|
1580
|
+
// keep the original filename to support migration
|
|
1581
|
+
if (file_obj.originalname.includes(`drv_${ref}`)) {
|
|
1582
|
+
file_name = file_obj.originalname;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
doc.server_file_name = file_name;
|
|
1586
|
+
|
|
1587
|
+
doc.app_id = app_id;
|
|
1588
|
+
doc.app_id_reference = ref;
|
|
1589
|
+
|
|
1590
|
+
/// check existing file
|
|
1591
|
+
if (check_exist) {
|
|
1592
|
+
const workspace_drive_res = await db_module.find_app_couch_query(
|
|
1593
|
+
app_id,
|
|
1594
|
+
{
|
|
1595
|
+
selector: { docType: "workspace_drive", originalname, stat: 3 },
|
|
1596
|
+
limit: 99,
|
|
1597
|
+
}
|
|
1598
|
+
);
|
|
1599
|
+
if (workspace_drive_res.docs.length) {
|
|
1600
|
+
return {
|
|
1601
|
+
code: -762,
|
|
1602
|
+
data: "file already exist",
|
|
1603
|
+
duplicates: workspace_drive_res.docs,
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
doc.bucket = {
|
|
1609
|
+
[`${process.env.XUDA_HOSTNAME}`]: await upload_file_to_spaces(
|
|
1610
|
+
tempPath,
|
|
1611
|
+
ref,
|
|
1612
|
+
drive_type,
|
|
1613
|
+
file_name
|
|
1614
|
+
),
|
|
1615
|
+
};
|
|
1616
|
+
doc._id = file_name;
|
|
1617
|
+
save_ret = await db_module.save_app_couch_doc(
|
|
1618
|
+
await _common.get_project_app_id(req.app_id),
|
|
1619
|
+
doc
|
|
1620
|
+
);
|
|
1621
|
+
misc_module.rsync_drive_resources_to_remote_servers("workspace", app_id);
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
case "user": {
|
|
1625
|
+
/// check existing file
|
|
1626
|
+
const user_drive_res = await db_module.find_couch_query("drive", {
|
|
1627
|
+
selector: { docType: "user_drive", originalname, stat: 3 },
|
|
1628
|
+
limit: 99,
|
|
1629
|
+
});
|
|
1630
|
+
if (user_drive_res.docs.length) {
|
|
1631
|
+
return {
|
|
1632
|
+
code: -762,
|
|
1633
|
+
data: "file already exist",
|
|
1634
|
+
duplicates: user_drive_res.docs,
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1638
|
+
ref = uid;
|
|
1639
|
+
file_name =
|
|
1640
|
+
"drv_" + ref + "_" + (await _common.xuda_get_uuid(drive_type)) + ext;
|
|
1641
|
+
|
|
1642
|
+
doc.server_file_name = file_name;
|
|
1643
|
+
|
|
1644
|
+
doc.bucket = {
|
|
1645
|
+
[`${process.env.XUDA_HOSTNAME}`]: await upload_file_to_spaces(
|
|
1646
|
+
tempPath,
|
|
1647
|
+
ref,
|
|
1648
|
+
drive_type,
|
|
1649
|
+
file_name
|
|
1650
|
+
),
|
|
1651
|
+
};
|
|
1652
|
+
doc._id = file_name;
|
|
1653
|
+
save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
1654
|
+
misc_module.rsync_drive_resources_to_remote_servers("user", uid);
|
|
1655
|
+
break;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
default:
|
|
1659
|
+
break;
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1541
1662
|
const ocr_drive_file = async function (doc) {
|
|
1542
1663
|
const { drive_type, target_file } = doc;
|
|
1543
1664
|
var doc_ret;
|