@xuda.io/drive_module 1.1.489 → 1.1.491

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.
Files changed (2) hide show
  1. package/index.js +0 -205
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1493,183 +1493,6 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
1493
1493
  break;
1494
1494
  }
1495
1495
 
1496
- // const target_dir = path.join(_conf[`${drive_type}_drive_path`], ref);
1497
- // const ext = path.extname(file_obj.originalname).toLowerCase();
1498
- // const originalname = path.basename(file_obj.originalname);
1499
- // var file_name = path.join(
1500
- // req.path.replace(target_dir, ""),
1501
- // file_obj.originalname
1502
- // );
1503
-
1504
- // if (drive_type !== "studio") {
1505
- // file_name =
1506
- // "drv_" + ref + "_" + (await _common.xuda_get_uuid(drive_type)) + ext;
1507
- // }
1508
-
1509
- // keep the original filename to support migration
1510
- // if (drive_type !== "user") {
1511
- // if (file_obj.originalname.includes(`drv_${app_id}`)) {
1512
- // file_name = file_obj.originalname;
1513
- // }
1514
- // }
1515
-
1516
- // const target_file = path.join(
1517
- // req.path !== "/" ? req.path : target_dir,
1518
- // drive_type !== "studio" ? file_name : originalname
1519
- // );
1520
-
1521
- // if (
1522
- // [..._conf.allowedExts_drive, ..._conf.archive_drive_ext].includes(ext)
1523
- // ) {
1524
- // if (!(await fs_module.file_exists(target_dir))) {
1525
- // await fs_module.mkdir(target_dir, 0o775, true);
1526
- // } else {
1527
- // if (await fs_module.file_exists(target_file)) {
1528
- // await fs_module.unlink(target_file);
1529
- // }
1530
- // }
1531
- // if (drive_type === "studio") {
1532
- // await fs_module.copy(tempPath, target_file);
1533
- // }
1534
-
1535
- //// OCR ////
1536
-
1537
- // var ocr_stat = ["image", "application", "text"].includes(
1538
- // file_obj.mimetype.split("/")[0]
1539
- // )
1540
- // ? 1
1541
- // : 0;
1542
-
1543
- // var ocr = "";
1544
- // debugger;
1545
- // switch (file_obj.mimetype.split("/")[0]) {
1546
- // case "image": {
1547
- // const tesseract = require("node-tesseract-ocr");
1548
- // ocr = await tesseract.recognize(target_file, {
1549
- // lang: "eng",
1550
- // oem: 1,
1551
- // psm: 3,
1552
- // });
1553
-
1554
- // break;
1555
- // }
1556
-
1557
- // case "application": {
1558
- // switch (file_obj.mimetype.split("/")[1]) {
1559
- // case "pdf": {
1560
- // const { convertPDF } = require("pdf2image");
1561
- // const tesseract = require("node-tesseract-ocr");
1562
-
1563
- // const images = await convertPDF(target_file);
1564
- // for await (const imageData of images) {
1565
- // ocr += await tesseract.recognize(imageData.path, {
1566
- // lang: "eng",
1567
- // oem: 1,
1568
- // psm: 3,
1569
- // });
1570
- // }
1571
- // break;
1572
- // }
1573
-
1574
- // case "vnd.openxmlformats-officedocument.wordprocessingml.document": {
1575
- // const mammoth = require("mammoth");
1576
- // ocr = (await mammoth.extractRawText({ path: target_file })).value;
1577
- // break;
1578
- // }
1579
-
1580
- // case "nd.ms-excel":
1581
- // case "vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
1582
- // const xlsx = require("node-xlsx").default;
1583
-
1584
- // const sheets = xlsx.parse(target_file);
1585
- // sheets.forEach((sheet) => {
1586
- // console.log(`Sheet: ${sheet.name}`);
1587
- // sheet.data.forEach((row) => {
1588
- // ocr += row.join(" "); // Join all cells in the row
1589
- // });
1590
- // });
1591
- // break;
1592
- // }
1593
-
1594
- // case "vnd.ms-powerpoint":
1595
- // case "vnd.openxmlformats-officedocument.presentationml.presentation":
1596
- // // tbd
1597
- // break;
1598
-
1599
- // default:
1600
- // ocr = (await fs_module.read_file(target_file)).data;
1601
- // break;
1602
- // }
1603
- // break;
1604
- // }
1605
-
1606
- // case "text": {
1607
- // ocr = (await fs_module.read_file(target_file)).data;
1608
- // break;
1609
- // }
1610
-
1611
- // default:
1612
- // break;
1613
- // }
1614
- // var size = 0;
1615
- // const fs = require("fs").promises;
1616
- // const stat = await fs.stat(tempPath);
1617
- // if (stat.isFile()) {
1618
- // size = stat.size;
1619
- // }
1620
-
1621
- // var doc = {
1622
- // _id: file_name,
1623
- // docType: `${drive_type}_drive`,
1624
- // stat: 3,
1625
- // server_file_name: file_name,
1626
- // originalname,
1627
- // uid,
1628
- // type: "file",
1629
- // date_created: Date.now(),
1630
- // ip: headers["cf-connecting-ip"],
1631
- // country: headers["cf-ipcountry"],
1632
- // file_ext: ext,
1633
- // is_archive: _conf.archive_drive_ext.includes(ext) ? true : false,
1634
- // drive_type,
1635
- // mime: file_obj.mimetype,
1636
- // ocr_stat,
1637
- // target_file,
1638
- // file_path: req.path,
1639
- // bucket: {
1640
- // [`${process.env.XUDA_HOSTNAME}`]: await upload_file_to_spaces(
1641
- // tempPath,
1642
- // ref,
1643
- // drive_type,
1644
- // file_name
1645
- // ),
1646
- // },
1647
- // size,
1648
- // };
1649
- // doc = { ...doc, ...(await get_file_info(tempPath)) };
1650
-
1651
- // if (drive_type !== "user") {
1652
- // doc.app_id = await _common.get_project_app_id(app_id);
1653
- // doc.app_id_reference = await _common.get_project_app_id(app_id, true);
1654
- // }
1655
-
1656
- // var save_ret;
1657
-
1658
- // switch (drive_type) {
1659
- // case "workspace":
1660
- // case "studio":
1661
- // const app_id_reference = await _common.get_project_app_id(app_id);
1662
- // save_ret = await db_module.save_app_couch_doc(app_id_reference, doc);
1663
- // break;
1664
-
1665
- // case "user":
1666
- // save_ret = await db_module.save_couch_doc("xuda_drive", doc);
1667
- // break;
1668
-
1669
- // default:
1670
- // break;
1671
- // }
1672
-
1673
1496
  let file_url = `https://${process.env.XUDA_HOSTNAME}/${drive_type}-drive/${ref}/${file_name}`;
1674
1497
  if (["workspace"].includes(req.drive_type)) {
1675
1498
  file_url = `https://${process.env.XUDA_HOSTNAME}/workspace-drive/${file_name}`;
@@ -1684,13 +1507,6 @@ exports.upload_drive_file = async function (req, job_id, headers, file_obj) {
1684
1507
  filename: file_obj.originalname,
1685
1508
  },
1686
1509
  };
1687
- // }
1688
-
1689
- // await fs_module.unlink(tempPath);
1690
-
1691
- // throw new Error(
1692
- // `Only ${_conf.allowedExts_drive.toString()} files are allowed!`
1693
- // );
1694
1510
  } catch (err) {
1695
1511
  return { code: -400, data: err.message };
1696
1512
  }
@@ -2057,29 +1873,8 @@ exports.get_drive_size = async function (req) {
2057
1873
  "/"
2058
1874
  );
2059
1875
 
2060
- // async function getFolderSize(folderPath) {
2061
- // let totalSize = 0;
2062
-
2063
- // async function calculateSize(dirPath) {
2064
- // const entries = await fse.readdir(dirPath, { withFileTypes: true });
2065
- // for (let entry of entries) {
2066
- // const fullPath = path.join(dirPath, entry.name);
2067
- // if (entry.isDirectory()) {
2068
- // await calculateSize(fullPath);
2069
- // } else {
2070
- // const fileStats = await fse.stat(fullPath);
2071
- // totalSize += fileStats.size;
2072
- // }
2073
- // }
2074
- // }
2075
-
2076
- // await calculateSize(folderPath);
2077
- // return totalSize;
2078
- // }
2079
-
2080
1876
  const size = await get_folder_size(directoryPath, drive_type, app_id);
2081
1877
 
2082
- // console.log(`Total size of folder "${directoryPath}" is ${size} bytes.`);
2083
1878
  return { code: 200, data: size };
2084
1879
  } catch (err) {
2085
1880
  return { code: -200, data: err.message };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/drive_module",
3
- "version": "1.1.489",
3
+ "version": "1.1.491",
4
4
  "description": "Xuda Drive Server Module",
5
5
  "main": "index.js",
6
6
  "dependencies": {