@whyour/qinglong 2.21.0-8 → 2.22.0

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 (265) hide show
  1. package/.dockerignore +13 -0
  2. package/.env.example +7 -0
  3. package/AGENTS.md +2 -2
  4. package/README-en.md +24 -0
  5. package/README.md +24 -0
  6. package/back/protos/api.proto +6 -1
  7. package/back/protos/cron.proto +4 -1
  8. package/docker/Dockerfile +31 -12
  9. package/docker/Dockerfile.310 +31 -12
  10. package/docker/Dockerfile.debian +22 -14
  11. package/docker/Dockerfile.debian310 +24 -14
  12. package/docker/build-manifest.cjs +28 -0
  13. package/docker/verify-build.cjs +49 -0
  14. package/docs/releases/2.22.0-validation.md +49 -0
  15. package/docs/releases/2.22.0.md +54 -0
  16. package/ecosystem.config.js +10 -1
  17. package/package.json +11 -6
  18. package/sample/config.sample.sh +10 -0
  19. package/sample/notify.js +54 -0
  20. package/sample/notify.py +37 -0
  21. package/scripts/benchmark-execution.cjs +96 -0
  22. package/scripts/write-build-info.cjs +27 -0
  23. package/shell/api.sh +34 -13
  24. package/shell/check.sh +59 -19
  25. package/shell/lang/en.sh +6 -0
  26. package/shell/lang/zh.sh +6 -0
  27. package/shell/node_path_cache.sh +128 -0
  28. package/shell/otask.sh +7 -1
  29. package/shell/preload/sitecustomize.js +5 -1
  30. package/shell/share.sh +25 -8
  31. package/shell/start.sh +6 -3
  32. package/shell/task.sh +13 -3
  33. package/shell/update.sh +65 -4
  34. package/static/build/api/clientIp.js +42 -0
  35. package/static/build/api/config.js +8 -16
  36. package/static/build/api/cron.js +38 -2
  37. package/static/build/api/dashboard.js +37 -0
  38. package/static/build/api/health.js +2 -2
  39. package/static/build/api/index.js +4 -0
  40. package/static/build/api/log.js +30 -19
  41. package/static/build/api/retention.js +63 -0
  42. package/static/build/api/script.js +23 -22
  43. package/static/build/api/subscription.js +16 -2
  44. package/static/build/api/system.js +25 -2
  45. package/static/build/api/user.js +75 -15
  46. package/static/build/app.js +54 -45
  47. package/static/build/bootstrap/database.js +51 -0
  48. package/static/build/config/const.js +1 -0
  49. package/static/build/config/share.js +5 -4
  50. package/static/build/config/util.js +133 -38
  51. package/static/build/data/cron.js +1 -0
  52. package/static/build/data/notify.js +11 -1
  53. package/static/build/loaders/app.js +2 -0
  54. package/static/build/loaders/db.js +3 -33
  55. package/static/build/loaders/deps.js +29 -0
  56. package/static/build/loaders/express.js +30 -21
  57. package/static/build/loaders/initData.js +10 -7
  58. package/static/build/loaders/sock.js +72 -6
  59. package/static/build/middlewares/monitoring.js +12 -33
  60. package/static/build/middlewares/protectedPathCase.js +17 -0
  61. package/static/build/protos/api.js +56 -2
  62. package/static/build/protos/cron.js +21 -4
  63. package/static/build/protos/health.js +1 -1
  64. package/static/build/schedule/addCron.js +9 -0
  65. package/static/build/schedule/api.js +5 -2
  66. package/static/build/schedule/client.js +38 -6
  67. package/static/build/schedule/health.js +72 -7
  68. package/static/build/services/config.js +5 -42
  69. package/static/build/services/cron.js +338 -199
  70. package/static/build/services/dependence.js +47 -0
  71. package/static/build/services/grpc.js +1 -1
  72. package/static/build/services/health.js +4 -7
  73. package/static/build/services/http.js +8 -2
  74. package/static/build/services/log.js +2 -3
  75. package/static/build/services/metrics.js +46 -14
  76. package/static/build/services/notify.js +26 -0
  77. package/static/build/services/retention.js +123 -0
  78. package/static/build/services/schedule.js +57 -33
  79. package/static/build/services/script.js +4 -5
  80. package/static/build/services/subscription.js +55 -34
  81. package/static/build/services/system.js +37 -9
  82. package/static/build/services/user.js +213 -25
  83. package/static/build/shared/auth.js +18 -5
  84. package/static/build/shared/authMutation.js +17 -0
  85. package/static/build/shared/childProcess.js +82 -0
  86. package/static/build/shared/clientIp.js +27 -0
  87. package/static/build/shared/errors.js +9 -0
  88. package/static/build/shared/fileAccess.js +60 -0
  89. package/static/build/shared/i18n.js +12 -5
  90. package/static/build/shared/logReader.js +85 -0
  91. package/static/build/shared/logStreamManager.js +80 -60
  92. package/static/build/shared/password.js +30 -0
  93. package/static/build/shared/retention.js +58 -0
  94. package/static/build/shared/runCron.js +28 -15
  95. package/static/build/shared/schedulerMutationLock.js +44 -0
  96. package/static/build/shared/schedulerReadiness.js +82 -0
  97. package/static/build/shared/schemaMigrations.js +58 -0
  98. package/static/build/shared/startupProcess.js +48 -0
  99. package/static/build/shared/store.js +7 -0
  100. package/static/build/shared/trustProxy.js +119 -0
  101. package/static/build/validation/schedule.js +3 -3
  102. package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
  103. package/static/dist/2031.6af40025.async.js +1 -0
  104. package/static/dist/2693.51c2636b.async.js +1 -0
  105. package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
  106. package/static/dist/2901.2ca95295.async.js +1 -0
  107. package/static/dist/445.a65ff63b.async.js +1 -0
  108. package/static/dist/4736.1d2b5cb6.async.js +1 -0
  109. package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
  110. package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
  111. package/static/dist/6212.9e6d9913.async.js +1 -0
  112. package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
  113. package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
  114. package/static/dist/7231.f7e5b668.async.js +1 -0
  115. package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
  116. package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
  117. package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
  118. package/static/dist/8844.a0fef08e.async.js +1 -0
  119. package/static/dist/index.html +2 -2
  120. package/static/dist/layouts__index.633d3553.async.js +1 -0
  121. package/static/dist/preload_helper.cf7de3fa.js +1 -0
  122. package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
  123. package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
  124. package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
  125. package/static/dist/{src__pages__crontab__logModal.831d5e4b.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
  126. package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
  127. package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
  128. package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
  129. package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
  130. package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
  131. package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
  132. package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
  133. package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
  134. package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
  135. package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
  136. package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
  137. package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
  138. package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
  139. package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
  140. package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
  141. package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
  142. package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
  143. package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
  144. package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
  145. package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
  146. package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
  147. package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
  148. package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
  149. package/static/dist/{src__pages__setting__checkUpdate.34d773f2.async.js → src__pages__setting__checkUpdate.d175b154.async.js} +1 -1
  150. package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
  151. package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
  152. package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
  153. package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
  154. package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
  155. package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
  156. package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
  157. package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
  158. package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
  159. package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
  160. package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
  161. package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
  162. package/static/dist/{umi.a54a59f6.js → umi.fc019050.js} +1 -1
  163. package/test/back/auth-security.test.cjs +74 -0
  164. package/test/back/build-provenance.test.cjs +150 -0
  165. package/test/back/cron-log-name.test.cjs +110 -0
  166. package/test/back/cron-validation.test.cjs +45 -0
  167. package/test/back/dashboard-failures.test.cjs +173 -0
  168. package/test/back/database-bootstrap.test.cjs +193 -0
  169. package/test/back/dependence-cache-status.test.cjs +125 -0
  170. package/test/back/deprecated-file-routes.test.cjs +82 -0
  171. package/test/back/ecosystem.test.cjs +28 -0
  172. package/test/back/env-name-parsing.test.cjs +96 -0
  173. package/test/back/execution-lifecycle.test.cjs +236 -0
  174. package/test/back/file-access-security.test.cjs +47 -0
  175. package/test/back/fileTreeListing.test.cjs +57 -0
  176. package/test/back/grpc-cron-response.test.cjs +60 -0
  177. package/test/back/http-exclusive-listen.test.cjs +31 -0
  178. package/test/back/http-security.test.cjs +213 -0
  179. package/test/back/listen-security.test.cjs +67 -0
  180. package/test/back/log-path-security.test.cjs +158 -0
  181. package/test/back/logReader.test.cjs +72 -0
  182. package/test/back/manual-execution.test.cjs +85 -0
  183. package/test/back/manual-stop-claim.test.cjs +220 -0
  184. package/test/back/metrics.test.cjs +34 -0
  185. package/test/back/monitoring.test.cjs +73 -0
  186. package/test/back/node-path-cache.test.cjs +173 -0
  187. package/test/back/node-path-lock.test.cjs +178 -0
  188. package/test/back/npm-publication.test.cjs +70 -0
  189. package/test/back/primary-apm.test.cjs +24 -0
  190. package/test/back/process-exit-state.test.cjs +81 -0
  191. package/test/back/process-stop-signal.test.cjs +77 -0
  192. package/test/back/protected-path-case.test.cjs +58 -0
  193. package/test/back/qlServiceLogCommand.test.cjs +128 -0
  194. package/test/back/retention.test.cjs +131 -0
  195. package/test/back/role-loading.test.cjs +118 -0
  196. package/test/back/schedule-health.test.cjs +86 -0
  197. package/test/back/scheduler-file-lock.test.cjs +51 -0
  198. package/test/back/scheduler-mutation.test.cjs +312 -0
  199. package/test/back/scheduler-readiness.test.cjs +85 -0
  200. package/test/back/scheduler-reconciliation.test.cjs +152 -0
  201. package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
  202. package/test/back/schema-migrations.test.cjs +127 -0
  203. package/test/back/shell-api-parsing.test.cjs +184 -0
  204. package/test/back/sock-polling.test.cjs +297 -0
  205. package/test/back/sock-security.test.cjs +72 -0
  206. package/test/back/start-env-preservation.test.cjs +53 -0
  207. package/test/back/stop-failure-feedback.test.cjs +158 -0
  208. package/test/back/stop-race.test.cjs +167 -0
  209. package/test/back/subscription-cleanup.test.cjs +53 -0
  210. package/test/back/subscription-stop-state.test.cjs +66 -0
  211. package/test/back/system-dependence-cache.test.cjs +126 -0
  212. package/test/back/task-time.test.cjs +116 -0
  213. package/test/back/user-api.test.cjs +99 -0
  214. package/test/back/user-security.test.cjs +248 -0
  215. package/test/back/worker-apm.test.cjs +84 -0
  216. package/test/back/wpush-grpc.test.cjs +115 -0
  217. package/test/front/cron-log-pagination.test.cjs +214 -0
  218. package/test/front/http-auth.test.cjs +152 -0
  219. package/test/front/http-error.test.cjs +29 -0
  220. package/test/helpers/load-security-module.cjs +42 -0
  221. package/version.yaml +19 -34
  222. package/CLAUDE.md +0 -43
  223. package/static/dist/1147.62793604.async.js +0 -1
  224. package/static/dist/134.54df9e38.async.js +0 -1
  225. package/static/dist/2208.85285476.async.js +0 -1
  226. package/static/dist/2286.f371c743.async.js +0 -1
  227. package/static/dist/3191.545ab873.async.js +0 -1
  228. package/static/dist/4902.555f92ab.async.js +0 -1
  229. package/static/dist/5520.ff2cfd6b.async.js +0 -1
  230. package/static/dist/6431.c50479be.async.js +0 -1
  231. package/static/dist/8826.db34ad8d.async.js +0 -1
  232. package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
  233. package/static/dist/preload_helper.3048fe5b.js +0 -1
  234. package/static/dist/src__pages__crontab__detail.b98f0084.async.js +0 -1
  235. package/static/dist/src__pages__crontab__index.68e78a33.async.js +0 -1
  236. package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
  237. package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
  238. package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
  239. package/static/dist/src__pages__dashboard__index.58177357.async.js +0 -1
  240. package/static/dist/src__pages__dependence__index.b7bbc795.async.js +0 -1
  241. package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
  242. package/static/dist/src__pages__dependence__modal.f7bb47ba.async.js +0 -1
  243. package/static/dist/src__pages__env__editNameModal.48715576.async.js +0 -1
  244. package/static/dist/src__pages__env__index.452cdc47.async.js +0 -1
  245. package/static/dist/src__pages__env__modal.e1234834.async.js +0 -1
  246. package/static/dist/src__pages__error__index.dedb2b90.async.js +0 -1
  247. package/static/dist/src__pages__initialization__index.22620a77.async.js +0 -1
  248. package/static/dist/src__pages__log__index.9c66639f.async.js +0 -1
  249. package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
  250. package/static/dist/src__pages__script__editNameModal.532a3044.async.js +0 -1
  251. package/static/dist/src__pages__script__index.1fc20f22.async.js +0 -1
  252. package/static/dist/src__pages__script__renameModal.5cdde919.async.js +0 -1
  253. package/static/dist/src__pages__script__saveModal.5ffed35f.async.js +0 -1
  254. package/static/dist/src__pages__script__setting.1a82c6d7.async.js +0 -1
  255. package/static/dist/src__pages__setting__appModal.43b7758a.async.js +0 -1
  256. package/static/dist/src__pages__setting__dependence.9c04c79a.async.js +0 -1
  257. package/static/dist/src__pages__setting__index.7e070838.async.js +0 -1
  258. package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
  259. package/static/dist/src__pages__setting__notification.bac481c2.async.js +0 -1
  260. package/static/dist/src__pages__setting__other.707cfafe.async.js +0 -1
  261. package/static/dist/src__pages__setting__security.b7235753.async.js +0 -1
  262. package/static/dist/src__pages__setting__systemLog.b81a8c1d.async.js +0 -1
  263. package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
  264. package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
  265. package/static/dist/src__pages__subscription__modal.562448e2.async.js +0 -1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRandomString = void 0;
4
+ const crypto_1 = require("crypto");
4
5
  function createRandomString(min, max) {
5
6
  const num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
6
7
  const english = [
@@ -66,16 +67,16 @@ function createRandomString(min, max) {
66
67
  arr.push(getOne(english));
67
68
  arr.push(getOne(ENGLISH));
68
69
  arr.push(getOne(special));
69
- const len = min + Math.floor(Math.random() * (max - min + 1));
70
+ const len = min + (0, crypto_1.randomInt)(max - min + 1);
70
71
  for (let i = 4; i < len; i++) {
71
- arr.push(config[Math.floor(Math.random() * config.length)]);
72
+ arr.push(config[(0, crypto_1.randomInt)(config.length)]);
72
73
  }
73
74
  const newArr = [];
74
75
  for (let j = 0; j < len; j++) {
75
- newArr.push(arr.splice(Math.random() * arr.length, 1)[0]);
76
+ newArr.push(arr.splice((0, crypto_1.randomInt)(arr.length), 1)[0]);
76
77
  }
77
78
  function getOne(arr) {
78
- return arr[Math.floor(Math.random() * arr.length)];
79
+ return arr[(0, crypto_1.randomInt)(arr.length)];
79
80
  }
80
81
  return newArr.join('');
81
82
  }
@@ -29,7 +29,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.updateLinuxMirrorFile = exports.detectOS = exports.isDemoEnv = exports.getUninstallCommand = exports.getInstallCommand = exports.getGetCommand = exports.setSystemTimezone = exports.rmPath = exports.safeJSONParse = exports.getUniqPath = exports.parseContentVersion = exports.parseVersion = exports.killAllTasks = exports.getAllPids = exports.getPid = exports.killTask = exports.psTree = exports.parseBody = exports.parseHeaders = exports.promiseExecSuccess = exports.promiseExec = exports.readDir = exports.readDirs = exports.dirSort = exports.concurrentRun = exports.handleLogPath = exports.createFile = exports.fileExist = exports.getPlatform = exports.getToken = exports.getLastModifyFilePath = exports.removeAnsi = exports.getFileContentByName = void 0;
32
+ exports.updateLinuxMirrorFile = exports.detectOS = exports.isDemoEnv = exports.getUninstallCommand = exports.getInstallCommand = exports.getGetCommand = exports.setSystemTimezone = exports.rmPath = exports.errStack = exports.safeJSONParse = exports.getUniqPath = exports.parseContentVersion = exports.parseVersion = exports.killAllTasks = exports.getAllPids = exports.getPid = exports.killTask = exports.psTree = exports.parseBody = exports.parseHeaders = exports.promiseExecSuccess = exports.promiseExec = exports.readDir = exports.readDirs = exports.dirSort = exports.concurrentRun = exports.handleLogPath = exports.createFile = exports.fileExist = exports.getPlatform = exports.getToken = exports.getLastModifyFilePath = exports.removeAnsi = exports.getFileContentByName = void 0;
33
33
  const fs = __importStar(require("fs/promises"));
34
34
  const path = __importStar(require("path"));
35
35
  const child_process_1 = require("child_process");
@@ -44,6 +44,7 @@ const dependence_1 = require("../data/dependence");
44
44
  const undici_1 = require("undici");
45
45
  const os_1 = __importDefault(require("os"));
46
46
  const container_1 = require("./container");
47
+ const fileAccess_1 = require("../shared/fileAccess");
47
48
  __exportStar(require("./share"), exports);
48
49
  let osType;
49
50
  function getOsTypeSync() {
@@ -172,7 +173,9 @@ async function createFile(file, data = '') {
172
173
  }
173
174
  exports.createFile = createFile;
174
175
  async function handleLogPath(logPath, data = '') {
175
- const absolutePath = path.resolve(index_1.default.logPath, logPath);
176
+ const absolutePath = (0, fileAccess_1.resolveFileAccess)(index_1.default.logPath, [logPath]);
177
+ if (!absolutePath)
178
+ throw new Error('Log path is outside the log directory');
176
179
  const logFileExist = await fileExist(absolutePath);
177
180
  if (!logFileExist) {
178
181
  await createFile(absolutePath, data);
@@ -226,40 +229,66 @@ function dirSort(a, b) {
226
229
  }
227
230
  }
228
231
  exports.dirSort = dirSort;
229
- async function readDirs(dir, baseDir = '', blacklist = [], sort = dirSort) {
232
+ const FILE_SYSTEM_READ_CONCURRENCY = 32;
233
+ function createFileSystemTaskRunner(concurrency) {
234
+ let activeCount = 0;
235
+ const queue = [];
236
+ const runNext = () => {
237
+ var _a;
238
+ while (activeCount < concurrency && queue.length > 0) {
239
+ activeCount += 1;
240
+ (_a = queue.shift()) === null || _a === void 0 ? void 0 : _a();
241
+ }
242
+ };
243
+ return (task) => new Promise((resolve, reject) => {
244
+ queue.push(() => {
245
+ task()
246
+ .then(resolve, reject)
247
+ .finally(() => {
248
+ activeCount -= 1;
249
+ runNext();
250
+ });
251
+ });
252
+ runNext();
253
+ });
254
+ }
255
+ async function readDirsWithRunner(dir, baseDir, blacklist, sort, runFileSystemTask) {
230
256
  const relativePath = path.relative(baseDir, dir);
231
- const files = await fs.readdir(dir);
232
- const result = [];
233
- for (const file of files) {
234
- const subPath = path.join(dir, file);
235
- const stats = await fs.lstat(subPath);
236
- const key = path.join(relativePath, file);
237
- if (blacklist.includes(file) || stats.isSymbolicLink()) {
238
- continue;
257
+ const entries = await runFileSystemTask(() => fs.readdir(dir, { withFileTypes: true }));
258
+ const items = await Promise.all(entries.map(async (entry) => {
259
+ if (blacklist.includes(entry.name) || entry.isSymbolicLink()) {
260
+ return undefined;
261
+ }
262
+ const subPath = path.join(dir, entry.name);
263
+ const stats = await runFileSystemTask(() => fs.lstat(subPath));
264
+ if (stats.isSymbolicLink()) {
265
+ return undefined;
239
266
  }
267
+ const key = path.join(relativePath, entry.name);
240
268
  if (stats.isDirectory()) {
241
- const children = await readDirs(subPath, baseDir, blacklist, sort);
242
- result.push({
243
- title: file,
269
+ const children = await readDirsWithRunner(subPath, baseDir, blacklist, sort, runFileSystemTask);
270
+ return {
271
+ title: entry.name,
244
272
  key,
245
273
  type: 'directory',
246
274
  parent: relativePath,
247
275
  createTime: stats.birthtime.getTime(),
248
- children: children.sort(sort),
249
- });
276
+ children,
277
+ };
250
278
  }
251
- else {
252
- result.push({
253
- title: file,
254
- type: 'file',
255
- key,
256
- parent: relativePath,
257
- size: stats.size,
258
- createTime: stats.birthtime.getTime(),
259
- });
260
- }
261
- }
262
- return result.sort(sort);
279
+ return {
280
+ title: entry.name,
281
+ type: 'file',
282
+ key,
283
+ parent: relativePath,
284
+ size: stats.size,
285
+ createTime: stats.birthtime.getTime(),
286
+ };
287
+ }));
288
+ return items.filter((item) => Boolean(item)).sort(sort);
289
+ }
290
+ async function readDirs(dir, baseDir = '', blacklist = [], sort = dirSort) {
291
+ return readDirsWithRunner(dir, baseDir, blacklist, sort, createFileSystemTaskRunner(FILE_SYSTEM_READ_CONCURRENCY));
263
292
  }
264
293
  exports.readDirs = readDirs;
265
294
  async function readDir(dir, baseDir = '', blacklist = []) {
@@ -407,19 +436,83 @@ function psTree(pid) {
407
436
  });
408
437
  }
409
438
  exports.psTree = psTree;
410
- async function killTask(pid) {
411
- const pids = await psTree(pid);
412
- if (pids.length) {
439
+ async function killTask(pid, waitForExit = false) {
440
+ const descendants = await psTree(pid);
441
+ const signal = (target, sig) => {
413
442
  try {
414
- [pid, ...pids].reverse().forEach((x) => {
415
- process.kill(x, 15);
416
- });
443
+ process.kill(target, sig);
417
444
  }
418
- catch (error) { }
419
- }
420
- else {
421
- process.kill(pid, 2);
445
+ catch (error) {
446
+ if (error.code !== 'ESRCH')
447
+ throw error;
448
+ }
449
+ };
450
+ if (!waitForExit) {
451
+ if (descendants.length) {
452
+ // A child may exit after psTree; keep signalling the remaining tree.
453
+ for (const target of [pid, ...descendants].reverse()) {
454
+ signal(target, 'SIGTERM');
455
+ }
456
+ }
457
+ else
458
+ signal(pid, 'SIGINT');
459
+ return;
422
460
  }
461
+ const pids = [...descendants.reverse(), pid];
462
+ for (const target of pids)
463
+ signal(target, 'SIGTERM');
464
+ const alive = async (target) => {
465
+ try {
466
+ process.kill(target, 0);
467
+ }
468
+ catch (error) {
469
+ if (error.code === 'ESRCH')
470
+ return false;
471
+ throw error;
472
+ }
473
+ if (process.platform === 'linux') {
474
+ try {
475
+ const stat = await fs.readFile(`/proc/${target}/stat`, 'utf8');
476
+ // The command field may contain spaces and parentheses. Zombies have
477
+ // exited even while their parent has not reaped the PID yet.
478
+ const state = stat.slice(stat.lastIndexOf(')') + 2).split(' ')[0];
479
+ if (['Z', 'X', 'x'].includes(state))
480
+ return false;
481
+ }
482
+ catch (_a) {
483
+ // /proc may be unavailable, or the process may have just exited.
484
+ // Retain the portable signal probe rather than assuming it is dead.
485
+ try {
486
+ process.kill(target, 0);
487
+ }
488
+ catch (error) {
489
+ if (error.code === 'ESRCH')
490
+ return false;
491
+ throw error;
492
+ }
493
+ }
494
+ }
495
+ return true;
496
+ };
497
+ const wait = async () => {
498
+ const deadline = Date.now() + 1000;
499
+ let remaining = pids;
500
+ while (true) {
501
+ const states = await Promise.all(remaining.map(alive));
502
+ remaining = remaining.filter((_, index) => states[index]);
503
+ if (!remaining.length || Date.now() >= deadline)
504
+ return remaining;
505
+ await new Promise((resolve) => setTimeout(resolve, 20));
506
+ }
507
+ };
508
+ let remaining = await wait();
509
+ if (!remaining.length)
510
+ return;
511
+ for (const target of remaining)
512
+ signal(target, 'SIGKILL');
513
+ remaining = await wait();
514
+ if (remaining.length)
515
+ throw new Error(`Task processes did not exit: ${remaining.join(', ')}`);
423
516
  }
424
517
  exports.killTask = killTask;
425
518
  async function getPid(cmd) {
@@ -503,6 +596,8 @@ function safeJSONParse(value) {
503
596
  }
504
597
  }
505
598
  exports.safeJSONParse = safeJSONParse;
599
+ var errors_1 = require("../shared/errors");
600
+ Object.defineProperty(exports, "errStack", { enumerable: true, get: function () { return errors_1.errStack; } });
506
601
  async function rmPath(path) {
507
602
  try {
508
603
  const _exsit = await fileExist(path);
@@ -61,6 +61,7 @@ exports.CrontabModel = _1.sequelize.define('Crontab', {
61
61
  isDisabled: sequelize_1.DataTypes.NUMBER,
62
62
  isPinned: sequelize_1.DataTypes.NUMBER,
63
63
  log_path: sequelize_1.DataTypes.STRING,
64
+ queued_token: sequelize_1.DataTypes.STRING,
64
65
  labels: sequelize_1.DataTypes.JSON,
65
66
  last_running_time: sequelize_1.DataTypes.NUMBER,
66
67
  last_execution_time: sequelize_1.DataTypes.NUMBER,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpeniLinkNotification = exports.WxPusherSptNotification = exports.WxPusherBotNotification = exports.NtfyNotification = exports.LarkNotification = exports.WebhookNotification = exports.ChronocatNotification = exports.PushMeNotification = exports.EmailNotification = exports.WePlusBotNotification = exports.PushPlusNotification = exports.IGotNotification = exports.AibotkNotification = exports.WeWorkAppNotification = exports.WeWorkBotNotification = exports.DingtalkBotNotification = exports.TelegramBotNotification = exports.BarkNotification = exports.synologyChatNotification = exports.PushDeerNotification = exports.ServerChanNotification = exports.GoCqHttpBotNotification = exports.GotifyNotification = exports.NotificationMode = void 0;
3
+ exports.WpushNotification = exports.OpeniLinkNotification = exports.WxPusherSptNotification = exports.WxPusherBotNotification = exports.NtfyNotification = exports.LarkNotification = exports.WebhookNotification = exports.ChronocatNotification = exports.PushMeNotification = exports.EmailNotification = exports.WePlusBotNotification = exports.PushPlusNotification = exports.IGotNotification = exports.AibotkNotification = exports.WeWorkAppNotification = exports.WeWorkBotNotification = exports.DingtalkBotNotification = exports.TelegramBotNotification = exports.BarkNotification = exports.synologyChatNotification = exports.PushDeerNotification = exports.ServerChanNotification = exports.GoCqHttpBotNotification = exports.GotifyNotification = exports.NotificationMode = void 0;
4
4
  var NotificationMode;
5
5
  (function (NotificationMode) {
6
6
  NotificationMode["gotify"] = "gotify";
@@ -25,6 +25,7 @@ var NotificationMode;
25
25
  NotificationMode["ntfy"] = "ntfy";
26
26
  NotificationMode["wxPusherBot"] = "wxPusherBot";
27
27
  NotificationMode["openiLink"] = "openiLink";
28
+ NotificationMode["wpush"] = "wpush";
28
29
  })(NotificationMode || (exports.NotificationMode = NotificationMode = {}));
29
30
  class NotificationBaseInfo {
30
31
  }
@@ -239,4 +240,13 @@ class OpeniLinkNotification extends NotificationBaseInfo {
239
240
  }
240
241
  }
241
242
  exports.OpeniLinkNotification = OpeniLinkNotification;
243
+ class WpushNotification extends NotificationBaseInfo {
244
+ constructor() {
245
+ super(...arguments);
246
+ this.wpushApiKey = '';
247
+ this.wpushChannel = '';
248
+ this.wpushTopicCode = '';
249
+ }
250
+ }
251
+ exports.WpushNotification = WpushNotification;
242
252
  //# sourceMappingURL=notify.js.map
@@ -10,6 +10,7 @@ const initData_1 = __importDefault(require("./initData"));
10
10
  const deps_1 = __importDefault(require("./deps"));
11
11
  const initTask_1 = __importDefault(require("./initTask"));
12
12
  const initFile_1 = __importDefault(require("./initFile"));
13
+ const trustProxy_1 = require("../shared/trustProxy");
13
14
  exports.default = async ({ app }) => {
14
15
  (0, depInjector_1.default)();
15
16
  logger_1.default.info('[boot] Dependency loaded');
@@ -22,6 +23,7 @@ exports.default = async ({ app }) => {
22
23
  (0, initTask_1.default)();
23
24
  logger_1.default.info('[boot] Init task loaded');
24
25
  (0, express_1.default)({ app });
26
+ await (0, trustProxy_1.initializeTrustProxy)(app);
25
27
  logger_1.default.info('[boot] Express loaded');
26
28
  };
27
29
  //# sourceMappingURL=app.js.map
@@ -14,6 +14,7 @@ const cronView_1 = require("../data/cronView");
14
14
  const cronStats_1 = require("../data/cronStats");
15
15
  const runningInstance_1 = require("../data/runningInstance");
16
16
  const data_1 = require("../data");
17
+ const schemaMigrations_1 = require("../shared/schemaMigrations");
17
18
  exports.default = async () => {
18
19
  try {
19
20
  await cron_1.CrontabModel.sync();
@@ -25,43 +26,12 @@ exports.default = async () => {
25
26
  await cronView_1.CrontabViewModel.sync();
26
27
  await cronStats_1.CrontabStatModel.sync();
27
28
  await runningInstance_1.RunningInstanceModel.sync();
28
- // 初始化新增字段
29
- const migrations = [
30
- {
31
- table: 'CrontabViews',
32
- column: 'filterRelation',
33
- type: 'VARCHAR(255)',
34
- },
35
- { table: 'Subscriptions', column: 'proxy', type: 'VARCHAR(255)' },
36
- { table: 'CrontabViews', column: 'type', type: 'NUMBER' },
37
- { table: 'Subscriptions', column: 'autoAddCron', type: 'NUMBER' },
38
- { table: 'Subscriptions', column: 'autoDelCron', type: 'NUMBER' },
39
- { table: 'Crontabs', column: 'sub_id', type: 'NUMBER' },
40
- { table: 'Crontabs', column: 'extra_schedules', type: 'JSON' },
41
- { table: 'Crontabs', column: 'task_before', type: 'TEXT' },
42
- { table: 'Crontabs', column: 'task_after', type: 'TEXT' },
43
- { table: 'Crontabs', column: 'log_name', type: 'VARCHAR(255)' },
44
- {
45
- table: 'Crontabs',
46
- column: 'allow_multiple_instances',
47
- type: 'NUMBER',
48
- },
49
- { table: 'Crontabs', column: 'work_dir', type: 'VARCHAR(255)' },
50
- { table: 'Envs', column: 'isPinned', type: 'NUMBER' },
51
- { table: 'Envs', column: 'labels', type: 'JSON' },
52
- ];
53
- for (const migration of migrations) {
54
- try {
55
- await data_1.sequelize.query(`alter table ${migration.table} add column ${migration.column} ${migration.type}`);
56
- }
57
- catch (error) {
58
- // Column already exists or other error, continue
59
- }
60
- }
29
+ await (0, schemaMigrations_1.migrateSchema)(data_1.sequelize);
61
30
  logger_1.default.info('[boot] DB loaded');
62
31
  }
63
32
  catch (error) {
64
33
  logger_1.default.error('[boot] DB load failed', error);
34
+ throw error;
65
35
  }
66
36
  };
67
37
  //# sourceMappingURL=db.js.map
@@ -20,6 +20,35 @@ async function linkCommand() {
20
20
  }
21
21
  }
22
22
  async function linkCommandToDir(commandDir) {
23
+ var _a, _b;
24
+ const cliRoot = process.env.QL_CLI_ROOT;
25
+ if (cliRoot) {
26
+ if (!path_1.default.isAbsolute(cliRoot)) {
27
+ throw new Error('QL_CLI_ROOT must be an absolute CLI installation path');
28
+ }
29
+ const { installCliEntrypoints } = require(path_1.default.join(cliRoot, 'dist/local/entrypoints.js'));
30
+ await installCliEntrypoints(commandDir, cliRoot);
31
+ const { installCronEntrypoint } = require(path_1.default.join(cliRoot, 'dist/local/cronEntrypoint.js'));
32
+ await installCronEntrypoint(commandDir, cliRoot, index_1.default.crontabFile, Object.assign(Object.assign({}, process.env), { QL_DIR: index_1.default.rootPath, QL_DATA_DIR: index_1.default.dataPath }));
33
+ // Container-wide legacy links may precede ~/bin. Ensure panel children use
34
+ // the explicitly selected entries without changing system-wide links.
35
+ process.env.PATH = [
36
+ commandDir,
37
+ ...((_b = (_a = process.env.PATH) === null || _a === void 0 ? void 0 : _a.split(path_1.default.delimiter)) !== null && _b !== void 0 ? _b : []).filter((entry) => entry !== commandDir),
38
+ ].join(path_1.default.delimiter);
39
+ return;
40
+ }
41
+ const cronBridge = path_1.default.join(commandDir, 'crontab');
42
+ try {
43
+ if ((await promises_1.default.lstat(cronBridge)).isFile() &&
44
+ (await promises_1.default.readFile(cronBridge, 'utf8')).includes('// QingLong CLI crontab bridge')) {
45
+ await promises_1.default.unlink(cronBridge);
46
+ }
47
+ }
48
+ catch (error) {
49
+ if (error.code !== 'ENOENT')
50
+ throw error;
51
+ }
23
52
  const linkShell = [
24
53
  {
25
54
  src: 'update.sh',
@@ -17,33 +17,43 @@ const store_1 = require("../shared/store");
17
17
  const auth_1 = require("../shared/auth");
18
18
  const path_1 = __importDefault(require("path"));
19
19
  const i18n_1 = require("../shared/i18n");
20
+ const protectedPathCase_1 = __importDefault(require("../middlewares/protectedPathCase"));
21
+ function resolveTrustProxy(value = process.env.QL_TRUST_PROXY) {
22
+ const setting = value === null || value === void 0 ? void 0 : value.trim();
23
+ if (!setting) {
24
+ return 'loopback';
25
+ }
26
+ if (setting === 'true' || setting === 'false') {
27
+ return setting === 'true';
28
+ }
29
+ if (/^\d+$/.test(setting)) {
30
+ return Number(setting);
31
+ }
32
+ return setting;
33
+ }
20
34
  exports.default = ({ app }) => {
21
35
  // Security: Enable strict routing to prevent case-insensitive path bypass
22
36
  app.set('case sensitive routing', true);
23
37
  app.set('strict routing', true);
24
- app.set('trust proxy', 'loopback');
38
+ app.set('trust proxy', resolveTrustProxy());
25
39
  app.use((0, cors_1.default)());
26
- // Security: Path normalization middleware to prevent case variation attacks
27
- app.use((req, res, next) => {
28
- const originalPath = req.path;
29
- const normalizedPath = originalPath.toLowerCase();
30
- // Block requests with case variations on protected paths
31
- if (originalPath !== normalizedPath &&
32
- (normalizedPath.startsWith('/api/') || normalizedPath.startsWith('/open/'))) {
33
- return res.status(400).json({
34
- code: 400,
35
- message: 'Invalid path format'
36
- });
37
- }
38
- next();
39
- });
40
+ // Security: Reject case variations under protected API namespaces before
41
+ // authentication checks can interpret the request differently from routing.
42
+ app.use(protectedPathCase_1.default);
40
43
  // Rewrite URLs to strip baseUrl prefix if configured
41
44
  // This allows the rest of the app to work without baseUrl awareness
42
45
  if (config_1.default.baseUrl) {
43
46
  app.use((0, express_urlrewrite_1.default)(`${config_1.default.baseUrl}/*`, '/$1'));
44
47
  }
45
48
  app.get(`${config_1.default.api.prefix}/env.js`, serverEnv_1.serveEnv);
46
- app.use(`${config_1.default.api.prefix}/static`, express_1.default.static(config_1.default.uploadPath));
49
+ app.use(`${config_1.default.api.prefix}/static`, express_1.default.static(config_1.default.uploadPath, {
50
+ setHeaders: (res) => {
51
+ res.setHeader('X-Content-Type-Options', 'nosniff');
52
+ res.setHeader('Content-Security-Policy', "sandbox; default-src 'none'");
53
+ },
54
+ }));
55
+ const credentialPaths = ['/api', '/open'].flatMap((prefix) => ['/user/login', '/user/init', '/user/two-factor/login'].map((route) => `${prefix}${route}`));
56
+ app.use(credentialPaths, body_parser_1.default.json({ limit: '16kb' }), body_parser_1.default.urlencoded({ limit: '16kb', extended: false }));
47
57
  app.use(body_parser_1.default.json({ limit: '50mb' }));
48
58
  app.use(body_parser_1.default.urlencoded({ limit: '50mb', extended: true }));
49
59
  const frontendPath = path_1.default.join(config_1.default.rootPath, 'static/dist');
@@ -84,7 +94,8 @@ exports.default = ({ app }) => {
84
94
  });
85
95
  return next(err);
86
96
  }
87
- if (!currentToken || currentToken.expiration < Math.round(Date.now() / 1000)) {
97
+ if (!currentToken ||
98
+ currentToken.expiration < Math.round(Date.now() / 1000)) {
88
99
  const err = new express_jwt_1.UnauthorizedError('invalid_token', {
89
100
  message: (0, i18n_1.t)('Token 已失效'),
90
101
  });
@@ -100,13 +111,11 @@ exports.default = ({ app }) => {
100
111
  return next();
101
112
  }
102
113
  const authInfo = await store_1.shareStore.getAuthInfo();
103
- if ((0, auth_1.isValidToken)(authInfo, headerToken, req.platform)) {
114
+ if ((0, auth_1.isValidToken)(authInfo, headerToken, req.platform, config_1.default.jwt.secret)) {
104
115
  return next();
105
116
  }
106
117
  const errorCode = headerToken ? 'invalid_token' : 'credentials_required';
107
- const errorMessage = headerToken
108
- ? (0, i18n_1.t)('Token 已失效')
109
- : (0, i18n_1.t)('请先登录');
118
+ const errorMessage = headerToken ? (0, i18n_1.t)('Token 已失效') : (0, i18n_1.t)('请先登录');
110
119
  const err = new express_jwt_1.UnauthorizedError(errorCode, { message: errorMessage });
111
120
  next(err);
112
121
  });
@@ -45,11 +45,12 @@ const util_1 = require("../config/util");
45
45
  const open_1 = __importDefault(require("../services/open"));
46
46
  const store_1 = require("../shared/store");
47
47
  const logger_1 = __importDefault(require("./logger"));
48
+ const client_1 = __importDefault(require("../schedule/client"));
48
49
  const open_2 = require("../data/open");
49
50
  const runningInstance_1 = require("../data/runningInstance");
50
51
  const i18n_1 = require("../shared/i18n");
51
52
  exports.default = async () => {
52
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
53
+ var _a, _b, _c, _d, _e, _f, _g, _h;
53
54
  const cronService = typedi_1.Container.get(cron_2.default);
54
55
  const envService = typedi_1.Container.get(env_1.default);
55
56
  const dependenceService = typedi_1.Container.get(dependence_1.default);
@@ -206,18 +207,20 @@ exports.default = async () => {
206
207
  }
207
208
  }
208
209
  });
209
- // 初始化保存一次ck和定时任务数据
210
- await cronService.autosave_crontab();
211
- // 确保 lang_env.sh 存在,提供默认 QL_LANG
210
+ // 初始化语言(必须在 autosave_crontab 之前)
211
+ const lang = ((_h = systemConfig.info) === null || _h === void 0 ? void 0 : _h.lang) || (0, i18n_1.systemLang)();
212
+ (0, i18n_1.setLang)(lang);
213
+ // 确保 lang_env.sh 存在
212
214
  try {
213
215
  const langEnvExist = await (0, util_1.fileExist)(config_1.default.langEnvFile);
214
216
  if (!langEnvExist) {
215
- const lang = ((_h = systemConfig.info) === null || _h === void 0 ? void 0 : _h.lang) || 'zh';
216
217
  await (0, promises_1.writeFile)(config_1.default.langEnvFile, `export QL_LANG='${lang}'\n`);
217
218
  }
218
219
  }
219
- catch (_k) { }
220
- (0, i18n_1.setLang)(((_j = systemConfig.info) === null || _j === void 0 ? void 0 : _j.lang) || 'zh');
220
+ catch (_j) { }
221
+ // 初始化保存一次ck和定时任务数据
222
+ client_1.default.readiness.configure(() => cronService.autosave_crontab(true));
223
+ await client_1.default.readiness.recover();
221
224
  await envService.set_envs();
222
225
  const authInfo = await userService.getAuthInfo();
223
226
  const apps = await openService.findApps();
@@ -11,23 +11,89 @@ const store_1 = require("../shared/store");
11
11
  const auth_1 = require("../shared/auth");
12
12
  const config_1 = __importDefault(require("../config"));
13
13
  exports.default = async ({ server }) => {
14
- const echo = sockjs_1.default.createServer({ prefix: `${config_1.default.baseUrl}/api/ws`, log: () => { } });
14
+ const echo = sockjs_1.default.createServer({
15
+ prefix: `${config_1.default.baseUrl}/api/ws`,
16
+ log: () => { },
17
+ });
15
18
  const sockService = typedi_1.Container.get(sock_1.default);
19
+ const sessions = new Map();
20
+ let sessionTimer;
21
+ let checking = false;
22
+ const checkSessions = async () => {
23
+ if (checking || sessions.size === 0)
24
+ return;
25
+ checking = true;
26
+ // Connections accepted during this read must not use an older snapshot.
27
+ const batch = [...sessions];
28
+ try {
29
+ const current = await store_1.shareStore.getAuthInfo();
30
+ // Reuse validation only within this synchronous check of one auth snapshot.
31
+ const validated = new Map();
32
+ for (const [conn, { token, platform }] of batch) {
33
+ if (!sessions.has(conn))
34
+ continue;
35
+ let platforms = validated.get(token);
36
+ if (!platforms) {
37
+ platforms = new Map();
38
+ validated.set(token, platforms);
39
+ }
40
+ let valid = platforms.get(platform);
41
+ if (valid === undefined) {
42
+ valid = (0, auth_1.isValidToken)(current, token, platform, config_1.default.jwt.secret);
43
+ platforms.set(platform, valid);
44
+ }
45
+ if (!valid)
46
+ conn.close('401');
47
+ }
48
+ }
49
+ catch (_a) {
50
+ for (const [conn] of batch) {
51
+ if (sessions.has(conn))
52
+ conn.close('401');
53
+ }
54
+ }
55
+ finally {
56
+ checking = false;
57
+ }
58
+ };
16
59
  echo.on('connection', async (conn) => {
17
60
  if (!conn.headers || !conn.url || !conn.pathname) {
18
61
  conn.close('404');
62
+ return;
19
63
  }
20
- const authInfo = await store_1.shareStore.getAuthInfo();
64
+ let closed = false;
65
+ conn.on('close', () => {
66
+ closed = true;
67
+ sessions.delete(conn);
68
+ sockService.removeClient(conn);
69
+ if (sessions.size === 0 && sessionTimer) {
70
+ clearInterval(sessionTimer);
71
+ sessionTimer = undefined;
72
+ }
73
+ });
74
+ let authInfo;
75
+ try {
76
+ authInfo = await store_1.shareStore.getAuthInfo();
77
+ }
78
+ catch (_a) {
79
+ if (!closed)
80
+ conn.close('401');
81
+ return;
82
+ }
83
+ if (closed)
84
+ return;
21
85
  const platform = (0, util_1.getPlatform)(conn.headers['user-agent'] || '') || 'desktop';
22
86
  const headerToken = conn.url.replace(`${conn.pathname}?token=`, '');
23
- if ((0, auth_1.isValidToken)(authInfo, headerToken, platform)) {
87
+ if ((0, auth_1.isValidToken)(authInfo, headerToken, platform, config_1.default.jwt.secret)) {
24
88
  sockService.addClient(conn);
89
+ sessions.set(conn, { token: headerToken, platform });
90
+ if (!sessionTimer) {
91
+ sessionTimer = setInterval(checkSessions, 1000);
92
+ sessionTimer.unref();
93
+ }
25
94
  conn.on('data', (message) => {
26
95
  conn.write(message);
27
96
  });
28
- conn.on('close', function () {
29
- sockService.removeClient(conn);
30
- });
31
97
  return;
32
98
  }
33
99
  conn.close('404');