zet-lib 3.1.3 → 3.1.5
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 +42 -5
- package/lib/zRoute.js +54 -2
- package/package.json +4 -2
package/lib/zAppRouter.js
CHANGED
|
@@ -22,8 +22,25 @@ const pm2 = require("pm2");
|
|
|
22
22
|
const zFunction = require("./zFunction");
|
|
23
23
|
const qs = require("qs");
|
|
24
24
|
const zip = require("express-zip");
|
|
25
|
-
const sharp = require("sharp");
|
|
26
25
|
const path = require("path");
|
|
26
|
+
|
|
27
|
+
// Lazy load sharp with error handling for cross-platform compatibility
|
|
28
|
+
let sharp = null;
|
|
29
|
+
function getSharp() {
|
|
30
|
+
if (sharp === null) {
|
|
31
|
+
try {
|
|
32
|
+
sharp = require("sharp");
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.warn("Warning: sharp module is not available. Image processing features will be disabled.");
|
|
35
|
+
console.warn("To enable image processing, install sharp: npm install --include=optional sharp");
|
|
36
|
+
sharp = false; // Mark as unavailable
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (sharp === false) {
|
|
40
|
+
throw new Error("sharp module is not available. Please install it: npm install --include=optional sharp");
|
|
41
|
+
}
|
|
42
|
+
return sharp;
|
|
43
|
+
}
|
|
27
44
|
const { Dropbox } = require("dropbox");
|
|
28
45
|
const fetch = require("isomorphic-fetch");
|
|
29
46
|
const JSZip = require("jszip");
|
|
@@ -1747,6 +1764,15 @@ router.post("/zcompress-dropzone", async (req, res) => {
|
|
|
1747
1764
|
io.to(room).emit("errormessage", message);
|
|
1748
1765
|
res.json(Util.flashError(message));
|
|
1749
1766
|
} else {
|
|
1767
|
+
// Check if sharp is available
|
|
1768
|
+
try {
|
|
1769
|
+
getSharp();
|
|
1770
|
+
} catch (error) {
|
|
1771
|
+
const message = "Image compression is not available. Please install sharp: npm install --include=optional sharp";
|
|
1772
|
+
io.to(room).emit("errormessage", message);
|
|
1773
|
+
return res.json(Util.flashError(message));
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1750
1776
|
const config = {
|
|
1751
1777
|
jpeg: { quality: 60, compressionLevel: 9 },
|
|
1752
1778
|
webp: { quality: 60, compressionLevel: 9 },
|
|
@@ -1782,7 +1808,8 @@ router.post("/zcompress-dropzone", async (req, res) => {
|
|
|
1782
1808
|
await wait(timeExcecute); // Wait for file system
|
|
1783
1809
|
let image;
|
|
1784
1810
|
try {
|
|
1785
|
-
|
|
1811
|
+
const sharpLib = getSharp();
|
|
1812
|
+
image = sharpLib(tempPath).resize({
|
|
1786
1813
|
width: 1024,
|
|
1787
1814
|
height: null, // Maintain aspect ratio
|
|
1788
1815
|
fit: "inside",
|
|
@@ -2146,6 +2173,15 @@ router.post("/zcompress-dropbox", async (req, res) => {
|
|
|
2146
2173
|
io.to(room).emit("errormessage", message);
|
|
2147
2174
|
res.json(Util.flashError(message));
|
|
2148
2175
|
} else {
|
|
2176
|
+
// Check if sharp is available
|
|
2177
|
+
try {
|
|
2178
|
+
getSharp();
|
|
2179
|
+
} catch (error) {
|
|
2180
|
+
const message = "Image compression is not available. Please install sharp: npm install --include=optional sharp";
|
|
2181
|
+
io.to(room).emit("errormessage", message);
|
|
2182
|
+
return res.json(Util.flashError(message));
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2149
2185
|
let arr = [];
|
|
2150
2186
|
let files = result[field];
|
|
2151
2187
|
const count = files.length || 0;
|
|
@@ -2162,7 +2198,8 @@ router.post("/zcompress-dropbox", async (req, res) => {
|
|
|
2162
2198
|
// Get the file name from the path
|
|
2163
2199
|
const fileName = file;
|
|
2164
2200
|
// Process the image with sharp
|
|
2165
|
-
const
|
|
2201
|
+
const sharpLib = getSharp();
|
|
2202
|
+
const processedImage = await sharpLib(response.result.fileBinary)
|
|
2166
2203
|
.resize({
|
|
2167
2204
|
width: 1024,
|
|
2168
2205
|
height: null, // Maintain aspect ratio
|
|
@@ -2173,7 +2210,7 @@ router.post("/zcompress-dropbox", async (req, res) => {
|
|
|
2173
2210
|
.then((buffer) => {
|
|
2174
2211
|
// Check if the file is PNG
|
|
2175
2212
|
if (fileName.toLowerCase().endsWith(".png")) {
|
|
2176
|
-
return
|
|
2213
|
+
return sharpLib(buffer)
|
|
2177
2214
|
.png({
|
|
2178
2215
|
quality: 60,
|
|
2179
2216
|
compressionLevel: 9, // Maximum compression for PNG
|
|
@@ -2181,7 +2218,7 @@ router.post("/zcompress-dropbox", async (req, res) => {
|
|
|
2181
2218
|
.toBuffer();
|
|
2182
2219
|
} else {
|
|
2183
2220
|
// For JPEG files
|
|
2184
|
-
return
|
|
2221
|
+
return sharpLib(buffer)
|
|
2185
2222
|
.jpeg({
|
|
2186
2223
|
quality: 60,
|
|
2187
2224
|
mozjpeg: true, // Better compression
|
package/lib/zRoute.js
CHANGED
|
@@ -4167,6 +4167,8 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4167
4167
|
let hasLocation = false;
|
|
4168
4168
|
let hasDragdrop = false;
|
|
4169
4169
|
let hasDropbox = false;
|
|
4170
|
+
let hasDropdownMulti = false;
|
|
4171
|
+
let hasSelectize = false;
|
|
4170
4172
|
let lexicals = [];
|
|
4171
4173
|
let mapKey = "";
|
|
4172
4174
|
let hasAttributes = [];
|
|
@@ -4182,6 +4184,8 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4182
4184
|
hasDatePicker = true;
|
|
4183
4185
|
} else if (widgets[key].name == "number") {
|
|
4184
4186
|
hasNumber = true;
|
|
4187
|
+
} else if (widgets[key].name == "dropdown_multi") {
|
|
4188
|
+
hasDropdownMulti = true;
|
|
4185
4189
|
} else if (widgets[key].name == "money") {
|
|
4186
4190
|
hasNumber = true;
|
|
4187
4191
|
moneys.push(key);
|
|
@@ -4261,6 +4265,7 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4261
4265
|
//add search on select
|
|
4262
4266
|
if (widgets[key].isSearch) {
|
|
4263
4267
|
selectize.push(key);
|
|
4268
|
+
hasSelectize = true;
|
|
4264
4269
|
}
|
|
4265
4270
|
}
|
|
4266
4271
|
}
|
|
@@ -4363,12 +4368,15 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4363
4368
|
headObj.datetimepicker = datetimepickerObj.head;
|
|
4364
4369
|
endObj.datetimepicker = datetimepickerObj.end;
|
|
4365
4370
|
}
|
|
4371
|
+
if(hasSelectize || hasDropdownMulti) {
|
|
4372
|
+
let selectizeObject = moduleLib.selectize(req, res);
|
|
4373
|
+
headObj.selectize = selectizeObject.head;
|
|
4374
|
+
endObj.selectize = selectizeObject.end;
|
|
4375
|
+
}
|
|
4366
4376
|
if (selectize.length > 0) {
|
|
4367
4377
|
selectize.map((item) => {
|
|
4368
4378
|
let selectizeObj = moduleLib.selectize(req, res, `#${item}`);
|
|
4369
4379
|
scriptForm += selectizeObj.script;
|
|
4370
|
-
headObj.selectize = selectizeObj.head;
|
|
4371
|
-
endObj.selectize = selectizeObj.end;
|
|
4372
4380
|
});
|
|
4373
4381
|
}
|
|
4374
4382
|
if (hasIde) {
|
|
@@ -4643,6 +4651,50 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = "", data = {}) => {
|
|
|
4643
4651
|
break;
|
|
4644
4652
|
|
|
4645
4653
|
case "dropdown_multi":
|
|
4654
|
+
scriptForm += `$(document).ready(function () {
|
|
4655
|
+
var $${keys}Select = $('#${keys}');
|
|
4656
|
+
if ($${keys}Select.length && typeof $.fn.selectize !== 'undefined') {
|
|
4657
|
+
if (!$${keys}Select[0].selectize) {
|
|
4658
|
+
var isMultiple = $${keys}Select.hasClass('dropdown-multi');
|
|
4659
|
+
if (isMultiple && !$${keys}Select.attr('multiple')) {
|
|
4660
|
+
$${keys}Select.attr('multiple', 'multiple');
|
|
4661
|
+
}
|
|
4662
|
+
var selectizeOptions = {
|
|
4663
|
+
plugins: isMultiple ? ['remove_button'] : [],
|
|
4664
|
+
delimiter: ',',
|
|
4665
|
+
persist: false,
|
|
4666
|
+
create: false,
|
|
4667
|
+
search: true,
|
|
4668
|
+
openOnFocus: true,
|
|
4669
|
+
closeAfterSelect: true,
|
|
4670
|
+
maxItems: 1,
|
|
4671
|
+
placeholder: 'Please select ${keys}',
|
|
4672
|
+
onType: function (str) {
|
|
4673
|
+
var results = this.search(str);
|
|
4674
|
+
if (results.length === 1) {
|
|
4675
|
+
var self = this;
|
|
4676
|
+
setTimeout(function () {
|
|
4677
|
+
self.setValue(results[0].value);
|
|
4678
|
+
self.close();
|
|
4679
|
+
}, 100);
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
};
|
|
4683
|
+
$${keys}Select.selectize(selectizeOptions);
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
$(document).on('click', '#dropdownadd${keys}', function () {
|
|
4687
|
+
var $select = $('#${keys}');
|
|
4688
|
+
if ($select.length) {
|
|
4689
|
+
var selectize = $select[0].selectize;
|
|
4690
|
+
if (selectize) {
|
|
4691
|
+
selectize.clear();
|
|
4692
|
+
} else {
|
|
4693
|
+
$select.val('').trigger('change');
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
});
|
|
4697
|
+
});`
|
|
4646
4698
|
scriptForm += ` $("#dropdownadd${keys}").on("click", function () {
|
|
4647
4699
|
var val = $("#${keys}").val();
|
|
4648
4700
|
if(val == ""){
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zet-lib",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"description": "zet is a library that part of zet generator.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -49,12 +49,14 @@
|
|
|
49
49
|
"qs": "^6.14.0",
|
|
50
50
|
"randomstring": "^1.3.1",
|
|
51
51
|
"read-excel-file": "^5.8.0",
|
|
52
|
-
"sharp": "^0.34.1",
|
|
53
52
|
"socket.io": "^4.8.1",
|
|
54
53
|
"uglify-js": "^3.19.3",
|
|
55
54
|
"uuid": "^9.0.1",
|
|
56
55
|
"xlsx": "^0.18.5"
|
|
57
56
|
},
|
|
57
|
+
"optionalDependencies": {
|
|
58
|
+
"sharp": "^0.34.1"
|
|
59
|
+
},
|
|
58
60
|
"overrides": {
|
|
59
61
|
"unzipper": "^0.12.3",
|
|
60
62
|
"rimraf": "^6.1.2",
|