zet-lib 1.4.19 → 1.4.20

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/index.js CHANGED
@@ -1,38 +1,39 @@
1
- 'use strict'
1
+ "use strict";
2
2
 
3
3
  module.exports = {
4
- access: require('./access'),
5
- Util: require('./Util'),
6
- myCache: require('./cache'),
7
- connection: require('./connection'),
8
- zDataTable: require('./zdataTable'),
9
- zDebug: require('./debug'),
10
- zForm: require('./Form'),
11
- io: require('./io'),
12
- zMail: require('./Mail'),
13
- moduleLib: require('./moduleLib'),
14
- Model:require('./Model'),
15
- zApp: require('./zapp'),
16
- zAppRouter: require('./zAppRouter'),
17
- zComponent: require('./zComponent'),
18
- zFn: require('./zFn'),
19
- zFunction: require('./zFunction'),
20
- zMenuRouter: require('./zMenuRouter'),
21
- zGeneratorRouter: require('./zGeneratorRouter'),
22
- zViewGenerator:require('./zViewGenerator'),
23
- zReport: require('./zReport'),
24
- zRoute: require('./zRoute'),
25
- zRole: require('./zRole'),
26
- zRoleRouter: require('./zRoleRouter'),
27
- zPage: require('./zPage'),
28
- zTester: require('./zTester'),
29
- zCache: require('./zCache'),
30
- puppeteer: require('puppeteer'),
31
- moment: require('moment'),
32
- ejs: require('ejs'),
33
- axios: require('axios'),
34
- Excel: require('exceljs'),
35
- pm2: require('pm2'),
36
- nodemailer: require('nodemailer'),
37
- readXlsxFile: require('read-excel-file/node')
38
- }
4
+ access: require("./access"),
5
+ Util: require("./Util"),
6
+ myCache: require("./cache"),
7
+ connection: require("./connection"),
8
+ zDataTable: require("./zdataTable"),
9
+ zDebug: require("./debug"),
10
+ zForm: require("./Form"),
11
+ io: require("./io"),
12
+ zMail: require("./Mail"),
13
+ moduleLib: require("./moduleLib"),
14
+ Model: require("./Model"),
15
+ zApp: require("./zapp"),
16
+ zAppRouter: require("./zAppRouter"),
17
+ zComponent: require("./zComponent"),
18
+ zFn: require("./zFn"),
19
+ zFunction: require("./zFunction"),
20
+ zMenuRouter: require("./zMenuRouter"),
21
+ zGeneratorRouter: require("./zGeneratorRouter"),
22
+ zViewGenerator: require("./zViewGenerator"),
23
+ zReport: require("./zReport"),
24
+ zRoute: require("./zRoute"),
25
+ zRole: require("./zRole"),
26
+ zRoleRouter: require("./zRoleRouter"),
27
+ zPage: require("./zPage"),
28
+ zTester: require("./zTester"),
29
+ zCache: require("./zCache"),
30
+ puppeteer: require("puppeteer"),
31
+ moment: require("moment"),
32
+ ejs: require("ejs"),
33
+ axios: require("axios"),
34
+ Excel: require("exceljs"),
35
+ pm2: require("pm2"),
36
+ nodemailer: require("nodemailer"),
37
+ readXlsxFile: require("read-excel-file/node"),
38
+ JSZip: require("jszip"),
39
+ };
package/lib/zAppRouter.js CHANGED
@@ -26,6 +26,8 @@ const sharp = require("sharp");
26
26
  const path = require("path");
27
27
  const { Dropbox } = require("dropbox");
28
28
  const fetch = require("isomorphic-fetch");
29
+ const JSZip = require("jszip");
30
+
29
31
  /*
30
32
  ajax Post
31
33
  */
@@ -405,8 +407,8 @@ router.post("/signup-custom", async (req, res) => {
405
407
  },
406
408
  });
407
409
  /* await zRoute.loginAjax(dataUser.username, body.password, req, res);
408
- //refresh cache
409
- await zCache.renew();*/
410
+ //refresh cache
411
+ await zCache.renew();*/
410
412
 
411
413
  res.json(Util.jsonSuccess("Successfuly"));
412
414
  } catch (e) {
@@ -710,15 +712,15 @@ router.post("/zzapproval", async (req, res) => {
710
712
  if (data.status == 2) {
711
713
  //send activity
712
714
  /* await zRoute.insertSQL(req, res, "zactivity", {
713
- user_id: res.locals.userId,
714
- table: MYMODEL.table,
715
- id_data: data.id,
716
- status: data.status,
717
- status_label: MYMODEL.widgets.status.fields[data.status],
718
- title: MYMODEL.widgets.status.fields[data.status],
719
- description: users[res.locals.userId].fname + " " +users[res.locals.userId].lname ,
720
- data: JSON.stringify(data)
721
- });*/
715
+ user_id: res.locals.userId,
716
+ table: MYMODEL.table,
717
+ id_data: data.id,
718
+ status: data.status,
719
+ status_label: MYMODEL.widgets.status.fields[data.status],
720
+ title: MYMODEL.widgets.status.fields[data.status],
721
+ description: users[res.locals.userId].fname + " " +users[res.locals.userId].lname ,
722
+ data: JSON.stringify(data)
723
+ });*/
722
724
  //if serial
723
725
  if (data.type == 2) {
724
726
  approvers = [approvers[0]];
@@ -788,38 +790,38 @@ router.post("/zzapproval", async (req, res) => {
788
790
  textWa += `Please click the link above to view the document.\r\n${link}`;
789
791
 
790
792
  /* await whatsapp({
791
- to: phone,
792
- text: textWa,
793
- sections: JSON.stringify(sections),
794
- buttonText: "Click me for details"
795
- });*/
793
+ to: phone,
794
+ text: textWa,
795
+ sections: JSON.stringify(sections),
796
+ buttonText: "Click me for details"
797
+ });*/
796
798
  }
797
799
 
798
800
  //send notification
799
801
  /* await zRoute.insertSQL(req, res, "znotification", {
800
- user_id: item,
801
- table: MYMODEL.table,
802
- id_data: data.id,
803
- status: 1,
804
- link: "/za/" + post.token,
805
- status_label: MYMODEL.widgets.status.fields[1],
806
- title: `Need Approve`,
807
- description: data.title,
808
- token: post.token
809
- });*/
802
+ user_id: item,
803
+ table: MYMODEL.table,
804
+ id_data: data.id,
805
+ status: 1,
806
+ link: "/za/" + post.token,
807
+ status_label: MYMODEL.widgets.status.fields[1],
808
+ title: `Need Approve`,
809
+ description: data.title,
810
+ token: post.token
811
+ });*/
810
812
 
811
813
  //send todolist
812
814
  /* await zRoute.insertSQL(req, res, "ztodolist", {
813
- user_id: item,
814
- table: MYMODEL.table,
815
- id_data: data.id,
816
- status: 1,
817
- link: "/za/" + post.token,
818
- status_label: MYMODEL.widgets.status.fields[1],
819
- title: `Need Approve`,
820
- description: data.title,
821
- users: JSON.stringify(allUsers)
822
- });*/
815
+ user_id: item,
816
+ table: MYMODEL.table,
817
+ id_data: data.id,
818
+ status: 1,
819
+ link: "/za/" + post.token,
820
+ status_label: MYMODEL.widgets.status.fields[1],
821
+ title: `Need Approve`,
822
+ description: data.title,
823
+ users: JSON.stringify(allUsers)
824
+ });*/
823
825
 
824
826
  //send toastr using socket.io
825
827
  io.to(users[item].token).emit("message", "Need Approve " + data.title);
@@ -865,50 +867,50 @@ router.post("/zzapproval", async (req, res) => {
865
867
  textWa += "We have some document for you.\r\n";
866
868
  textWa += `Please click the link above to view the document.\r\n${link}`;
867
869
  /* await whatsapp({
868
- to: phone,
869
- text: textWa,
870
- sections: JSON.stringify(sections),
871
- buttonText: "Click me for details"
872
- });*/
870
+ to: phone,
871
+ text: textWa,
872
+ sections: JSON.stringify(sections),
873
+ buttonText: "Click me for details"
874
+ });*/
873
875
  }
874
876
 
875
877
  //send activity
876
878
  /* await cRoute.insertSQL(req, res, "zactivity",{
877
- user_id:item,
878
- table:MYMODEL.table,
879
- id_data:data.id,
880
- status:7,
881
- status_label: MYMODEL.widgets.status.fields[7],
882
- title : MYMODEL.widgets.status.fields[7],
883
- description: data.title,
884
- data:JSON.stringify(data)
885
- });*/
879
+ user_id:item,
880
+ table:MYMODEL.table,
881
+ id_data:data.id,
882
+ status:7,
883
+ status_label: MYMODEL.widgets.status.fields[7],
884
+ title : MYMODEL.widgets.status.fields[7],
885
+ description: data.title,
886
+ data:JSON.stringify(data)
887
+ });*/
886
888
 
887
889
  //send notification
888
890
  /* await zRoute.insertSQL(req, res, "znotification", {
889
- user_id: item,
890
- table: MYMODEL.table,
891
- id_data: data.id,
892
- status: 1,
893
- link: "/za/" + post.token,
894
- status_label: MYMODEL.widgets.status.fields[1],
895
- title: `Need Acknowledge`,
896
- description: data.title,
897
- token: post.token
898
- });
899
-
900
- //send todolist
901
- await zRoute.insertSQL(req, res, "ztodolist", {
902
- user_id: item,
903
- table: MYMODEL.table,
904
- id_data: data.id,
905
- status: 1,
906
- link: "/za/" + post.token,
907
- status_label: MYMODEL.widgets.status.fields[1],
908
- title: `Need Acknowledge`,
909
- description: data.title,
910
- users: JSON.stringify(allUsers)
911
- });*/
891
+ user_id: item,
892
+ table: MYMODEL.table,
893
+ id_data: data.id,
894
+ status: 1,
895
+ link: "/za/" + post.token,
896
+ status_label: MYMODEL.widgets.status.fields[1],
897
+ title: `Need Acknowledge`,
898
+ description: data.title,
899
+ token: post.token
900
+ });
901
+
902
+ //send todolist
903
+ await zRoute.insertSQL(req, res, "ztodolist", {
904
+ user_id: item,
905
+ table: MYMODEL.table,
906
+ id_data: data.id,
907
+ status: 1,
908
+ link: "/za/" + post.token,
909
+ status_label: MYMODEL.widgets.status.fields[1],
910
+ title: `Need Acknowledge`,
911
+ description: data.title,
912
+ users: JSON.stringify(allUsers)
913
+ });*/
912
914
  io.to(users[item].token).emit(
913
915
  "message",
914
916
  "Need Acknowledge " + data.title
@@ -1044,23 +1046,23 @@ router.get("/za/:token", csrfProtection, async (req, res) => {
1044
1046
  if (result.mystatus == 7) {
1045
1047
  MYMODEL = MYMODELS["zapprovals"];
1046
1048
  /* await connection.insert({
1047
- table: "zactivity",
1048
- data: {
1049
- company_id: result.company_id,
1050
- created_at: Util.now(),
1051
- created_by: result.user_id,
1052
- updated_by: result.user_id,
1053
- user_id: result.user_id,
1054
- table: MYMODEL.table,
1055
- id_data: result.ide,
1056
- status: 6,
1057
- status_label: MYMODEL.widgets.status.fields[6],
1058
- title: `${MYMODEL.widgets.status.fields[6]}`,
1059
- description: `Ok `,
1060
- data: JSON.stringify(data)
1061
- }
1062
- });
1063
- */
1049
+ table: "zactivity",
1050
+ data: {
1051
+ company_id: result.company_id,
1052
+ created_at: Util.now(),
1053
+ created_by: result.user_id,
1054
+ updated_by: result.user_id,
1055
+ user_id: result.user_id,
1056
+ table: MYMODEL.table,
1057
+ id_data: result.ide,
1058
+ status: 6,
1059
+ status_label: MYMODEL.widgets.status.fields[6],
1060
+ title: `${MYMODEL.widgets.status.fields[6]}`,
1061
+ description: `Ok `,
1062
+ data: JSON.stringify(data)
1063
+ }
1064
+ });
1065
+ */
1064
1066
 
1065
1067
  await connection.update({
1066
1068
  table: "zapprovals_details",
@@ -2057,6 +2059,7 @@ router.post("/zdropbox-files", async (req, res) => {
2057
2059
  }
2058
2060
  res.json(datas);
2059
2061
  });
2062
+
2060
2063
  router.post("/zdropbox-file/:index", handleTokenRefresh, async (req, res) => {
2061
2064
  let datas = {};
2062
2065
  const room = res.locals.token;
@@ -2197,4 +2200,72 @@ router.get(
2197
2200
  }
2198
2201
  );
2199
2202
 
2203
+ // Download and zip files endpoint
2204
+ router.get("/zdownloads-dropbox/:table/:field/:id", async (req, res) => {
2205
+ try {
2206
+ let table = req.params.table;
2207
+ let field = req.params.field;
2208
+ let id = req.params.id;
2209
+ const room = res.locals.token;
2210
+ let result = await connection.result({
2211
+ table: table,
2212
+ where: {
2213
+ id: id,
2214
+ },
2215
+ });
2216
+ let dir = `${dirRoot}/public/uploads/${table}/${field}/`;
2217
+ let arr = [];
2218
+ let files = result[field];
2219
+ const jsZip = new JSZip();
2220
+ const filesToZip = [];
2221
+ // Download each file and add to zip
2222
+ let i = 0;
2223
+ let filePath = "";
2224
+ let fileName = "";
2225
+ const count = files.length || 0;
2226
+ for (const file of files) {
2227
+ try {
2228
+ filePath = `/${table}/${field}/${file}`;
2229
+ const response = await dbx.filesDownload({
2230
+ path: filePath,
2231
+ });
2232
+ // Get the file name from the path
2233
+ fileName = filePath.split("/").pop();
2234
+ // Add file to zip array
2235
+ jsZip.file(fileName, response.result.fileBinary);
2236
+ io.to(room).emit("progress", {
2237
+ value: Math.round(((i + 1) / count) * 100),
2238
+ style: `progress-bar progress-bar-striped bg-success`,
2239
+ data: `Download ${fileName} successfully`,
2240
+ });
2241
+ } catch (error) {
2242
+ console.error(`Error downloading file ${filePath}:`, error);
2243
+ io.to(room).emit("errormessage", `Error downloading file ${fileName} `);
2244
+ continue;
2245
+ }
2246
+ i++;
2247
+ }
2248
+ io.to(room).emit("progress", {
2249
+ value: 100,
2250
+ style: `progress-bar progress-bar-striped bg-success`,
2251
+ data: `Zip all images complete...`,
2252
+ });
2253
+ let time = new Date().getTime();
2254
+ let zipname = `${table}_${field}_${time}.zip`;
2255
+ // Generate zip file
2256
+ const zipBuffer = await jsZip.generateAsync({ type: "nodebuffer" });
2257
+ // Set response headers
2258
+ res.setHeader("Content-Type", "application/zip");
2259
+ res.setHeader(`Content-Disposition`, `attachment; filename=${zipname}`);
2260
+ // Send the zip file
2261
+ res.send(zipBuffer);
2262
+ } catch (error) {
2263
+ console.error("Error creating zip file:", error);
2264
+ res.status(500).json({
2265
+ error: "Failed to create zip file",
2266
+ details: error.message,
2267
+ });
2268
+ }
2269
+ });
2270
+
2200
2271
  module.exports = router;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.4.19",
3
+ "version": "1.4.20",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -40,6 +40,7 @@
40
40
  "html-minifier-terser": "^7.2.0",
41
41
  "isomorphic-fetch": "^3.0.0",
42
42
  "js-sha256": "^0.9.0",
43
+ "jszip": "^3.10.1",
43
44
  "moment": "^2.30.1",
44
45
  "node-cache": "^5.1.2",
45
46
  "nodemailer": "^6.9.4",