zet-lib 5.0.2 → 6.0.0
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/views/generatorjs.ejs +0 -12
- package/lib/zAppRouter.js +25 -15
- package/lib/zGeneratorRouter.js +3 -83
- package/lib/zPage.js +1 -9
- package/lib/zRoute.js +14 -7
- package/package.json +4 -6
|
@@ -516,18 +516,6 @@
|
|
|
516
516
|
}
|
|
517
517
|
})
|
|
518
518
|
|
|
519
|
-
$('.btn-minify').on('click', function () {
|
|
520
|
-
if (window.confirm('Minify all views in one line make your website faster ?')) {
|
|
521
|
-
ajaxPost('/<%- routeName%>/minify', {}, function (data) {
|
|
522
|
-
if (data.status == 0) {
|
|
523
|
-
toastr.error(data.message, data.title)
|
|
524
|
-
} else {
|
|
525
|
-
toastr.success(data.title, data.message)
|
|
526
|
-
}
|
|
527
|
-
})
|
|
528
|
-
}
|
|
529
|
-
})
|
|
530
|
-
|
|
531
519
|
$('.btn-generate-assets').on('click', function () {
|
|
532
520
|
if (window.confirm('Replace javascript assets with this one ?')) {
|
|
533
521
|
ajaxPost('/<%- routeName%>/generate-assets', {}, function (data) {
|
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/zGeneratorRouter.js
CHANGED
|
@@ -5,8 +5,6 @@ const csrfProtection = csrf({ cookie: true });
|
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
6
|
const axios = require("axios");
|
|
7
7
|
const getPm2 = require("./optionalPm2");
|
|
8
|
-
const uglifyJS = require("uglify-js");
|
|
9
|
-
const { minify } = require("html-minifier-terser");
|
|
10
8
|
const zRoute = require("./zRoute");
|
|
11
9
|
const connection = require("./connection");
|
|
12
10
|
const Util = require("./Util");
|
|
@@ -614,22 +612,10 @@ const generate = async (req, res) => {
|
|
|
614
612
|
if (!fs.existsSync(DIR_VIEW)) {
|
|
615
613
|
fs.mkdirSync(DIR_VIEW);
|
|
616
614
|
}
|
|
617
|
-
let compilesJS = ["createjs.ejs", "updatejs.ejs", "importjs.ejs"];
|
|
618
615
|
if (!dummy) {
|
|
619
616
|
for (const q in filesKey) {
|
|
620
617
|
console.log(q);
|
|
621
|
-
|
|
622
|
-
fs.writeFileSync(path.join(DIR_VIEW, q), filesKey[q]);
|
|
623
|
-
} else {
|
|
624
|
-
fs.writeFileSync(
|
|
625
|
-
path.join(DIR_VIEW, q),
|
|
626
|
-
await minify(filesKey[q], {
|
|
627
|
-
minifyJS: true,
|
|
628
|
-
minifyCSS: true,
|
|
629
|
-
collapseWhitespace: true,
|
|
630
|
-
})
|
|
631
|
-
);
|
|
632
|
-
}
|
|
618
|
+
fs.writeFileSync(path.join(DIR_VIEW, q), filesKey[q]);
|
|
633
619
|
console.log(`The files views of ${q} is saved!`);
|
|
634
620
|
}
|
|
635
621
|
}
|
|
@@ -657,17 +643,11 @@ const generate = async (req, res) => {
|
|
|
657
643
|
let relations = await zRoute.relations(req, res, MYMODEL.table);
|
|
658
644
|
//add script
|
|
659
645
|
let jsObj = zRoute.generateJS(req, res, MYMODEL, relations);
|
|
660
|
-
//minify script
|
|
661
|
-
let script = uglifyJS.minify(jsObj.script);
|
|
662
|
-
if (script.error) {
|
|
663
|
-
console.log(jsObj.script);
|
|
664
|
-
throw script.error;
|
|
665
|
-
}
|
|
666
646
|
let time = new Date().getTime();
|
|
667
647
|
Util.deleteAllFiles(path_script);
|
|
668
648
|
Util.deleteAllFiles(path_head);
|
|
669
649
|
Util.deleteAllFiles(path_end);
|
|
670
|
-
Util.writeFile(path.join(path_script, `${time}.js`), script
|
|
650
|
+
Util.writeFile(path.join(path_script, `${time}.js`), jsObj.script);
|
|
671
651
|
Util.writeFile(path.join(path_head, "head.txt"), jsObj.head);
|
|
672
652
|
Util.writeFile(path.join(path_end, "end.txt"), jsObj.end);
|
|
673
653
|
}
|
|
@@ -1589,10 +1569,7 @@ router.post("/generate-assets", async (req, res) => {
|
|
|
1589
1569
|
Util.deleteAllFiles(path_end);
|
|
1590
1570
|
Util.deleteAllFiles(path_script);
|
|
1591
1571
|
|
|
1592
|
-
|
|
1593
|
-
let script = uglifyJS.minify(jsObj.script);
|
|
1594
|
-
if (script.error) throw script.error;
|
|
1595
|
-
Util.writeFile(path.join(path_script, `${time}.js`), script.code);
|
|
1572
|
+
Util.writeFile(path.join(path_script, `${time}.js`), jsObj.script);
|
|
1596
1573
|
Util.writeFile(path.join(path_head, "head.txt"), jsObj.head);
|
|
1597
1574
|
Util.writeFile(path.join(path_end, "end.txt"), jsObj.end);
|
|
1598
1575
|
}
|
|
@@ -1602,63 +1579,6 @@ router.post("/generate-assets", async (req, res) => {
|
|
|
1602
1579
|
res.json(notifObj);
|
|
1603
1580
|
});
|
|
1604
1581
|
|
|
1605
|
-
router.post("/minify", async (req, res) => {
|
|
1606
|
-
let notifyObj = Util.jsonSuccess("Success to cached");
|
|
1607
|
-
try {
|
|
1608
|
-
notifyObj = await viewsMini();
|
|
1609
|
-
} catch (e) {
|
|
1610
|
-
console.log(e);
|
|
1611
|
-
notifyObj = Util.flashError(e.toString());
|
|
1612
|
-
}
|
|
1613
|
-
res.json(notifyObj);
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
const viewsMini = async () => {
|
|
1617
|
-
let notifyObj = Util.jsonSuccess("Success");
|
|
1618
|
-
const viewDir = path.join(dirRoot, "views");
|
|
1619
|
-
const layoutsDir = path.join(dirRoot, "views", "layouts");
|
|
1620
|
-
let item;
|
|
1621
|
-
try {
|
|
1622
|
-
let views = Util.getAllFiles(viewDir);
|
|
1623
|
-
let options = {
|
|
1624
|
-
minifyJS: true,
|
|
1625
|
-
minifyCSS: true,
|
|
1626
|
-
collapseWhitespace: true,
|
|
1627
|
-
};
|
|
1628
|
-
const notViewDir = ["zgenerator", "layouts", "index", "zindex"];
|
|
1629
|
-
for (const dir of views) {
|
|
1630
|
-
console.log("dir :", dir);
|
|
1631
|
-
if (!Util.in_array(dir, notViewDir)) {
|
|
1632
|
-
let files = Util.getAllFiles(path.join(viewDir, dir));
|
|
1633
|
-
//console.log(files);
|
|
1634
|
-
for (item of files) {
|
|
1635
|
-
if (item.includes(".ejs")) {
|
|
1636
|
-
let filename = path.join(viewDir, dir, item);
|
|
1637
|
-
let content = Util.readFile(filename);
|
|
1638
|
-
let contentChange = await minify(content, options);
|
|
1639
|
-
fs.writeFileSync(filename, contentChange);
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
let layouts = Util.getAllFiles(layoutsDir);
|
|
1646
|
-
for (item of layouts) {
|
|
1647
|
-
if (item.includes(".ejs")) {
|
|
1648
|
-
let filename = path.join(layoutsDir, item);
|
|
1649
|
-
let content = Util.readFile(filename);
|
|
1650
|
-
let contentChange = await minify(content, options);
|
|
1651
|
-
fs.writeFileSync(filename, contentChange);
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
} catch (e) {
|
|
1655
|
-
notifyObj = Util.flashError(
|
|
1656
|
-
`error in item : ${item} , error str :${e.toString()}`
|
|
1657
|
-
);
|
|
1658
|
-
}
|
|
1659
|
-
return notifyObj;
|
|
1660
|
-
};
|
|
1661
|
-
|
|
1662
1582
|
router.post("/load-joins", async (req, res) => {
|
|
1663
1583
|
let jsonNotif = Util.jsonSuccess("Success");
|
|
1664
1584
|
let html = "";
|
package/lib/zPage.js
CHANGED
|
@@ -8,7 +8,6 @@ const nodemailer = require('nodemailer');
|
|
|
8
8
|
const qs = require('qs');
|
|
9
9
|
const moment = require('moment');
|
|
10
10
|
const getPm2 = require('./optionalPm2');
|
|
11
|
-
const { minify } = require('html-minifier-terser');
|
|
12
11
|
const connection = require('./connection');
|
|
13
12
|
const Util = require('./Util');
|
|
14
13
|
const myCache = require('./cache');
|
|
@@ -159,14 +158,7 @@ zpage.createRoute = (obj, token, layoutObj) => {
|
|
|
159
158
|
zpage.buildLayout = async (obj) => {
|
|
160
159
|
let name = Util.toName(obj.name);
|
|
161
160
|
if (obj.active) {
|
|
162
|
-
|
|
163
|
-
removeComments:true,
|
|
164
|
-
minifyJS:true,
|
|
165
|
-
minifyCSS:true,
|
|
166
|
-
collapseWhitespace: true
|
|
167
|
-
});
|
|
168
|
-
console.log(path.join(dirRoot, "views", "layouts", name + ".ejs"));
|
|
169
|
-
fs.writeFileSync(path.join(dirRoot, "views", "layouts", name + ".ejs"), html, 'utf-8');
|
|
161
|
+
fs.writeFileSync(path.join(dirRoot, "views", "layouts", name + ".ejs"), obj.code, 'utf-8');
|
|
170
162
|
if (process.env.NODE_ENV === "production") {
|
|
171
163
|
setTimeout(function () {
|
|
172
164
|
const pm2 = getPm2()
|
package/lib/zRoute.js
CHANGED
|
@@ -8,7 +8,6 @@ const qs = require("qs");
|
|
|
8
8
|
//for generate PDF
|
|
9
9
|
const puppeteer = require("puppeteer");
|
|
10
10
|
const ejs = require("ejs");
|
|
11
|
-
const uglifyJS = require("uglify-js");
|
|
12
11
|
const Excel = require("exceljsremake");
|
|
13
12
|
const fs = require("fs-extra");
|
|
14
13
|
const Util = require("./Util");
|
|
@@ -4123,8 +4122,7 @@ zRoute.moduleLib = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4123
4122
|
let time = new Date().getTime();
|
|
4124
4123
|
Util.deleteAllFiles(path_head);
|
|
4125
4124
|
Util.deleteAllFiles(path_end);
|
|
4126
|
-
|
|
4127
|
-
Util.writeFile(path.join(path_script, `${time}.js`), uglifyJS.minify(jsObj.script));
|
|
4125
|
+
Util.writeFile(path.join(path_script, `${time}.js`), jsObj.script);
|
|
4128
4126
|
Util.writeFile(path.join(path_head, "head.txt"), jsObj.head);
|
|
4129
4127
|
Util.writeFile(path.join(path_end, "end.txt"), jsObj.end);
|
|
4130
4128
|
end += `<script src="/runtime/script/${table}/${time}.js"></script>`;
|
|
@@ -4538,6 +4536,18 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4538
4536
|
addRemoveLinks: !0,
|
|
4539
4537
|
maxFilesize: 30,
|
|
4540
4538
|
headers: {"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")},
|
|
4539
|
+
success: function(file, response) {
|
|
4540
|
+
const type = window.location.href.split("/").pop();
|
|
4541
|
+
if(response && response.fileName) {
|
|
4542
|
+
// Persist server-side unique name on the file object so remove uses it too
|
|
4543
|
+
file.name = response.fileName;
|
|
4544
|
+
if(file.upload) file.upload.filename = response.fileName;
|
|
4545
|
+
ajaxPost("/zdropzone-attributes",{file:response.fileName,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
4546
|
+
} else {
|
|
4547
|
+
// fallback to original
|
|
4548
|
+
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'add',field:"${item}",table:"${MYMODEL.table}", type:type},() => {})
|
|
4549
|
+
}
|
|
4550
|
+
},
|
|
4541
4551
|
removedfile: function(file) {
|
|
4542
4552
|
const type = window.location.href.split("/").pop();
|
|
4543
4553
|
ajaxPost("/zdropzone-remove",{file:file.name, cname:"dropzone__ZUSER___ID__${MYMODEL.table}__${item}__"+type},(data) => {
|
|
@@ -4547,9 +4557,6 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4547
4557
|
init: function() {
|
|
4548
4558
|
let dz = this;
|
|
4549
4559
|
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
4560
|
dz.on("removedfile", function(file) {
|
|
4554
4561
|
ajaxPost("/zdropzone-attributes",{file:file.name,'category':'remove',field:"${item}",table:"${MYMODEL.table}", type:type},() => {});
|
|
4555
4562
|
$("div#${item}").find(".dz-message").remove();
|
|
@@ -6715,4 +6722,4 @@ zRoute.tableBody = (
|
|
|
6715
6722
|
}
|
|
6716
6723
|
return html;
|
|
6717
6724
|
};
|
|
6718
|
-
module.exports = zRoute;
|
|
6725
|
+
module.exports = zRoute;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zet-lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "zet is a library that part of zet generator.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -32,10 +32,9 @@
|
|
|
32
32
|
"dotenv": "^16.5.0",
|
|
33
33
|
"dropbox": "^10.34.0",
|
|
34
34
|
"ejs": "^3.1.10",
|
|
35
|
-
"exceljsremake": "^0.1.
|
|
35
|
+
"exceljsremake": "^0.1.4",
|
|
36
36
|
"express-zip": "^3.0.0",
|
|
37
37
|
"fs-extra": "^11.3.4",
|
|
38
|
-
"html-minifier-terser": "^7.2.0",
|
|
39
38
|
"isomorphic-fetch": "^3.0.0",
|
|
40
39
|
"js-sha256": "^0.11.1",
|
|
41
40
|
"jszip": "^3.10.1",
|
|
@@ -43,12 +42,11 @@
|
|
|
43
42
|
"node-cache": "^5.1.2",
|
|
44
43
|
"nodemailer": "^8.0.5",
|
|
45
44
|
"pg": "^8.16.3",
|
|
46
|
-
"puppeteer": "^
|
|
45
|
+
"puppeteer": "^25.1.0",
|
|
47
46
|
"qs": "^6.14.0",
|
|
48
47
|
"randomstring": "^1.3.1",
|
|
49
48
|
"read-excel-file": "^5.8.0",
|
|
50
|
-
"socket.io": "^4.8.3"
|
|
51
|
-
"uglify-js": "^3.19.3"
|
|
49
|
+
"socket.io": "^4.8.3"
|
|
52
50
|
},
|
|
53
51
|
"optionalDependencies": {
|
|
54
52
|
"sharp": "^0.34.1"
|