fix-chat-aggregate-dates.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const fs = require('fs')
  2. const paths = [
  3. 'd:/ylrz_saas_new/saas-companyui/public/chat-aggregate.html',
  4. 'd:/ylrz_saas_new/saas-mgnui/public/chat-aggregate.html',
  5. 'd:/ylrz_saas_new/adminui/public/chat-aggregate.html',
  6. 'd:/ylrz_saas_new/java/fs-comm-gateway/src/main/resources/static/chat-aggregate.html',
  7. 'd:/ylrz_saas_new/java/fs-saas-company/src/main/resources/static/chat-aggregate.html'
  8. ]
  9. const fnBlock = `
  10. const formatLobsterDateTime = (time) => {
  11. if (time === null || time === undefined || time === '') return '??';
  12. const date = time instanceof Date ? time : new Date(time);
  13. if (isNaN(date.getTime())) return '??';
  14. const y = date.getFullYear();
  15. const m = String(date.getMonth() + 1).padStart(2, '0');
  16. const d = String(date.getDate()).padStart(2, '0');
  17. const h = String(date.getHours()).padStart(2, '0');
  18. const mi = String(date.getMinutes()).padStart(2, '0');
  19. const s = String(date.getSeconds()).padStart(2, '0');
  20. return \`\${y}-\${m}-\${d} \${h}:\${mi}:\${s}\`;
  21. };
  22. `
  23. for (const p of paths) {
  24. if (!fs.existsSync(p)) {
  25. console.log('skip', p)
  26. continue
  27. }
  28. let c = fs.readFileSync(p, 'utf8')
  29. if (c.includes('const formatLobsterDateTime')) {
  30. console.log('already', p)
  31. continue
  32. }
  33. c = c.replace(
  34. /return await response\.json\(\);\r?\n };\r?\n\r?\n \/\/ �˻��б�/,
  35. 'return await response.json();\n };\n\n const formatLobsterDateTime = (time) => {\n if (time === null || time === undefined || time === \'\') return \'��\';\n const date = time instanceof Date ? time : new Date(time);\n if (isNaN(date.getTime())) return \'��\';\n const y = date.getFullYear();\n const m = String(date.getMonth() + 1).padStart(2, \'0\');\n const d = String(date.getDate()).padStart(2, \'0\');\n const h = String(date.getHours()).padStart(2, \'0\');\n const mi = String(date.getMinutes()).padStart(2, \'0\');\n const s = String(date.getSeconds()).padStart(2, \'0\');\n return `${y}-${m}-${d} ${h}:${mi}:${s}`;\n };\n\n // �˻��б�'
  36. )
  37. c = c.replace(
  38. '<div class="session-time">{{sess.lastTime||\'\'}}</div>',
  39. '<div class="session-time">{{formatLobsterDateTime(sess.lastTime)}}</div>'
  40. )
  41. c = c.replace(
  42. '<div class="msg-time">{{msg.time}}</div>',
  43. '<div class="msg-time">{{formatLobsterDateTime(msg.time)}}</div>'
  44. )
  45. c = c.replace(
  46. '<span class="value">{{currentSession?.createTime||\'-\'}}</span>',
  47. '<span class="value">{{formatLobsterDateTime(currentSession?.createTime)}}</span>'
  48. )
  49. c = c.replace(
  50. '<div class="time">{{record.time}}</div>',
  51. '<div class="time">{{formatLobsterDateTime(record.time)}}</div>'
  52. )
  53. c = c.replace(
  54. /new Date\(\)\.toLocaleTimeString\('zh-CN',\{hour:'2-digit',minute:'2-digit'\}\)/g,
  55. 'new Date()'
  56. )
  57. c = c.replace(/new Date\(\)\.toLocaleDateString\('zh-CN'\)/g, 'new Date()')
  58. c = c.replace(
  59. /selectAccount, selectSession, sendMessage, toggleControlMode, channelName/,
  60. 'selectAccount, selectSession, sendMessage, toggleControlMode, channelName, formatLobsterDateTime'
  61. )
  62. fs.writeFileSync(p, c, 'utf8')
  63. console.log('updated', p)
  64. }