zet-lib 1.5.15 → 1.5.17
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/Mail.js +56 -3
- package/lib/Util.js +1 -1
- package/lib/zAppRouter.js +139 -160
- package/package.json +1 -1
package/lib/Mail.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require("dotenv").config();
|
|
1
2
|
const nodemailer = require('nodemailer')
|
|
2
3
|
const ejs = require('ejs')
|
|
3
4
|
const Util = require('./Util')
|
|
@@ -7,7 +8,7 @@ const moment = require('moment')
|
|
|
7
8
|
const config = require('dotenv').config()
|
|
8
9
|
|
|
9
10
|
if (typeof global.dirRoot === 'undefined') {
|
|
10
|
-
|
|
11
|
+
global.dirRoot = Util.dirRoot;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
const MAIL = {}
|
|
@@ -34,8 +35,8 @@ MAIL.gmailTransporter = (user = '', pass = '') => {
|
|
|
34
35
|
MAIL.send = function (options = {}, transporter = null) {
|
|
35
36
|
let option = Object.assign(mailOptions, options)
|
|
36
37
|
// send mail with defined transport object
|
|
37
|
-
option.user = option.user ||
|
|
38
|
-
option.pass = option.pass ||
|
|
38
|
+
option.user = option.user || process.env.GOOGLE_EMAIL
|
|
39
|
+
option.pass = option.pass || process.env.GOOGLE_PASSWORD
|
|
39
40
|
transporter = transporter || MAIL.gmailTransporter(option.user, option.pass)
|
|
40
41
|
transporter.sendMail(options, function (error, info) {
|
|
41
42
|
if (error) {
|
|
@@ -69,4 +70,56 @@ MAIL.register = (datas = {}, options = {}) => {
|
|
|
69
70
|
})
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
MAIL.approval = (req, res, data, email) => {
|
|
74
|
+
let obj = {
|
|
75
|
+
USERNAME: process.env.GOOGLE_EMAIL,
|
|
76
|
+
PASSWORD: process.env.GOOGLE_PASSWORD,
|
|
77
|
+
TO: "andif@injani.com",
|
|
78
|
+
SUBJECT: "Test gmail Subject widget cms",
|
|
79
|
+
MESSAGE: "Test gmail test message cms",
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var mail = nodemailer.createTransport({
|
|
83
|
+
service: "gmail",
|
|
84
|
+
auth: {
|
|
85
|
+
user: obj.USERNAME,
|
|
86
|
+
pass: obj.PASSWORD,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
ejs.renderFile(
|
|
91
|
+
dirRoot + "/views/layouts/email/approval.ejs",
|
|
92
|
+
{ data: data, Util: Util },
|
|
93
|
+
function (err, html) {
|
|
94
|
+
if (err) {
|
|
95
|
+
console.log(err);
|
|
96
|
+
} else {
|
|
97
|
+
var mailOptions = {
|
|
98
|
+
from: obj.USERNAME,
|
|
99
|
+
to: email,
|
|
100
|
+
subject: data.subject,
|
|
101
|
+
html: html,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
mail.sendMail(mailOptions, function (error, info) {
|
|
105
|
+
if (error) {
|
|
106
|
+
debug(req, res, error);
|
|
107
|
+
io.to(res.locals.token).emit(
|
|
108
|
+
"warning",
|
|
109
|
+
"email not sent to " + email + " : " + error.toString()
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
console.log("Email sent: " + info.response);
|
|
113
|
+
io.to(res.locals.token).emit(
|
|
114
|
+
"message",
|
|
115
|
+
"email sent to " + email + " : " + info.response
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
|
|
72
125
|
module.exports = MAIL
|
package/lib/Util.js
CHANGED
package/lib/zAppRouter.js
CHANGED
|
@@ -74,8 +74,8 @@ router.get("/profile", csrfProtection, access, async (req, res) => {
|
|
|
74
74
|
where: { id: res.locals.companyId },
|
|
75
75
|
});
|
|
76
76
|
let verify_signed = result.verify_signed
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
? "/uploads/zuser/" + result.verify_signed
|
|
78
|
+
: "/img/user.png";
|
|
79
79
|
res.render("layouts/" + layout, {
|
|
80
80
|
menu: { menu: "profile" },
|
|
81
81
|
data: result,
|
|
@@ -144,10 +144,10 @@ router.post("/profile-sign", access, async (req, res) => {
|
|
|
144
144
|
},
|
|
145
145
|
});
|
|
146
146
|
fs.writeFile(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
dirRoot + "/public/uploads/zuser/" + filename,
|
|
148
|
+
base64Image,
|
|
149
|
+
{ encoding: "base64" },
|
|
150
|
+
function (err) {}
|
|
151
151
|
);
|
|
152
152
|
res.json(json);
|
|
153
153
|
});
|
|
@@ -186,7 +186,7 @@ router.post("/login", csrfProtection, async (req, res) => {
|
|
|
186
186
|
|
|
187
187
|
router.post("/login-ajax", csrfProtection, async (req, res) => {
|
|
188
188
|
res.json(
|
|
189
|
-
|
|
189
|
+
await zRoute.loginAjax(req.body.username, req.body.password, req, res)
|
|
190
190
|
);
|
|
191
191
|
});
|
|
192
192
|
|
|
@@ -227,8 +227,8 @@ router.post("/signup", async (req, res) => {
|
|
|
227
227
|
data: dataCompany,
|
|
228
228
|
});
|
|
229
229
|
let dataCache = zCache.myCache.has(body.username)
|
|
230
|
-
|
|
231
|
-
|
|
230
|
+
? zCache.get(body.username)
|
|
231
|
+
: {
|
|
232
232
|
fullname: "",
|
|
233
233
|
email: "",
|
|
234
234
|
image: "",
|
|
@@ -481,7 +481,7 @@ router.post("/forgot", csrfProtection, async (req, res) => {
|
|
|
481
481
|
let data = zRoute.post(req, res, MYMODEL)["zuser"];
|
|
482
482
|
var port = ecosystem.apps[0].env.PORT;
|
|
483
483
|
var url =
|
|
484
|
-
|
|
484
|
+
env == "production" ? process.env.APP_URL : "http://localhost:" + port;
|
|
485
485
|
let email = data.email || " ";
|
|
486
486
|
email = email.trim();
|
|
487
487
|
if (email.length > 5) {
|
|
@@ -524,35 +524,35 @@ router.post("/forgot", csrfProtection, async (req, res) => {
|
|
|
524
524
|
});
|
|
525
525
|
|
|
526
526
|
router.get(
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
527
|
+
"/reset-password/:forgot_password",
|
|
528
|
+
csrfProtection,
|
|
529
|
+
async (req, res) => {
|
|
530
|
+
let forgot_password = req.params.forgot_password || "";
|
|
531
|
+
let activated = false;
|
|
532
|
+
if (forgot_password != "") {
|
|
533
|
+
let results = await connection.results({
|
|
534
|
+
table: "zuser",
|
|
535
|
+
where: {
|
|
536
|
+
forgot_password: forgot_password,
|
|
537
|
+
},
|
|
538
|
+
});
|
|
539
|
+
if (results.length > 0) {
|
|
540
|
+
activated = true;
|
|
541
|
+
}
|
|
541
542
|
}
|
|
542
|
-
|
|
543
|
-
var script = `submitForm('form-group','','',function(data){
|
|
543
|
+
var script = `submitForm('form-group','','',function(data){
|
|
544
544
|
if(data.status==1){
|
|
545
545
|
location.href = '/login'
|
|
546
546
|
}
|
|
547
547
|
});`;
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
548
|
+
await moduleLib.custom(req, res, script);
|
|
549
|
+
res.render("layouts/fronts", {
|
|
550
|
+
activated: activated,
|
|
551
|
+
csrfToken: req.csrfToken(),
|
|
552
|
+
forgot_password: forgot_password,
|
|
553
|
+
renderBody: "index/reset-password.ejs",
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
556
|
);
|
|
557
557
|
|
|
558
558
|
router.get("/no-access", async (req, res) => {
|
|
@@ -643,8 +643,8 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
643
643
|
let MYMODEL = MYMODELS["zapprovals"];
|
|
644
644
|
const port = ecosystem.apps[0].env.PORT;
|
|
645
645
|
let users = Util.arrayToObject(
|
|
646
|
-
|
|
647
|
-
|
|
646
|
+
await connection.results({ table: "zuser" }),
|
|
647
|
+
"id"
|
|
648
648
|
);
|
|
649
649
|
try {
|
|
650
650
|
let userId = res.locals.userId;
|
|
@@ -755,16 +755,16 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
755
755
|
};
|
|
756
756
|
await zRoute.insertSQL(req, res, "zapprovals_details", post);
|
|
757
757
|
let link =
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
758
|
+
env == "production"
|
|
759
|
+
? process.env.APP_URL + "/za/" + post.token
|
|
760
|
+
: `http://localhost:${port}/za/${post.token}`;
|
|
761
761
|
let email = users[post.user_id].email;
|
|
762
762
|
|
|
763
763
|
post.subject = `Need Approve ${data.title}`;
|
|
764
764
|
post.buttonTitle = `Approve Now`;
|
|
765
765
|
post.title = `NEED APPROVE DOCUMENT`;
|
|
766
766
|
post.link = link;
|
|
767
|
-
post.url =
|
|
767
|
+
post.url = process.env.APP_URL;
|
|
768
768
|
post.description = `Hai ${users[post.user_id].fullname} <br>
|
|
769
769
|
|
|
770
770
|
|
|
@@ -772,18 +772,8 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
772
772
|
Please click the link above to view the document.`;
|
|
773
773
|
|
|
774
774
|
post.note = `If you click the link, it's will be automatically acknowledged`;
|
|
775
|
-
Mail.
|
|
776
|
-
|
|
777
|
-
//send to whatsapp
|
|
778
|
-
let phone = Util.phoneWA(users[post.user_id].phone);
|
|
779
|
-
if (phone) {
|
|
780
|
-
var textWa = "";
|
|
781
|
-
textWa += `*NEED APPROVE DOCUMENT* \r\n_${data.title}_\r\nHai ${
|
|
782
|
-
users[post.user_id].fullname
|
|
783
|
-
} \r\n \r\n`;
|
|
784
|
-
textWa += "We have some document for you.\r\n";
|
|
785
|
-
textWa += `Please click the link above to view the document.\r\n${link}`;
|
|
786
|
-
}
|
|
775
|
+
Mail.approval(req, res, post, email);
|
|
776
|
+
|
|
787
777
|
//send notification
|
|
788
778
|
//send toastr using socket.io
|
|
789
779
|
io.to(users[item].token).emit("message", "Need Approve " + data.title);
|
|
@@ -799,9 +789,9 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
799
789
|
};
|
|
800
790
|
await zRoute.insertSQL(req, res, "zapprovals_details", post);
|
|
801
791
|
let link =
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
792
|
+
env == "production"
|
|
793
|
+
? process.env.APP_URL + "/za/" + post.token
|
|
794
|
+
: `http://localhost:${port}/za/${post.token}`;
|
|
805
795
|
let email = users[post.user_id].email;
|
|
806
796
|
|
|
807
797
|
post.subject = `Need acknowledge ${data.title}`;
|
|
@@ -809,7 +799,7 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
809
799
|
post.title = `NEED ACKNOWLEDGE DOCUMENT`;
|
|
810
800
|
|
|
811
801
|
post.link = link;
|
|
812
|
-
post.url =
|
|
802
|
+
post.url = process.env.APP_URL;
|
|
813
803
|
post.description = `Hai ${users[post.user_id].fullname} <br>
|
|
814
804
|
|
|
815
805
|
|
|
@@ -817,21 +807,11 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
817
807
|
Please click the link above to view the document.`;
|
|
818
808
|
|
|
819
809
|
post.note = `If you click the link, it's will be automatically acknowledged`;
|
|
820
|
-
Mail.
|
|
821
|
-
|
|
822
|
-
//send to whatsapp
|
|
823
|
-
let phone = Util.phoneWA(users[post.user_id].phone);
|
|
824
|
-
if (phone) {
|
|
825
|
-
var textWa = "";
|
|
826
|
-
textWa += `*NEED ACKNOWLEDGE DOCUMENT* \r\n_${data.title}_\r\nHai ${
|
|
827
|
-
users[post.user_id].fullname
|
|
828
|
-
} \r\n \r\n`;
|
|
829
|
-
textWa += "We have some document for you.\r\n";
|
|
830
|
-
textWa += `Please click the link above to view the document.\r\n${link}`;
|
|
831
|
-
}
|
|
810
|
+
Mail.approval(req, res, post, email);
|
|
811
|
+
|
|
832
812
|
io.to(users[item].token).emit(
|
|
833
|
-
|
|
834
|
-
|
|
813
|
+
"message",
|
|
814
|
+
"Need Acknowledge " + data.title
|
|
835
815
|
);
|
|
836
816
|
});
|
|
837
817
|
}
|
|
@@ -849,30 +829,30 @@ router.post("/zzapproval", async (req, res) => {
|
|
|
849
829
|
router.get("/za/:token", csrfProtection, async (req, res) => {
|
|
850
830
|
let token = req.params.token;
|
|
851
831
|
let data = {},
|
|
852
|
-
|
|
832
|
+
data2 = {};
|
|
853
833
|
let template = "";
|
|
854
834
|
let result;
|
|
855
835
|
let isClosed = false;
|
|
856
836
|
let footers = "";
|
|
857
837
|
let details = [];
|
|
858
|
-
|
|
859
|
-
|
|
838
|
+
var port = ecosystem.apps[0].env.PORT;
|
|
839
|
+
let routeName = env == "production" ? process.env.APP_URL : `http://localhost:${port}`;
|
|
860
840
|
let statusLabel = "";
|
|
861
841
|
let knowings = [];
|
|
862
842
|
const MYMODELS = myCache.get("MYMODELS");
|
|
863
843
|
let MYMODEL = MYMODELS["zapprovals"];
|
|
864
844
|
let users = Util.arrayToObject(
|
|
865
|
-
|
|
866
|
-
|
|
845
|
+
await connection.results({ table: "zuser" }),
|
|
846
|
+
"id"
|
|
867
847
|
);
|
|
868
848
|
try {
|
|
869
849
|
result = await connection.result({
|
|
870
850
|
select:
|
|
871
|
-
|
|
851
|
+
"*, zapprovals.id as ide, zapprovals_details.token as usertoken, zapprovals.status as statuse, zapprovals_details.status as mystatus, zapprovals_details.type as user_type, zapprovals_details.updated_at, zuser.token as usertoken",
|
|
872
852
|
table: "zapprovals_details",
|
|
873
853
|
joins: [
|
|
874
854
|
"LEFT JOIN zapprovals ON (zapprovals_details.title_id = zapprovals.id)",
|
|
875
|
-
"LEFT JOIN
|
|
855
|
+
"LEFT JOIN zuser ON (zapprovals_details.user_id = zuser.id)",
|
|
876
856
|
],
|
|
877
857
|
where: { "zapprovals_details.token": token },
|
|
878
858
|
});
|
|
@@ -882,10 +862,10 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
|
|
|
882
862
|
statusLabel = MYMODEL.widgets.status.fields[result.statuse];
|
|
883
863
|
routeName = routeName + "/" + result.table + "/view/" + result.id_data;
|
|
884
864
|
if (
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
865
|
+
result.statuse == 3 ||
|
|
866
|
+
result.statuse == 4 ||
|
|
867
|
+
result.mystatus == 3 ||
|
|
868
|
+
result.mystatus == 4
|
|
889
869
|
) {
|
|
890
870
|
isClosed = true;
|
|
891
871
|
}
|
|
@@ -938,9 +918,9 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
|
|
|
938
918
|
});
|
|
939
919
|
//var users = await zRoute.getUsers();
|
|
940
920
|
var message =
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
921
|
+
users[result.user_id].fullname +
|
|
922
|
+
" has readed document " +
|
|
923
|
+
result.title;
|
|
944
924
|
details.forEach(function (item) {
|
|
945
925
|
io.to(users[item.user_id].token).emit("message", message);
|
|
946
926
|
});
|
|
@@ -957,7 +937,6 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
|
|
|
957
937
|
for (var key in data) {
|
|
958
938
|
template = Util.replaceAll(template, "{{" + key + "}}", data[key]);
|
|
959
939
|
}
|
|
960
|
-
|
|
961
940
|
footers = await zRoute.approversFooter(details);
|
|
962
941
|
|
|
963
942
|
//send activity
|
|
@@ -1000,13 +979,13 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1000
979
|
let status = req.body.status;
|
|
1001
980
|
let json = Util.jsonSuccess("Success");
|
|
1002
981
|
let data = {},
|
|
1003
|
-
|
|
982
|
+
data2 = {};
|
|
1004
983
|
let template = "";
|
|
1005
984
|
let approvers = [],
|
|
1006
|
-
|
|
985
|
+
knowings = [];
|
|
1007
986
|
let users = Util.arrayToObject(
|
|
1008
|
-
|
|
1009
|
-
|
|
987
|
+
await connection.results({ table: "zuser" }),
|
|
988
|
+
"id"
|
|
1010
989
|
);
|
|
1011
990
|
let employee_user = users;
|
|
1012
991
|
const MYMODELS = myCache.get("MYMODELS");
|
|
@@ -1015,7 +994,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1015
994
|
try {
|
|
1016
995
|
var results = await connection.results({
|
|
1017
996
|
select:
|
|
1018
|
-
|
|
997
|
+
"*,zapprovals_details.status as approvers_status, zapprovals.created_by as submiter, zapprovals.type as typee, zapprovals.status as statuse, zapprovals_details.id as detaild_id, zapprovals.id as ide, zapprovals.approvers as approvers ",
|
|
1019
998
|
table: "zapprovals_details",
|
|
1020
999
|
joins: [
|
|
1021
1000
|
"LEFT JOIN zapprovals ON (zapprovals_details.title_id = zapprovals.id)",
|
|
@@ -1083,24 +1062,24 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1083
1062
|
where: { id: result.ide },
|
|
1084
1063
|
});
|
|
1085
1064
|
|
|
1086
|
-
//send activity
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1065
|
+
/* //send activity
|
|
1066
|
+
await connection.insert({
|
|
1067
|
+
table: "zactivity",
|
|
1068
|
+
data: {
|
|
1069
|
+
company_id: result.company_id,
|
|
1070
|
+
created_at: Util.now(),
|
|
1071
|
+
created_by: result.user_id,
|
|
1072
|
+
updated_by: result.user_id,
|
|
1073
|
+
user_id: result.user_id,
|
|
1074
|
+
table: MYMODEL.table,
|
|
1075
|
+
id_data: result.ide,
|
|
1076
|
+
status: status,
|
|
1077
|
+
status_label: MYMODEL.widgets.status.fields[status],
|
|
1078
|
+
title: MYMODEL.widgets.status.fields[status],
|
|
1079
|
+
description: comments,
|
|
1080
|
+
data: JSON.stringify(post),
|
|
1081
|
+
},
|
|
1082
|
+
});*/
|
|
1104
1083
|
|
|
1105
1084
|
//send notification
|
|
1106
1085
|
if (status == 3 || status == 4) {
|
|
@@ -1162,7 +1141,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1162
1141
|
{
|
|
1163
1142
|
title: users[item].fullname + " " + users[item].position,
|
|
1164
1143
|
description:
|
|
1165
|
-
|
|
1144
|
+
"@" + users[item].fullname + " " + users[item].position,
|
|
1166
1145
|
rowId: "roe" + index,
|
|
1167
1146
|
},
|
|
1168
1147
|
];
|
|
@@ -1173,7 +1152,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1173
1152
|
{
|
|
1174
1153
|
title: users[item].fullname + " " + users[item].position,
|
|
1175
1154
|
description:
|
|
1176
|
-
|
|
1155
|
+
"@" + users[item].fullname + " " + users[item].position,
|
|
1177
1156
|
rowId: "roe" + index,
|
|
1178
1157
|
},
|
|
1179
1158
|
];
|
|
@@ -1204,7 +1183,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1204
1183
|
});
|
|
1205
1184
|
|
|
1206
1185
|
//send todolist
|
|
1207
|
-
await connection.insert({
|
|
1186
|
+
/*await connection.insert({
|
|
1208
1187
|
table: "ztodolist",
|
|
1209
1188
|
data: {
|
|
1210
1189
|
company_id: result.company_id,
|
|
@@ -1221,12 +1200,12 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
|
|
|
1221
1200
|
description: result.title,
|
|
1222
1201
|
users: JSON.stringify(approvers),
|
|
1223
1202
|
},
|
|
1224
|
-
})
|
|
1203
|
+
});*/
|
|
1225
1204
|
|
|
1226
1205
|
//send toastr using socket.io
|
|
1227
1206
|
io.to(users[item].token).emit(
|
|
1228
|
-
|
|
1229
|
-
|
|
1207
|
+
"message",
|
|
1208
|
+
"Need Approve for document : " + result.title
|
|
1230
1209
|
);
|
|
1231
1210
|
}
|
|
1232
1211
|
}
|
|
@@ -1595,21 +1574,21 @@ router.post("/zhistory-data", async (req, res) => {
|
|
|
1595
1574
|
users = myCache.get("users");
|
|
1596
1575
|
} else {
|
|
1597
1576
|
users = Util.arrayToObject(
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1577
|
+
await connection.results({
|
|
1578
|
+
table: "zuser",
|
|
1579
|
+
}),
|
|
1580
|
+
"id"
|
|
1602
1581
|
);
|
|
1603
1582
|
myCache.set("users", users);
|
|
1604
1583
|
}
|
|
1605
1584
|
html = await zRoute.history(
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1585
|
+
req,
|
|
1586
|
+
res,
|
|
1587
|
+
relations,
|
|
1588
|
+
id,
|
|
1589
|
+
MYMODEL,
|
|
1590
|
+
users,
|
|
1591
|
+
results
|
|
1613
1592
|
);
|
|
1614
1593
|
}
|
|
1615
1594
|
res.json(html);
|
|
@@ -1680,10 +1659,10 @@ router.post("/zcompress-dropzone", async (req, res) => {
|
|
|
1680
1659
|
console.log(dir);
|
|
1681
1660
|
const timestamp = Date.now();
|
|
1682
1661
|
const tempDir = path.join(
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1662
|
+
dirRoot,
|
|
1663
|
+
"public",
|
|
1664
|
+
"temps",
|
|
1665
|
+
`${table}___${field}___${id}___${userId}___${timestamp}`
|
|
1687
1666
|
);
|
|
1688
1667
|
if (!fs.existsSync(tempDir)) {
|
|
1689
1668
|
fs.mkdirSync(tempDir);
|
|
@@ -1713,8 +1692,8 @@ router.post("/zcompress-dropzone", async (req, res) => {
|
|
|
1713
1692
|
} catch (error) {
|
|
1714
1693
|
console.log(`Skipping ${filename} - not a valid image file`);
|
|
1715
1694
|
io.to(room).emit(
|
|
1716
|
-
|
|
1717
|
-
|
|
1695
|
+
"errormessage",
|
|
1696
|
+
`Skipping ${filename} - not a valid image file`
|
|
1718
1697
|
);
|
|
1719
1698
|
continue;
|
|
1720
1699
|
}
|
|
@@ -1724,7 +1703,7 @@ router.post("/zcompress-dropzone", async (req, res) => {
|
|
|
1724
1703
|
try {
|
|
1725
1704
|
// Compress the image to a buffer
|
|
1726
1705
|
const compressedBuffer = await image[format](
|
|
1727
|
-
|
|
1706
|
+
config[format]
|
|
1728
1707
|
).toBuffer();
|
|
1729
1708
|
await wait(timeExcecute); // Wait for file system
|
|
1730
1709
|
// Write the compressed buffer to the original file
|
|
@@ -1883,8 +1862,8 @@ router.post("/zdropbox-file/:index", async (req, res) => {
|
|
|
1883
1862
|
res.json(jsonMessage.datas);
|
|
1884
1863
|
} else {
|
|
1885
1864
|
io.to(room).emit(
|
|
1886
|
-
|
|
1887
|
-
|
|
1865
|
+
"errormessage",
|
|
1866
|
+
`Please reload your browser !! Error ${pathFile} not exist in dropbox, `
|
|
1888
1867
|
);
|
|
1889
1868
|
res.json(datas);
|
|
1890
1869
|
}
|
|
@@ -2085,32 +2064,32 @@ router.post("/zcompress-dropbox", async (req, res) => {
|
|
|
2085
2064
|
const fileName = file;
|
|
2086
2065
|
// Process the image with sharp
|
|
2087
2066
|
const processedImage = await sharp(response.result.fileBinary)
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2067
|
+
.resize({
|
|
2068
|
+
width: 1024,
|
|
2069
|
+
height: null, // Maintain aspect ratio
|
|
2070
|
+
fit: "inside",
|
|
2071
|
+
withoutEnlargement: true, // Don't enlarge if image is smaller than 1024px
|
|
2072
|
+
})
|
|
2073
|
+
.toBuffer()
|
|
2074
|
+
.then((buffer) => {
|
|
2075
|
+
// Check if the file is PNG
|
|
2076
|
+
if (fileName.toLowerCase().endsWith(".png")) {
|
|
2077
|
+
return sharp(buffer)
|
|
2078
|
+
.png({
|
|
2079
|
+
quality: 60,
|
|
2080
|
+
compressionLevel: 9, // Maximum compression for PNG
|
|
2081
|
+
})
|
|
2082
|
+
.toBuffer();
|
|
2083
|
+
} else {
|
|
2084
|
+
// For JPEG files
|
|
2085
|
+
return sharp(buffer)
|
|
2086
|
+
.jpeg({
|
|
2087
|
+
quality: 60,
|
|
2088
|
+
mozjpeg: true, // Better compression
|
|
2089
|
+
})
|
|
2090
|
+
.toBuffer();
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2114
2093
|
|
|
2115
2094
|
// Upload the compressed image back to Dropbox
|
|
2116
2095
|
await dbx.filesUpload({
|