node-karin 1.15.5 → 1.16.1

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/adapter-BqlH3u3X.mjs +218 -0
  3. package/dist/app-DdMQbBEY.mjs +4109 -0
  4. package/dist/cache-CPcPeo6N.mjs +163 -0
  5. package/dist/chunk-NzVPYdc1.mjs +21 -0
  6. package/dist/cli/index.cjs +10900 -1
  7. package/dist/cli/index.d.ts +1 -1
  8. package/dist/cli/index.mjs +10770 -10224
  9. package/dist/file-ZGuqNDd-.mjs +15987 -0
  10. package/dist/file-dGy9of8-.mjs +268 -0
  11. package/dist/fsSync-Cf5MWILk.mjs +65 -0
  12. package/dist/index.d.ts +12235 -12738
  13. package/dist/index.mjs +2054 -25247
  14. package/dist/internal-DupfycKE.mjs +597 -0
  15. package/dist/kv-DZp4UIxg.mjs +192 -0
  16. package/dist/module/art-template.d.ts +2 -13
  17. package/dist/module/art-template.mjs +3 -1
  18. package/dist/module/axios.d.ts +3 -2
  19. package/dist/module/axios.mjs +5 -2
  20. package/dist/module/chalk.d.ts +3 -2
  21. package/dist/module/chalk.mjs +5 -2
  22. package/dist/module/chokidar.d.ts +3 -2
  23. package/dist/module/chokidar.mjs +5 -2
  24. package/dist/module/express.d.ts +2 -1
  25. package/dist/module/express.mjs +3 -1
  26. package/dist/module/lodash.d.ts +2 -1
  27. package/dist/module/lodash.mjs +3 -1
  28. package/dist/module/log4js.d.ts +3 -2
  29. package/dist/module/log4js.mjs +5 -2
  30. package/dist/module/moment.d.ts +2 -1
  31. package/dist/module/moment.mjs +3 -1
  32. package/dist/module/node-schedule.d.ts +3 -2
  33. package/dist/module/node-schedule.mjs +5 -2
  34. package/dist/module/redis.d.ts +3 -2
  35. package/dist/module/redis.mjs +5 -2
  36. package/dist/module/sqlite3.d.ts +3 -2
  37. package/dist/module/sqlite3.mjs +5 -2
  38. package/dist/module/ws.d.ts +3 -2
  39. package/dist/module/ws.mjs +5 -2
  40. package/dist/module/yaml.d.ts +3 -2
  41. package/dist/module/yaml.mjs +5 -2
  42. package/dist/queue-CnKedaZA.mjs +70 -0
  43. package/dist/redis-aLJ7wbJH.mjs +1556 -0
  44. package/dist/render-DPqueDZr.mjs +170 -0
  45. package/dist/root.d.ts +46 -46
  46. package/dist/root.mjs +136 -93
  47. package/dist/router-zPSN9-tY.mjs +124 -0
  48. package/dist/server-DT64D-m-.mjs +38 -0
  49. package/dist/snapka-BTlnZOyI.mjs +450 -0
  50. package/dist/sqlite-Dcj9jlW9.mjs +307 -0
  51. package/dist/start/app.d.ts +1 -1
  52. package/dist/start/app.mjs +14 -7
  53. package/dist/start/index.d.ts +1 -1
  54. package/dist/start/index.mjs +325 -656
  55. package/dist/template-Djk6y0uC.mjs +133 -0
  56. package/dist/terminalManager-Lxa8Sm06.mjs +783 -0
  57. package/dist/uptime-C121X_rq.mjs +210 -0
  58. package/dist/web/{CompressaPRO-GX.woff2.br → CompressaPRO-GX.woff2} +0 -0
  59. package/dist/web/assets/css/style-CBB8wM_W.css +14880 -0
  60. package/dist/web/assets/js/entry-Blf4Trpx.js +258540 -0
  61. package/dist/web/{googleapis.woff2.br → googleapis.woff2} +0 -0
  62. package/dist/web/index.html +2 -15
  63. package/dist/web/karin.png +0 -0
  64. package/dist/web/sha256.min.js +9 -0
  65. package/dist/ws-BLDoC2gV.mjs +80 -0
  66. package/dist/ws-CcoWd3Ar.mjs +106 -0
  67. package/package.json +7 -7
  68. package/dist/global.d.d.ts +0 -68
  69. package/dist/types-hAhbXJDZ.d.ts +0 -109
  70. package/dist/web/assets/css/components-ep7vm38G.css +0 -1
  71. package/dist/web/assets/css/index-Dadvd9mn.css.br +0 -0
  72. package/dist/web/assets/css/vendor-editor-CFbL2ovg.css.br +0 -0
  73. package/dist/web/assets/css/vendor-others-ZgkIHsf0.css +0 -1
  74. package/dist/web/assets/js/components-CU2xw4lY.js.br +0 -0
  75. package/dist/web/assets/js/entry-Dvb7eYLE.js.br +0 -0
  76. package/dist/web/assets/js/hooks-CRfhs4ON.js.br +0 -0
  77. package/dist/web/assets/js/page-404.tsx-DYMd_RI_.js +0 -1
  78. package/dist/web/assets/js/page-dashboard-CG60V_Z-.js.br +0 -0
  79. package/dist/web/assets/js/page-loading.tsx-wY8a9me3.js.br +0 -0
  80. package/dist/web/assets/js/page-login.tsx-B54ZOEZB.js.br +0 -0
  81. package/dist/web/assets/js/utils-C9nWTSuo.js +0 -2
  82. package/dist/web/assets/js/vendor-editor-BmqYP7lh.js.br +0 -0
  83. package/dist/web/assets/js/vendor-heroui-ClBCy2zk.js.br +0 -0
  84. package/dist/web/assets/js/vendor-others-6GiMrjd4.js.br +0 -0
  85. package/dist/web/assets/js/vendor-react-Dc9jdQiK.js.br +0 -0
  86. package/dist/web/assets/js/vendor-ui-utils-D0xkboLL.js.br +0 -0
  87. package/dist/web/assets/js/vendor-visual-saF8KLH_.js.br +0 -0
  88. package/dist/web/karin.png.br +0 -0
  89. package/dist/web/sha256.min.js.br +0 -0
@@ -0,0 +1,133 @@
1
+ import { t as __exportAll } from "./chunk-NzVPYdc1.mjs";
2
+ import { htmlPath } from "./root.mjs";
3
+ import { a as mkdirSync } from "./fsSync-Cf5MWILk.mjs";
4
+ import { l as getAllFiles } from "./file-dGy9of8-.mjs";
5
+ import path from "node:path";
6
+ import fs from "node:fs";
7
+ import crypto from "node:crypto";
8
+ import schedule from "node-schedule";
9
+ import template from "art-template";
10
+
11
+ //#region src/adapter/render/admin/template.ts
12
+ var template_exports = /* @__PURE__ */ __exportAll({
13
+ renderTemplate: () => renderTemplate,
14
+ renderTpl: () => renderTpl,
15
+ startCleanExpiredFiles: () => startCleanExpiredFiles
16
+ });
17
+ /**
18
+ * @description 处理模板
19
+ * @param options 截图参数
20
+ * @deprecated 请使用`renderTemplate`
21
+ */
22
+ const renderTpl = (options) => {
23
+ if (typeof options.file !== "string") throw TypeError("模板文件路径必须为字符串");
24
+ if (!options.name) options.name = path.basename(options.file) || "render";
25
+ /** 渲染模板数据 */
26
+ if (options.data) {
27
+ /** 他喵的 不会真的有笨比传个http吧... */
28
+ if (options.file.startsWith("http")) throw TypeError("他喵的 不会真的有笨比传个http来当做模板吧...");
29
+ const file = path.resolve(options.file);
30
+ const tplData = fs.readFileSync(file, "utf-8");
31
+ const renderData = template.render(tplData, options.data);
32
+ /** 保存文件的绝对路径 */
33
+ const outputPath = getOutputPath(options.file, renderData, options.name);
34
+ fs.writeFileSync(outputPath, renderData);
35
+ delete options.data;
36
+ options.file = `file://${outputPath}`;
37
+ return options;
38
+ }
39
+ if (!options.file.startsWith("http") && !options.file.startsWith("file")) options.file = `file://${path.resolve(options.file)}`;
40
+ delete options.data;
41
+ return options;
42
+ };
43
+ /**
44
+ * @description 处理模板
45
+ * @param options 截图参数
46
+ */
47
+ const renderTemplate = (options) => {
48
+ if (typeof options.file !== "string") throw TypeError("模板文件路径必须为字符串");
49
+ if ("name" in options) {
50
+ options.file_name = options.name;
51
+ delete options.name;
52
+ }
53
+ if (!options.file_name) options.file_name = path.basename(options.file) || "render";
54
+ /** 渲染模板数据 */
55
+ if (options.data) {
56
+ /** 他喵的 不会真的有笨比传个http吧... */
57
+ if (options.file.startsWith("http")) throw TypeError("他喵的 不会真的有笨比传个http来当做模板吧...");
58
+ const file = path.resolve(options.file);
59
+ const tplData = fs.readFileSync(file, "utf-8");
60
+ const renderData = template.render(tplData, options.data);
61
+ /** 保存文件的绝对路径 */
62
+ const outputPath = getOutputPath(options.file, renderData, options.file_name);
63
+ fs.writeFileSync(outputPath, renderData);
64
+ delete options.data;
65
+ options.file = `file://${outputPath}`;
66
+ return options;
67
+ }
68
+ if (!options.file.startsWith("http") && !options.file.startsWith("file")) options.file = `file://${path.resolve(options.file)}`;
69
+ delete options.data;
70
+ return options;
71
+ };
72
+ /**
73
+ * 生成渲染模板后保存的文件路径并保存模板
74
+ * @param file 模板文件路径
75
+ * @param data 模板数据
76
+ * @param name 保存文件的目录名称
77
+ */
78
+ const getOutputPath = (file, data, name) => {
79
+ /** 后缀 */
80
+ const extname = path.extname(file);
81
+ /** 文件名称 不含后缀 */
82
+ const basename = path.basename(file, extname);
83
+ /** 保存文件的目录 */
84
+ const fileDir = path.join(htmlPath, name || "render");
85
+ mkdirSync(fileDir);
86
+ /** 内容哈希 */
87
+ const contentHash = crypto.createHash("md5").update(data).digest("hex").substring(0, 8);
88
+ const filePath = path.join(fileDir, `${basename}-${contentHash}${extname}`);
89
+ /** 如果文件已存在 则更新文件的修改时间 */
90
+ if (fs.existsSync(filePath)) {
91
+ const now = /* @__PURE__ */ new Date();
92
+ try {
93
+ fs.utimesSync(filePath, now, now);
94
+ } catch (err) {
95
+ logger.error(`[文件更新] 更新文件时出错: ${filePath}, ${err}`);
96
+ }
97
+ return filePath;
98
+ }
99
+ fs.writeFileSync(filePath, data);
100
+ return filePath;
101
+ };
102
+ /**
103
+ * 清理过期文件
104
+ * 删除修改时间超过10分钟的HTML文件
105
+ */
106
+ const cleanExpiredFiles = async () => {
107
+ let count = 0;
108
+ const now = Date.now();
109
+ const files = await getAllFiles(htmlPath, {
110
+ suffixs: [".html"],
111
+ returnType: "abs"
112
+ });
113
+ if (files.length === 0) return;
114
+ const EXPIRE_TIME = 600 * 1e3;
115
+ for (const file of files) try {
116
+ if (now - (await fs.promises.stat(file)).mtimeMs > EXPIRE_TIME) {
117
+ await fs.promises.unlink(file);
118
+ count++;
119
+ }
120
+ } catch (err) {
121
+ logger.error(`[文件清理] 处理文件时出错: ${file}, ${err}`);
122
+ }
123
+ logger.mark(`[文件清理] 清理HTML完成: ${count}/${files.length}`);
124
+ };
125
+ /**
126
+ * 定时清理过期的html文件
127
+ */
128
+ const startCleanExpiredFiles = () => {
129
+ schedule.scheduleJob(process.env.CLEAN_HTML_CRON || "*/10 * * * *", cleanExpiredFiles);
130
+ };
131
+
132
+ //#endregion
133
+ export { renderTpl as n, template_exports as r, renderTemplate as t };