zet-lib 1.5.16 → 1.5.18

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 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
- global.dirRoot = Util.dirRoot;
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 || 'aptiwise@gmail.com'
38
- option.pass = option.pass || 'affi ftqv ceal zzwe'
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/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
- ? "/uploads/zuser/" + result.verify_signed
78
- : "/img/user.png";
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
- dirRoot + "/public/uploads/zuser/" + filename,
148
- base64Image,
149
- { encoding: "base64" },
150
- function (err) {}
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
- await zRoute.loginAjax(req.body.username, req.body.password, req, res)
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
- ? zCache.get(body.username)
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
- env == "production" ? process.env.APP_URL : "http://localhost:" + port;
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
- "/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;
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
- 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
- }
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
- await connection.results({ table: "zuser" }),
647
- "id"
646
+ await connection.results({ table: "zuser" }),
647
+ "id"
648
648
  );
649
649
  try {
650
650
  let userId = res.locals.userId;
@@ -755,16 +755,17 @@ router.post("/zzapproval", async (req, res) => {
755
755
  };
756
756
  await zRoute.insertSQL(req, res, "zapprovals_details", post);
757
757
  let link =
758
- env == "production"
759
- ? process.env.APP_URL + "/za/" + post.token
760
- : `http://localhost:${port}/za/${post.token}`;
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
- post.title = `NEED APPROVE DOCUMENT`;
765
+ post.caption = `NEED APPROVE DOCUMENT`;
766
+ post.title = data.title;
766
767
  post.link = link;
767
- post.url = CONFIG.app.url;
768
+ post.url = process.env.APP_URL;
768
769
  post.description = `Hai ${users[post.user_id].fullname} <br>
769
770
 
770
771
 
@@ -772,18 +773,8 @@ router.post("/zzapproval", async (req, res) => {
772
773
  Please click the link above to view the document.`;
773
774
 
774
775
  post.note = `If you click the link, it's will be automatically acknowledged`;
775
- Mail.gmail(req, res, post, email);
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
- }
776
+ Mail.approval(req, res, post, email);
777
+
787
778
  //send notification
788
779
  //send toastr using socket.io
789
780
  io.to(users[item].token).emit("message", "Need Approve " + data.title);
@@ -799,17 +790,18 @@ router.post("/zzapproval", async (req, res) => {
799
790
  };
800
791
  await zRoute.insertSQL(req, res, "zapprovals_details", post);
801
792
  let link =
802
- env == "production"
803
- ? process.env.APP_URL + "/za/" + post.token
804
- : `http://localhost:${port}/za/${post.token}`;
793
+ env == "production"
794
+ ? process.env.APP_URL + "/za/" + post.token
795
+ : `http://localhost:${port}/za/${post.token}`;
805
796
  let email = users[post.user_id].email;
806
797
 
807
798
  post.subject = `Need acknowledge ${data.title}`;
808
799
  post.buttonTitle = `Acknowledge Now`;
809
- post.title = `NEED ACKNOWLEDGE DOCUMENT`;
800
+ post.title = data.title
801
+ post.caption = `NEED ACKNOWLEDGE DOCUMENT`;
810
802
 
811
803
  post.link = link;
812
- post.url = CONFIG.app.url;
804
+ post.url = process.env.APP_URL;
813
805
  post.description = `Hai ${users[post.user_id].fullname} <br>
814
806
 
815
807
 
@@ -817,21 +809,11 @@ router.post("/zzapproval", async (req, res) => {
817
809
  Please click the link above to view the document.`;
818
810
 
819
811
  post.note = `If you click the link, it's will be automatically acknowledged`;
820
- Mail.gmail(req, res, post, email);
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
- }
812
+ Mail.approval(req, res, post, email);
813
+
832
814
  io.to(users[item].token).emit(
833
- "message",
834
- "Need Acknowledge " + data.title
815
+ "message",
816
+ "Need Acknowledge " + data.title
835
817
  );
836
818
  });
837
819
  }
@@ -849,30 +831,30 @@ router.post("/zzapproval", async (req, res) => {
849
831
  router.get("/za/:token", csrfProtection, async (req, res) => {
850
832
  let token = req.params.token;
851
833
  let data = {},
852
- data2 = {};
834
+ data2 = {};
853
835
  let template = "";
854
836
  let result;
855
837
  let isClosed = false;
856
838
  let footers = "";
857
839
  let details = [];
858
- let routeName =
859
- env == "production" ? process.env.APP_URL : `http://localhost:${port}`;
840
+ var port = ecosystem.apps[0].env.PORT;
841
+ let routeName = env == "production" ? process.env.APP_URL : `http://localhost:${port}`;
860
842
  let statusLabel = "";
861
843
  let knowings = [];
862
844
  const MYMODELS = myCache.get("MYMODELS");
863
845
  let MYMODEL = MYMODELS["zapprovals"];
864
846
  let users = Util.arrayToObject(
865
- await connection.results({ table: "zuser" }),
866
- "id"
847
+ await connection.results({ table: "zuser" }),
848
+ "id"
867
849
  );
868
850
  try {
869
851
  result = await connection.result({
870
852
  select:
871
- "*, 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",
853
+ "*, 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
854
  table: "zapprovals_details",
873
855
  joins: [
874
856
  "LEFT JOIN zapprovals ON (zapprovals_details.title_id = zapprovals.id)",
875
- "LEFT JOIN employee ON (zapprovals_details.user_id = employee.id)",
857
+ "LEFT JOIN zuser ON (zapprovals_details.user_id = zuser.id)",
876
858
  ],
877
859
  where: { "zapprovals_details.token": token },
878
860
  });
@@ -882,10 +864,10 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
882
864
  statusLabel = MYMODEL.widgets.status.fields[result.statuse];
883
865
  routeName = routeName + "/" + result.table + "/view/" + result.id_data;
884
866
  if (
885
- result.statuse == 3 ||
886
- result.statuse == 4 ||
887
- result.mystatus == 3 ||
888
- result.mystatus == 4
867
+ result.statuse == 3 ||
868
+ result.statuse == 4 ||
869
+ result.mystatus == 3 ||
870
+ result.mystatus == 4
889
871
  ) {
890
872
  isClosed = true;
891
873
  }
@@ -938,9 +920,9 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
938
920
  });
939
921
  //var users = await zRoute.getUsers();
940
922
  var message =
941
- users[result.user_id].fullname +
942
- " has readed document " +
943
- result.title;
923
+ users[result.user_id].fullname +
924
+ " has readed document " +
925
+ result.title;
944
926
  details.forEach(function (item) {
945
927
  io.to(users[item.user_id].token).emit("message", message);
946
928
  });
@@ -957,7 +939,6 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
957
939
  for (var key in data) {
958
940
  template = Util.replaceAll(template, "{{" + key + "}}", data[key]);
959
941
  }
960
-
961
942
  footers = await zRoute.approversFooter(details);
962
943
 
963
944
  //send activity
@@ -1000,13 +981,13 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1000
981
  let status = req.body.status;
1001
982
  let json = Util.jsonSuccess("Success");
1002
983
  let data = {},
1003
- data2 = {};
984
+ data2 = {};
1004
985
  let template = "";
1005
986
  let approvers = [],
1006
- knowings = [];
987
+ knowings = [];
1007
988
  let users = Util.arrayToObject(
1008
- await connection.results({ table: "zuser" }),
1009
- "id"
989
+ await connection.results({ table: "zuser" }),
990
+ "id"
1010
991
  );
1011
992
  let employee_user = users;
1012
993
  const MYMODELS = myCache.get("MYMODELS");
@@ -1015,7 +996,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1015
996
  try {
1016
997
  var results = await connection.results({
1017
998
  select:
1018
- "*,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 ",
999
+ "*,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
1000
  table: "zapprovals_details",
1020
1001
  joins: [
1021
1002
  "LEFT JOIN zapprovals ON (zapprovals_details.title_id = zapprovals.id)",
@@ -1083,24 +1064,24 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1083
1064
  where: { id: result.ide },
1084
1065
  });
1085
1066
 
1086
- //send activity
1087
- await connection.insert({
1088
- table: "zactivity",
1089
- data: {
1090
- company_id: result.company_id,
1091
- created_at: Util.now(),
1092
- created_by: result.user_id,
1093
- updated_by: result.user_id,
1094
- user_id: result.user_id,
1095
- table: MYMODEL.table,
1096
- id_data: result.ide,
1097
- status: status,
1098
- status_label: MYMODEL.widgets.status.fields[status],
1099
- title: MYMODEL.widgets.status.fields[status],
1100
- description: comments,
1101
- data: JSON.stringify(post),
1102
- },
1103
- });
1067
+ /* //send activity
1068
+ await connection.insert({
1069
+ table: "zactivity",
1070
+ data: {
1071
+ company_id: result.company_id,
1072
+ created_at: Util.now(),
1073
+ created_by: result.user_id,
1074
+ updated_by: result.user_id,
1075
+ user_id: result.user_id,
1076
+ table: MYMODEL.table,
1077
+ id_data: result.ide,
1078
+ status: status,
1079
+ status_label: MYMODEL.widgets.status.fields[status],
1080
+ title: MYMODEL.widgets.status.fields[status],
1081
+ description: comments,
1082
+ data: JSON.stringify(post),
1083
+ },
1084
+ });*/
1104
1085
 
1105
1086
  //send notification
1106
1087
  if (status == 3 || status == 4) {
@@ -1138,14 +1119,14 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1138
1119
  table: "zapprovals_details",
1139
1120
  data: post,
1140
1121
  });
1141
- let link = CONFIG.app.url + "/za/" + post.token;
1122
+ let link = process.env.APP_URL + "/za/" + post.token;
1142
1123
  let email = users[item].username;
1143
1124
 
1144
1125
  post.subject = `Need Approve ${result.title}`;
1145
1126
  post.buttonTitle = `Approve Now`;
1146
- post.title = `NEED APPROVE DOCUMENT`;
1127
+ post.title = result.title;
1147
1128
  post.link = link;
1148
- post.url = CONFIG.app.url;
1129
+ post.url = process.env.APP_URL;
1149
1130
  post.description = `Hai ${users[item].fullname} <br>
1150
1131
 
1151
1132
 
@@ -1162,7 +1143,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1162
1143
  {
1163
1144
  title: users[item].fullname + " " + users[item].position,
1164
1145
  description:
1165
- "@" + users[item].fullname + " " + users[item].position,
1146
+ "@" + users[item].fullname + " " + users[item].position,
1166
1147
  rowId: "roe" + index,
1167
1148
  },
1168
1149
  ];
@@ -1173,7 +1154,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1173
1154
  {
1174
1155
  title: users[item].fullname + " " + users[item].position,
1175
1156
  description:
1176
- "@" + users[item].fullname + " " + users[item].position,
1157
+ "@" + users[item].fullname + " " + users[item].position,
1177
1158
  rowId: "roe" + index,
1178
1159
  },
1179
1160
  ];
@@ -1204,7 +1185,7 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1204
1185
  });
1205
1186
 
1206
1187
  //send todolist
1207
- await connection.insert({
1188
+ /*await connection.insert({
1208
1189
  table: "ztodolist",
1209
1190
  data: {
1210
1191
  company_id: result.company_id,
@@ -1221,12 +1202,12 @@ router.post("/za/:token", csrfProtection, async (req, res) => {
1221
1202
  description: result.title,
1222
1203
  users: JSON.stringify(approvers),
1223
1204
  },
1224
- });
1205
+ });*/
1225
1206
 
1226
1207
  //send toastr using socket.io
1227
1208
  io.to(users[item].token).emit(
1228
- "message",
1229
- "Need Approve for document : " + result.title
1209
+ "message",
1210
+ "Need Approve for document : " + result.title
1230
1211
  );
1231
1212
  }
1232
1213
  }
@@ -1595,21 +1576,21 @@ router.post("/zhistory-data", async (req, res) => {
1595
1576
  users = myCache.get("users");
1596
1577
  } else {
1597
1578
  users = Util.arrayToObject(
1598
- await connection.results({
1599
- table: "zuser",
1600
- }),
1601
- "id"
1579
+ await connection.results({
1580
+ table: "zuser",
1581
+ }),
1582
+ "id"
1602
1583
  );
1603
1584
  myCache.set("users", users);
1604
1585
  }
1605
1586
  html = await zRoute.history(
1606
- req,
1607
- res,
1608
- relations,
1609
- id,
1610
- MYMODEL,
1611
- users,
1612
- results
1587
+ req,
1588
+ res,
1589
+ relations,
1590
+ id,
1591
+ MYMODEL,
1592
+ users,
1593
+ results
1613
1594
  );
1614
1595
  }
1615
1596
  res.json(html);
@@ -1680,10 +1661,10 @@ router.post("/zcompress-dropzone", async (req, res) => {
1680
1661
  console.log(dir);
1681
1662
  const timestamp = Date.now();
1682
1663
  const tempDir = path.join(
1683
- dirRoot,
1684
- "public",
1685
- "temps",
1686
- `${table}___${field}___${id}___${userId}___${timestamp}`
1664
+ dirRoot,
1665
+ "public",
1666
+ "temps",
1667
+ `${table}___${field}___${id}___${userId}___${timestamp}`
1687
1668
  );
1688
1669
  if (!fs.existsSync(tempDir)) {
1689
1670
  fs.mkdirSync(tempDir);
@@ -1713,8 +1694,8 @@ router.post("/zcompress-dropzone", async (req, res) => {
1713
1694
  } catch (error) {
1714
1695
  console.log(`Skipping ${filename} - not a valid image file`);
1715
1696
  io.to(room).emit(
1716
- "errormessage",
1717
- `Skipping ${filename} - not a valid image file`
1697
+ "errormessage",
1698
+ `Skipping ${filename} - not a valid image file`
1718
1699
  );
1719
1700
  continue;
1720
1701
  }
@@ -1724,7 +1705,7 @@ router.post("/zcompress-dropzone", async (req, res) => {
1724
1705
  try {
1725
1706
  // Compress the image to a buffer
1726
1707
  const compressedBuffer = await image[format](
1727
- config[format]
1708
+ config[format]
1728
1709
  ).toBuffer();
1729
1710
  await wait(timeExcecute); // Wait for file system
1730
1711
  // Write the compressed buffer to the original file
@@ -1883,8 +1864,8 @@ router.post("/zdropbox-file/:index", async (req, res) => {
1883
1864
  res.json(jsonMessage.datas);
1884
1865
  } else {
1885
1866
  io.to(room).emit(
1886
- "errormessage",
1887
- `Please reload your browser !! Error ${pathFile} not exist in dropbox, `
1867
+ "errormessage",
1868
+ `Please reload your browser !! Error ${pathFile} not exist in dropbox, `
1888
1869
  );
1889
1870
  res.json(datas);
1890
1871
  }
@@ -2085,32 +2066,32 @@ router.post("/zcompress-dropbox", async (req, res) => {
2085
2066
  const fileName = file;
2086
2067
  // Process the image with sharp
2087
2068
  const processedImage = await sharp(response.result.fileBinary)
2088
- .resize({
2089
- width: 1024,
2090
- height: null, // Maintain aspect ratio
2091
- fit: "inside",
2092
- withoutEnlargement: true, // Don't enlarge if image is smaller than 1024px
2093
- })
2094
- .toBuffer()
2095
- .then((buffer) => {
2096
- // Check if the file is PNG
2097
- if (fileName.toLowerCase().endsWith(".png")) {
2098
- return sharp(buffer)
2099
- .png({
2100
- quality: 60,
2101
- compressionLevel: 9, // Maximum compression for PNG
2102
- })
2103
- .toBuffer();
2104
- } else {
2105
- // For JPEG files
2106
- return sharp(buffer)
2107
- .jpeg({
2108
- quality: 60,
2109
- mozjpeg: true, // Better compression
2110
- })
2111
- .toBuffer();
2112
- }
2113
- });
2069
+ .resize({
2070
+ width: 1024,
2071
+ height: null, // Maintain aspect ratio
2072
+ fit: "inside",
2073
+ withoutEnlargement: true, // Don't enlarge if image is smaller than 1024px
2074
+ })
2075
+ .toBuffer()
2076
+ .then((buffer) => {
2077
+ // Check if the file is PNG
2078
+ if (fileName.toLowerCase().endsWith(".png")) {
2079
+ return sharp(buffer)
2080
+ .png({
2081
+ quality: 60,
2082
+ compressionLevel: 9, // Maximum compression for PNG
2083
+ })
2084
+ .toBuffer();
2085
+ } else {
2086
+ // For JPEG files
2087
+ return sharp(buffer)
2088
+ .jpeg({
2089
+ quality: 60,
2090
+ mozjpeg: true, // Better compression
2091
+ })
2092
+ .toBuffer();
2093
+ }
2094
+ });
2114
2095
 
2115
2096
  // Upload the compressed image back to Dropbox
2116
2097
  await dbx.filesUpload({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.5.16",
3
+ "version": "1.5.18",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"