zet-lib 5.0.2 → 5.0.3
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/zAppRouter.js +25 -15
- package/lib/zRoute.js +13 -4
- package/package.json +1 -1
package/lib/zAppRouter.js
CHANGED
|
@@ -1609,24 +1609,34 @@ router.get("/addapproval-models", async (req, res) => {
|
|
|
1609
1609
|
//post dropzone widget
|
|
1610
1610
|
router.post("/zdropzone", async (req, res) => {
|
|
1611
1611
|
try {
|
|
1612
|
-
|
|
1613
|
-
if (userId) {
|
|
1614
|
-
|
|
1615
|
-
if (!fs.existsSync(dir)) {
|
|
1616
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
1617
|
-
}
|
|
1618
|
-
let filename = req.files.file.name;
|
|
1619
|
-
req.files.file.mv(path.join(dir, filename), function (err) {
|
|
1620
|
-
if (err) {
|
|
1621
|
-
return res.status(500).send(err + "");
|
|
1622
|
-
}
|
|
1623
|
-
});
|
|
1612
|
+
const userId = res.locals.userId;
|
|
1613
|
+
if (!userId) {
|
|
1614
|
+
return res.status(401).send("Unauthorized");
|
|
1624
1615
|
}
|
|
1625
|
-
|
|
1616
|
+
|
|
1617
|
+
const file = req?.files?.file;
|
|
1618
|
+
if (!file || !file.name) {
|
|
1619
|
+
return res.status(400).send("No file uploaded");
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
const dir = path.join(dirRoot, "public", "zdropzone", `${userId}`);
|
|
1623
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
1624
|
+
|
|
1625
|
+
// Prevent path traversal; keep only the base name.
|
|
1626
|
+
const originalName = path.basename(file.name);
|
|
1627
|
+
const uniquePrefix = `${Date.now()}_${Math.random().toString(16).slice(2, 10)}_`;
|
|
1628
|
+
const savedName = `${uniquePrefix}${originalName}`;
|
|
1629
|
+
const destPath = path.join(dir, savedName);
|
|
1630
|
+
|
|
1631
|
+
await new Promise((resolve, reject) => {
|
|
1632
|
+
file.mv(destPath, (err) => (err ? reject(err) : resolve()));
|
|
1633
|
+
});
|
|
1634
|
+
|
|
1635
|
+
// Return the stored filename so client can reference it uniquely
|
|
1636
|
+
res.json({ ok: true, fileName: savedName, originalName });
|
|
1626
1637
|
} catch (e) {
|
|
1627
1638
|
console.log(e);
|
|
1628
|
-
res.status(500);
|
|
1629
|
-
res.send(e + "");
|
|
1639
|
+
res.status(500).send(e + "");
|
|
1630
1640
|
}
|
|
1631
1641
|
});
|
|
1632
1642
|
|
package/lib/zRoute.js
CHANGED
|
@@ -4538,6 +4538,18 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4538
4538
|
addRemoveLinks: !0,
|
|
4539
4539
|
maxFilesize: 30,
|
|
4540
4540
|
headers: {"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")},
|
|
4541
|
+
success: function(file, response) {
|
|
4542
|
+
const type = window.location.href.split("/").pop();
|
|
4543
|
+
if(response && response.fileName) {
|
|
4544
|
+
// Persist server-side unique name on the file object so remove uses it too
|
|
4545
|
+
file.name = response.fileName;
|
|
4546
|
+
if(file.upload) file.upload.filename = response.fileName;
|
|
4547
|
+
ajaxPost("/zdropzone-attributes",{file:response.fileName,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
4548
|
+
} else {
|
|
4549
|
+
// fallback to original
|
|
4550
|
+
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
4551
|
+
}
|
|
4552
|
+
},
|
|
4541
4553
|
removedfile: function(file) {
|
|
4542
4554
|
const type = window.location.href.split("/").pop();
|
|
4543
4555
|
ajaxPost("/zdropzone-remove",{file:file.name, cname:"dropzone__ZUSER___ID__${MYMODEL.table}__${item}__"+type},(data) => {
|
|
@@ -4547,9 +4559,6 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4547
4559
|
init: function() {
|
|
4548
4560
|
let dz = this;
|
|
4549
4561
|
const type = window.location.href.split("/").pop();
|
|
4550
|
-
dz.on("addedfile", function(file) {
|
|
4551
|
-
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
4552
|
-
});
|
|
4553
4562
|
dz.on("removedfile", function(file) {
|
|
4554
4563
|
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'remove',field:"${item}",table:"${MYMODEL.table}", type:type},() => {});
|
|
4555
4564
|
$("div#${item}").find(".dz-message").remove();
|
|
@@ -6715,4 +6724,4 @@ zRoute.tableBody = (
|
|
|
6715
6724
|
}
|
|
6716
6725
|
return html;
|
|
6717
6726
|
};
|
|
6718
|
-
module.exports = zRoute;
|
|
6727
|
+
module.exports = zRoute;
|