@xuda.io/drive_module 1.1.488 → 1.1.490
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 +0 -211
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -356,33 +356,6 @@ exports.get_drive_file_info = async function (req) {
|
|
|
356
356
|
try {
|
|
357
357
|
const { type, drive_type, app_id, file_name } = req;
|
|
358
358
|
var { file_path } = req;
|
|
359
|
-
// const app_id_master = await _common.get_project_app_id(app_id, true);
|
|
360
|
-
// if (drive_type === "workspace") {
|
|
361
|
-
// if (!file_path.includes(app_id)) {
|
|
362
|
-
// return {
|
|
363
|
-
// code: -400,
|
|
364
|
-
// data: "error - file_path unauthorized",
|
|
365
|
-
// };
|
|
366
|
-
// }
|
|
367
|
-
// }
|
|
368
|
-
|
|
369
|
-
// path.basename(file_obj.originalname)
|
|
370
|
-
|
|
371
|
-
// if (drive_type === "workspace") {
|
|
372
|
-
// file_path = path.join(_conf.workspace_drive_path, app_id_master, file_path);
|
|
373
|
-
// }
|
|
374
|
-
// var doc = {};
|
|
375
|
-
|
|
376
|
-
// var doc_id;
|
|
377
|
-
// if (drive_type === "studio") {
|
|
378
|
-
// const target_dir = path.join(_conf[`studio_drive_path`], app_id_master);
|
|
379
|
-
|
|
380
|
-
// doc_id = file_path.replace(target_dir, "");
|
|
381
|
-
// } else {
|
|
382
|
-
// doc_id = file_name;
|
|
383
|
-
// }
|
|
384
|
-
|
|
385
|
-
// const doc_ret = await db_module.get_app_couch_doc(app_id_reference, doc_id);
|
|
386
359
|
|
|
387
360
|
let doc_ret,
|
|
388
361
|
doc_id,
|
|
@@ -1520,183 +1493,6 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
1520
1493
|
break;
|
|
1521
1494
|
}
|
|
1522
1495
|
|
|
1523
|
-
// const target_dir = path.join(_conf[`${drive_type}_drive_path`], ref);
|
|
1524
|
-
// const ext = path.extname(file_obj.originalname).toLowerCase();
|
|
1525
|
-
// const originalname = path.basename(file_obj.originalname);
|
|
1526
|
-
// var file_name = path.join(
|
|
1527
|
-
// req.path.replace(target_dir, ""),
|
|
1528
|
-
// file_obj.originalname
|
|
1529
|
-
// );
|
|
1530
|
-
|
|
1531
|
-
// if (drive_type !== "studio") {
|
|
1532
|
-
// file_name =
|
|
1533
|
-
// "drv_" + ref + "_" + (await _common.xuda_get_uuid(drive_type)) + ext;
|
|
1534
|
-
// }
|
|
1535
|
-
|
|
1536
|
-
// keep the original filename to support migration
|
|
1537
|
-
// if (drive_type !== "user") {
|
|
1538
|
-
// if (file_obj.originalname.includes(`drv_${app_id}`)) {
|
|
1539
|
-
// file_name = file_obj.originalname;
|
|
1540
|
-
// }
|
|
1541
|
-
// }
|
|
1542
|
-
|
|
1543
|
-
// const target_file = path.join(
|
|
1544
|
-
// req.path !== "/" ? req.path : target_dir,
|
|
1545
|
-
// drive_type !== "studio" ? file_name : originalname
|
|
1546
|
-
// );
|
|
1547
|
-
|
|
1548
|
-
// if (
|
|
1549
|
-
// [..._conf.allowedExts_drive, ..._conf.archive_drive_ext].includes(ext)
|
|
1550
|
-
// ) {
|
|
1551
|
-
// if (!(await fs_module.file_exists(target_dir))) {
|
|
1552
|
-
// await fs_module.mkdir(target_dir, 0o775, true);
|
|
1553
|
-
// } else {
|
|
1554
|
-
// if (await fs_module.file_exists(target_file)) {
|
|
1555
|
-
// await fs_module.unlink(target_file);
|
|
1556
|
-
// }
|
|
1557
|
-
// }
|
|
1558
|
-
// if (drive_type === "studio") {
|
|
1559
|
-
// await fs_module.copy(tempPath, target_file);
|
|
1560
|
-
// }
|
|
1561
|
-
|
|
1562
|
-
//// OCR ////
|
|
1563
|
-
|
|
1564
|
-
// var ocr_stat = ["image", "application", "text"].includes(
|
|
1565
|
-
// file_obj.mimetype.split("/")[0]
|
|
1566
|
-
// )
|
|
1567
|
-
// ? 1
|
|
1568
|
-
// : 0;
|
|
1569
|
-
|
|
1570
|
-
// var ocr = "";
|
|
1571
|
-
// debugger;
|
|
1572
|
-
// switch (file_obj.mimetype.split("/")[0]) {
|
|
1573
|
-
// case "image": {
|
|
1574
|
-
// const tesseract = require("node-tesseract-ocr");
|
|
1575
|
-
// ocr = await tesseract.recognize(target_file, {
|
|
1576
|
-
// lang: "eng",
|
|
1577
|
-
// oem: 1,
|
|
1578
|
-
// psm: 3,
|
|
1579
|
-
// });
|
|
1580
|
-
|
|
1581
|
-
// break;
|
|
1582
|
-
// }
|
|
1583
|
-
|
|
1584
|
-
// case "application": {
|
|
1585
|
-
// switch (file_obj.mimetype.split("/")[1]) {
|
|
1586
|
-
// case "pdf": {
|
|
1587
|
-
// const { convertPDF } = require("pdf2image");
|
|
1588
|
-
// const tesseract = require("node-tesseract-ocr");
|
|
1589
|
-
|
|
1590
|
-
// const images = await convertPDF(target_file);
|
|
1591
|
-
// for await (const imageData of images) {
|
|
1592
|
-
// ocr += await tesseract.recognize(imageData.path, {
|
|
1593
|
-
// lang: "eng",
|
|
1594
|
-
// oem: 1,
|
|
1595
|
-
// psm: 3,
|
|
1596
|
-
// });
|
|
1597
|
-
// }
|
|
1598
|
-
// break;
|
|
1599
|
-
// }
|
|
1600
|
-
|
|
1601
|
-
// case "vnd.openxmlformats-officedocument.wordprocessingml.document": {
|
|
1602
|
-
// const mammoth = require("mammoth");
|
|
1603
|
-
// ocr = (await mammoth.extractRawText({ path: target_file })).value;
|
|
1604
|
-
// break;
|
|
1605
|
-
// }
|
|
1606
|
-
|
|
1607
|
-
// case "nd.ms-excel":
|
|
1608
|
-
// case "vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
|
|
1609
|
-
// const xlsx = require("node-xlsx").default;
|
|
1610
|
-
|
|
1611
|
-
// const sheets = xlsx.parse(target_file);
|
|
1612
|
-
// sheets.forEach((sheet) => {
|
|
1613
|
-
// console.log(`Sheet: ${sheet.name}`);
|
|
1614
|
-
// sheet.data.forEach((row) => {
|
|
1615
|
-
// ocr += row.join(" "); // Join all cells in the row
|
|
1616
|
-
// });
|
|
1617
|
-
// });
|
|
1618
|
-
// break;
|
|
1619
|
-
// }
|
|
1620
|
-
|
|
1621
|
-
// case "vnd.ms-powerpoint":
|
|
1622
|
-
// case "vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
1623
|
-
// // tbd
|
|
1624
|
-
// break;
|
|
1625
|
-
|
|
1626
|
-
// default:
|
|
1627
|
-
// ocr = (await fs_module.read_file(target_file)).data;
|
|
1628
|
-
// break;
|
|
1629
|
-
// }
|
|
1630
|
-
// break;
|
|
1631
|
-
// }
|
|
1632
|
-
|
|
1633
|
-
// case "text": {
|
|
1634
|
-
// ocr = (await fs_module.read_file(target_file)).data;
|
|
1635
|
-
// break;
|
|
1636
|
-
// }
|
|
1637
|
-
|
|
1638
|
-
// default:
|
|
1639
|
-
// break;
|
|
1640
|
-
// }
|
|
1641
|
-
// var size = 0;
|
|
1642
|
-
// const fs = require("fs").promises;
|
|
1643
|
-
// const stat = await fs.stat(tempPath);
|
|
1644
|
-
// if (stat.isFile()) {
|
|
1645
|
-
// size = stat.size;
|
|
1646
|
-
// }
|
|
1647
|
-
|
|
1648
|
-
// var doc = {
|
|
1649
|
-
// _id: file_name,
|
|
1650
|
-
// docType: `${drive_type}_drive`,
|
|
1651
|
-
// stat: 3,
|
|
1652
|
-
// server_file_name: file_name,
|
|
1653
|
-
// originalname,
|
|
1654
|
-
// uid,
|
|
1655
|
-
// type: "file",
|
|
1656
|
-
// date_created: Date.now(),
|
|
1657
|
-
// ip: headers["cf-connecting-ip"],
|
|
1658
|
-
// country: headers["cf-ipcountry"],
|
|
1659
|
-
// file_ext: ext,
|
|
1660
|
-
// is_archive: _conf.archive_drive_ext.includes(ext) ? true : false,
|
|
1661
|
-
// drive_type,
|
|
1662
|
-
// mime: file_obj.mimetype,
|
|
1663
|
-
// ocr_stat,
|
|
1664
|
-
// target_file,
|
|
1665
|
-
// file_path: req.path,
|
|
1666
|
-
// bucket: {
|
|
1667
|
-
// [`${process.env.XUDA_HOSTNAME}`]: await upload_file_to_spaces(
|
|
1668
|
-
// tempPath,
|
|
1669
|
-
// ref,
|
|
1670
|
-
// drive_type,
|
|
1671
|
-
// file_name
|
|
1672
|
-
// ),
|
|
1673
|
-
// },
|
|
1674
|
-
// size,
|
|
1675
|
-
// };
|
|
1676
|
-
// doc = { ...doc, ...(await get_file_info(tempPath)) };
|
|
1677
|
-
|
|
1678
|
-
// if (drive_type !== "user") {
|
|
1679
|
-
// doc.app_id = await _common.get_project_app_id(app_id);
|
|
1680
|
-
// doc.app_id_reference = await _common.get_project_app_id(app_id, true);
|
|
1681
|
-
// }
|
|
1682
|
-
|
|
1683
|
-
// var save_ret;
|
|
1684
|
-
|
|
1685
|
-
// switch (drive_type) {
|
|
1686
|
-
// case "workspace":
|
|
1687
|
-
// case "studio":
|
|
1688
|
-
// const app_id_reference = await _common.get_project_app_id(app_id);
|
|
1689
|
-
// save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
|
|
1690
|
-
// break;
|
|
1691
|
-
|
|
1692
|
-
// case "user":
|
|
1693
|
-
// save_ret = await db_module.save_couch_doc("xuda_drive", doc);
|
|
1694
|
-
// break;
|
|
1695
|
-
|
|
1696
|
-
// default:
|
|
1697
|
-
// break;
|
|
1698
|
-
// }
|
|
1699
|
-
|
|
1700
1496
|
let file_url = `https://${process.env.XUDA_HOSTNAME}/${drive_type}-drive/${ref}/${file_name}`;
|
|
1701
1497
|
if (["workspace"].includes(req.drive_type)) {
|
|
1702
1498
|
file_url = `https://${process.env.XUDA_HOSTNAME}/workspace-drive/${file_name}`;
|
|
@@ -1711,13 +1507,6 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
|
|
|
1711
1507
|
filename: file_obj.originalname,
|
|
1712
1508
|
},
|
|
1713
1509
|
};
|
|
1714
|
-
// }
|
|
1715
|
-
|
|
1716
|
-
// await fs_module.unlink(tempPath);
|
|
1717
|
-
|
|
1718
|
-
// throw new Error(
|
|
1719
|
-
// `Only ${_conf.allowedExts_drive.toString()} files are allowed!`
|
|
1720
|
-
// );
|
|
1721
1510
|
} catch (err) {
|
|
1722
1511
|
return { code: -400, data: err.message };
|
|
1723
1512
|
}
|