zet-lib 1.5.0 → 1.5.2
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/lib/Util.js +15 -9
- package/lib/zAppRouter.js +151 -179
- package/package.json +1 -1
package/lib/Util.js
CHANGED
|
@@ -622,16 +622,22 @@ Util.toNumber = function (num) {
|
|
|
622
622
|
};
|
|
623
623
|
|
|
624
624
|
Util.formatNumber = function (num, thousandSeparator = ".") {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
625
|
+
try {
|
|
626
|
+
const strValue = String(num);
|
|
627
|
+
// Split into integer and decimal parts
|
|
628
|
+
const parts = strValue.split(",");
|
|
629
|
+
// Format integer part with thousand separators
|
|
630
|
+
const integerPart = parts[0].replace(
|
|
631
|
+
/\B(?=(\d{3})+(?!\d))/g,
|
|
632
|
+
thousandSeparator
|
|
632
633
|
);
|
|
633
|
-
|
|
634
|
-
|
|
634
|
+
// If there's a decimal part, add it back
|
|
635
|
+
if (parts.length > 1) {
|
|
636
|
+
return `${integerPart},${parts[1]}`;
|
|
637
|
+
}
|
|
638
|
+
return integerPart;
|
|
639
|
+
} catch (e) {
|
|
640
|
+
console.log(e);
|
|
635
641
|
}
|
|
636
642
|
};
|
|
637
643
|
|
package/lib/zAppRouter.js
CHANGED
|
@@ -1769,75 +1769,67 @@ const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
1769
1769
|
|
|
1770
1770
|
let dbx = zDropbox.dbx;
|
|
1771
1771
|
// Upload endpoint
|
|
1772
|
-
router.post(
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
await zDropbox.ensureFolder(dir);
|
|
1788
|
-
const filePath = `${dir}/${fileName}`;
|
|
1789
|
-
/*console.log("Uploading file to path:", filePath);
|
|
1772
|
+
router.post("/zdropbox/:table/:field", async (req, res) => {
|
|
1773
|
+
try {
|
|
1774
|
+
if (!req.files || !req.files.file) {
|
|
1775
|
+
return res.status(400).json({ error: "No file uploaded" });
|
|
1776
|
+
}
|
|
1777
|
+
const userId = res.locals.userId;
|
|
1778
|
+
const table = req.params.table;
|
|
1779
|
+
const field = req.params.field;
|
|
1780
|
+
const file = req.files.file;
|
|
1781
|
+
const fileName = file.name;
|
|
1782
|
+
//ensure folder
|
|
1783
|
+
const dir = `/temps/${table}/${field}/${userId}`;
|
|
1784
|
+
await zDropbox.ensureFolder(dir);
|
|
1785
|
+
const filePath = `${dir}/${fileName}`;
|
|
1786
|
+
/*console.log("Uploading file to path:", filePath);
|
|
1790
1787
|
console.log("File size:", file.size);
|
|
1791
1788
|
console.log("File name:", fileName);*/
|
|
1792
1789
|
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
}
|
|
1790
|
+
const response = await dbx.filesUpload({
|
|
1791
|
+
path: filePath,
|
|
1792
|
+
contents: file.data,
|
|
1793
|
+
mode: { ".tag": "add" },
|
|
1794
|
+
autorename: true,
|
|
1795
|
+
});
|
|
1796
|
+
res.json("ok");
|
|
1797
|
+
} catch (error) {
|
|
1798
|
+
console.error("Error details:", {
|
|
1799
|
+
message: error.message,
|
|
1800
|
+
stack: error.stack,
|
|
1801
|
+
response: error.response,
|
|
1802
|
+
});
|
|
1803
|
+
res.status(500).json({
|
|
1804
|
+
error: "Failed to upload file",
|
|
1805
|
+
details: error.message,
|
|
1806
|
+
});
|
|
1811
1807
|
}
|
|
1812
|
-
);
|
|
1808
|
+
});
|
|
1813
1809
|
|
|
1814
|
-
router.post(
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
if (
|
|
1826
|
-
arr.
|
|
1827
|
-
} else {
|
|
1828
|
-
if (myCache.has(name)) {
|
|
1829
|
-
arr = myCache.get(name);
|
|
1830
|
-
}
|
|
1831
|
-
arr = Util.arrayDelete(arr, body.file);
|
|
1810
|
+
router.post("/zdropbox-attributes", async (req, res) => {
|
|
1811
|
+
try {
|
|
1812
|
+
let userId = res.locals.userId;
|
|
1813
|
+
let body = req.body;
|
|
1814
|
+
console.log(body);
|
|
1815
|
+
let category = body.category;
|
|
1816
|
+
let name = `dropbox__${userId}__${body.table}__${body.field}__${body.type}`;
|
|
1817
|
+
let arr = myCache.has(name) ? myCache.get(name) : [];
|
|
1818
|
+
if (category === "add") {
|
|
1819
|
+
arr.push(body.file);
|
|
1820
|
+
} else {
|
|
1821
|
+
if (myCache.has(name)) {
|
|
1822
|
+
arr = myCache.get(name);
|
|
1832
1823
|
}
|
|
1833
|
-
|
|
1834
|
-
res.json("ok");
|
|
1835
|
-
} catch (e) {
|
|
1836
|
-
console.log(e);
|
|
1837
|
-
res.status(500).send(e + "");
|
|
1824
|
+
arr = Util.arrayDelete(arr, body.file);
|
|
1838
1825
|
}
|
|
1826
|
+
myCache.set(name, arr);
|
|
1827
|
+
res.json("ok");
|
|
1828
|
+
} catch (e) {
|
|
1829
|
+
console.log(e);
|
|
1830
|
+
res.status(500).send(e + "");
|
|
1839
1831
|
}
|
|
1840
|
-
);
|
|
1832
|
+
});
|
|
1841
1833
|
|
|
1842
1834
|
//get all files and meta in dropbox
|
|
1843
1835
|
router.post("/zdropbox-files", async (req, res) => {
|
|
@@ -1868,140 +1860,120 @@ router.post("/zdropbox-files", async (req, res) => {
|
|
|
1868
1860
|
res.json(datas);
|
|
1869
1861
|
});
|
|
1870
1862
|
|
|
1871
|
-
router.post(
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
);
|
|
1896
|
-
}
|
|
1897
|
-
}, 4000);
|
|
1898
|
-
}
|
|
1899
|
-
} catch (e) {
|
|
1900
|
-
console.log(e);
|
|
1901
|
-
res.json(datas);
|
|
1863
|
+
router.post("/zdropbox-file/:index", async (req, res) => {
|
|
1864
|
+
let datas = {};
|
|
1865
|
+
try {
|
|
1866
|
+
const room = res.locals.token;
|
|
1867
|
+
const index = req.params.index;
|
|
1868
|
+
const { fileName, table, field } = req.body;
|
|
1869
|
+
let dir = `/${table}/${field}`;
|
|
1870
|
+
let pathFile = `${dir}/${fileName}`;
|
|
1871
|
+
console.log(pathFile);
|
|
1872
|
+
let jsonMessage = await zDropbox.file(fileName, table, field, index);
|
|
1873
|
+
if (jsonMessage.status == 1) {
|
|
1874
|
+
res.json(jsonMessage.datas);
|
|
1875
|
+
} else {
|
|
1876
|
+
setTimeout(async () => {
|
|
1877
|
+
jsonMessage = await zDropbox.file(fileName, table, field, index);
|
|
1878
|
+
if (jsonMessage.status == 1) {
|
|
1879
|
+
res.json(jsonMessage.datas);
|
|
1880
|
+
} else {
|
|
1881
|
+
io.to(room).emit(
|
|
1882
|
+
"errormessage",
|
|
1883
|
+
`Please reload your browser !! Error ${pathFile} not exist in dropbox, `
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
}, 4000);
|
|
1902
1887
|
}
|
|
1888
|
+
} catch (e) {
|
|
1889
|
+
console.log(e);
|
|
1890
|
+
res.json(datas);
|
|
1903
1891
|
}
|
|
1904
|
-
);
|
|
1892
|
+
});
|
|
1905
1893
|
|
|
1906
1894
|
// Delete file dicache dulu kemudian submit delete dropbox file
|
|
1907
|
-
router.post(
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
path: filePath,
|
|
1938
|
-
});
|
|
1939
|
-
arr = Util.arrayDelete(arr, body.file);
|
|
1940
|
-
myCache.set(cacheName, arr);
|
|
1941
|
-
} catch (e) {
|
|
1942
|
-
console.log(e);
|
|
1943
|
-
}
|
|
1944
|
-
} else {
|
|
1945
|
-
arr.push(body.file);
|
|
1895
|
+
router.post("/zdropbox-remove/", async (req, res) => {
|
|
1896
|
+
try {
|
|
1897
|
+
let body = req.body;
|
|
1898
|
+
//console.log(body);
|
|
1899
|
+
const userId = res.locals.userId;
|
|
1900
|
+
const fileName = body.file;
|
|
1901
|
+
let cname = body.cname.replace("ZUSER___ID", userId);
|
|
1902
|
+
let cacheName = cname;
|
|
1903
|
+
//console.log(cacheName);
|
|
1904
|
+
let splits = cname.split("__");
|
|
1905
|
+
let table = splits[2];
|
|
1906
|
+
let field = splits[3];
|
|
1907
|
+
let type = splits[4];
|
|
1908
|
+
const dir = `/temps/${table}/${field}/${userId}`;
|
|
1909
|
+
await zDropbox.ensureFolder(dir);
|
|
1910
|
+
const filePath = `${dir}/${fileName}`;
|
|
1911
|
+
let arr = [];
|
|
1912
|
+
if (type != "create") {
|
|
1913
|
+
cacheName = cacheName + "__remove";
|
|
1914
|
+
}
|
|
1915
|
+
if (myCache.has(cacheName)) {
|
|
1916
|
+
arr = myCache.get(cacheName);
|
|
1917
|
+
}
|
|
1918
|
+
//console.log(cacheName)
|
|
1919
|
+
if (type == "create") {
|
|
1920
|
+
try {
|
|
1921
|
+
await dbx.filesDeleteV2({
|
|
1922
|
+
path: filePath,
|
|
1923
|
+
});
|
|
1924
|
+
arr = Util.arrayDelete(arr, body.file);
|
|
1946
1925
|
myCache.set(cacheName, arr);
|
|
1926
|
+
} catch (e) {
|
|
1927
|
+
console.log(e);
|
|
1947
1928
|
}
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
res.status(500).json({ error: "Error deleting file" });
|
|
1929
|
+
} else {
|
|
1930
|
+
arr.push(body.file);
|
|
1931
|
+
myCache.set(cacheName, arr);
|
|
1952
1932
|
}
|
|
1933
|
+
res.json({ success: true });
|
|
1934
|
+
} catch (error) {
|
|
1935
|
+
console.error("Error deleting file:", error);
|
|
1936
|
+
res.status(500).json({ error: "Error deleting file" });
|
|
1953
1937
|
}
|
|
1954
|
-
);
|
|
1938
|
+
});
|
|
1955
1939
|
|
|
1956
1940
|
// Endpoint to check token status
|
|
1957
|
-
router.get(
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
res.json({ status: "valid" });
|
|
1964
|
-
} catch (error) {
|
|
1965
|
-
res.status(401).json({ status: "invalid" });
|
|
1966
|
-
}
|
|
1941
|
+
router.get("/zdropbox-check-token", async (req, res) => {
|
|
1942
|
+
try {
|
|
1943
|
+
await dbx.usersGetCurrentAccount();
|
|
1944
|
+
res.json({ status: "valid" });
|
|
1945
|
+
} catch (error) {
|
|
1946
|
+
res.status(401).json({ status: "invalid" });
|
|
1967
1947
|
}
|
|
1968
|
-
);
|
|
1948
|
+
});
|
|
1969
1949
|
|
|
1970
1950
|
// Get temporary link for a file
|
|
1971
|
-
router.post(
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
} catch (error) {
|
|
1981
|
-
console.error("Error getting temporary link:", error);
|
|
1982
|
-
res.status(500).json({ error: "Error getting temporary link" });
|
|
1983
|
-
}
|
|
1951
|
+
router.post("/zdropbox-get-temp-link", async (req, res) => {
|
|
1952
|
+
try {
|
|
1953
|
+
const response = await dbx.filesGetTemporaryLink({
|
|
1954
|
+
path: req.body.path,
|
|
1955
|
+
});
|
|
1956
|
+
res.json({ link: response.result.link });
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
console.error("Error getting temporary link:", error);
|
|
1959
|
+
res.status(500).json({ error: "Error getting temporary link" });
|
|
1984
1960
|
}
|
|
1985
|
-
);
|
|
1961
|
+
});
|
|
1986
1962
|
|
|
1987
|
-
router.get(
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
} catch (e) {
|
|
2000
|
-
console.log(e);
|
|
2001
|
-
res.send(e);
|
|
2002
|
-
}
|
|
1963
|
+
router.get("/zdropbox-view/:table/:field/:item", async (req, res) => {
|
|
1964
|
+
try {
|
|
1965
|
+
let item = req.params.item;
|
|
1966
|
+
item = item.substring(13);
|
|
1967
|
+
let filePath = `/${req.params.table}/${req.params.field}/${req.params.item}`;
|
|
1968
|
+
const response = await dbx.filesGetTemporaryLink({
|
|
1969
|
+
path: filePath,
|
|
1970
|
+
});
|
|
1971
|
+
res.send(`<img src="${response.result.link}">`);
|
|
1972
|
+
} catch (e) {
|
|
1973
|
+
console.log(e);
|
|
1974
|
+
res.send(e);
|
|
2003
1975
|
}
|
|
2004
|
-
);
|
|
1976
|
+
});
|
|
2005
1977
|
|
|
2006
1978
|
// Download and zip files endpoint
|
|
2007
1979
|
router.get("/zdownloads-dropbox/:table/:field/:id", async (req, res) => {
|