zet-lib 1.2.97 → 1.2.98

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/Form.js CHANGED
@@ -466,7 +466,7 @@ Form.field = (obj) => {
466
466
  if (extFile.type == 'image') {
467
467
  displayForm += `<img src="${filename}" class="boxy zoom mx-2 my-2" width="200px">`
468
468
  } else {
469
- displayForm += Util.fileView(`/uploads/${obj.table}/${obj.key}/`, item, { withIcon: true })
469
+ displayForm += '<br>' + Util.fileView(`/uploads/${obj.table}/${obj.key}/`, item, { withIcon: true }) + '<br>'
470
470
  }
471
471
  })
472
472
  }
package/lib/Util.js CHANGED
@@ -1254,4 +1254,8 @@ Util.sortArray = (arr, key) => {
1254
1254
  return arr.sort(compare)
1255
1255
  }
1256
1256
 
1257
+ Util.cleanString = (str = '') => {
1258
+ return str.replaceAll('(', '').replaceAll(')', '').replaceAll('%', '').replaceAll('-', '')
1259
+ }
1260
+
1257
1261
  module.exports = Util
package/lib/zAppRouter.js CHANGED
@@ -1479,6 +1479,7 @@ router.post('/zdropzone', async (req, res) => {
1479
1479
  router.post('/zdropzone-remove', async (req, res) => {
1480
1480
  try {
1481
1481
  let userId = res.locals.userId
1482
+ let cacheName = req.body.cname.replace('ZUSER___ID', userId)
1482
1483
  let dir = `${dirRoot}/public/zdropzone/${userId}`
1483
1484
  if (!fs.existsSync(dir)) {
1484
1485
  fs.mkdirSync(dir, { recursive: true })
@@ -1486,6 +1487,11 @@ router.post('/zdropzone-remove', async (req, res) => {
1486
1487
  let filename = `${dirRoot}/public/zdropzone/${userId}/${req.body.file}`
1487
1488
  if (Util.fileExist(filename)) {
1488
1489
  await fs.unlink(filename)
1490
+ if (myCache.has(cacheName)) {
1491
+ arr = myCache.get(name)
1492
+ }
1493
+ arr = Util.arrayDelete(arr, body.file)
1494
+ myCache.set(name, arr)
1489
1495
  }
1490
1496
  res.json('ok')
1491
1497
  } catch (e) {
@@ -1503,6 +1509,7 @@ router.post('/zdropzone-attributes', async (req, res) => {
1503
1509
  let body = req.body
1504
1510
  let category = body.category
1505
1511
  let name = `dropzone__${userId}__${body.table}__${body.field}__${body.type}`
1512
+ //dropzone__${res.locals.userId}__${table}__${key}__create
1506
1513
  let arr = []
1507
1514
  if (category === 'add') {
1508
1515
  if (myCache.has(name)) {
package/lib/zRoute.js CHANGED
@@ -968,6 +968,9 @@ zRoute.dataTableData = (key, value, MYMODEL, relations, myid = '') => {
968
968
 
969
969
  case 'dropzone':
970
970
  if (myvalue && myvalue.length > 0) {
971
+ if (typeof myvalue === 'string') {
972
+ value = [myvalue]
973
+ }
971
974
  myvalue = value.map((item) => `<a class="text-success" target="_blank" href="/uploads/${MYMODEL.routeName}/${key}/${item}"> ${item.substring(13)}</a> `)
972
975
  }
973
976
  break
@@ -2318,7 +2321,11 @@ zRoute.forms = (req, res, MYMODEL, relations, data = {}) => {
2318
2321
  case 'dropzone':
2319
2322
  let dropzone_data_arr = []
2320
2323
  if (obj.value.length > 0) {
2321
- obj.value.map((item) => {
2324
+ let dropfiles = obj.value || []
2325
+ if (typeof obj.value == 'string') {
2326
+ dropfiles = [obj.value]
2327
+ }
2328
+ dropfiles.map((item) => {
2322
2329
  let filename = `${dirRoot}/public/uploads/${MYMODEL.table}/${key}/${item}`
2323
2330
  var fileSizeInBytes = 12345
2324
2331
  if (Util.fileExist(filename)) {
@@ -2502,7 +2509,6 @@ zRoute.viewFormsSync = async (req, res, MYMODEL, data = {}) => {
2502
2509
  //add tabs role
2503
2510
  if (MYMODEL.hasOwnProperty('hasTabs') && MYMODEL.hasTabs) {
2504
2511
  let script = ''
2505
- //MYMODEL.tabs.map((table))
2506
2512
  script += `$(()=> {
2507
2513
  ajaxPost('/ztab-access',{table:"${MYMODEL.table}"},(data)=> {
2508
2514
  let dataTabs = ${MYMODEL.hasOwnProperty('tabs') ? JSON.stringify(MYMODEL.tabs) : []};
@@ -3242,7 +3248,8 @@ zRoute.generateJS = (req, res, MYMODEL, relations, zForms = '', data = {}) => {
3242
3248
  maxFilesize: 30,
3243
3249
  headers: {"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content")},
3244
3250
  removedfile: function(file) {
3245
- ajaxPost("/zdropzone-remove",{file:file.name},(data) => {
3251
+ const type = window.location.href.split("/").pop();
3252
+ ajaxPost("/zdropzone-remove",{file:file.name, cname:"dropzone__ZUSER___ID__${MYMODEL.table}__${item}__"+type},(data) => {
3246
3253
  file.previewElement.remove();
3247
3254
  })
3248
3255
  },
@@ -3615,14 +3622,18 @@ zRoute.insertSQL = async (req, res, table, data) => {
3615
3622
  if (arr.length > 0) {
3616
3623
  let time = new Date().getTime()
3617
3624
  arr.map((item) => {
3618
- let newItem = time + item
3619
- newArr.push(newItem)
3620
- fs.rename(path_src + item, path_dest + newItem)
3625
+ if (Util.fileExist(path_src + item)) {
3626
+ let newItem = Util.cleanString(time + item)
3627
+ newArr.push(newItem)
3628
+ fs.rename(path_src + item, path_dest + newItem)
3629
+ }
3621
3630
  })
3622
-
3623
3631
  data[key] = Util.array_to_jsonb(newArr)
3624
3632
  }
3625
3633
  }
3634
+
3635
+ //delete cache
3636
+ myCache.del(name)
3626
3637
  }
3627
3638
  }
3628
3639
  const result = await connection.insert({ table: table, data: data })
@@ -3670,21 +3681,19 @@ zRoute.updateSQL = async (req, res, table, data, whereData) => {
3670
3681
  }
3671
3682
  let name = `dropzone__${userId}__${MYMODEL.table}__${key}__${whereData.id}`
3672
3683
  if (myCache.has(name)) {
3673
- let arr = myCache.get(name)
3684
+ let arr = myCache.get(name) || []
3674
3685
  let newArr = []
3675
- if (arr.length > 0) {
3676
- let time = new Date().getTime()
3677
- arr.map((item) => {
3678
- if (!Util.fileExist(path_dest + item)) {
3679
- let newItem = time + item
3680
- newArr.push(newItem)
3681
- fs.rename(path_src + item, path_dest + newItem)
3682
- } else {
3683
- newArr.push(item)
3684
- }
3685
- })
3686
- data[key] = Util.array_to_jsonb(newArr)
3687
- }
3686
+ let time = new Date().getTime()
3687
+ arr.map((item) => {
3688
+ if (!Util.fileExist(path_dest + item)) {
3689
+ let newItem = time + item
3690
+ newArr.push(newItem)
3691
+ fs.rename(path_src + item, path_dest + newItem)
3692
+ } else {
3693
+ newArr.push(item)
3694
+ }
3695
+ })
3696
+ data[key] = Util.array_to_jsonb(newArr)
3688
3697
  }
3689
3698
  }
3690
3699
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "1.2.97",
3
+ "version": "1.2.98",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"