@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.
- package/.dockerignore +13 -0
- package/.env.example +7 -0
- package/AGENTS.md +2 -2
- package/README-en.md +24 -0
- package/README.md +24 -0
- package/back/protos/api.proto +6 -1
- package/back/protos/cron.proto +4 -1
- package/docker/Dockerfile +31 -12
- package/docker/Dockerfile.310 +31 -12
- package/docker/Dockerfile.debian +22 -14
- package/docker/Dockerfile.debian310 +24 -14
- package/docker/build-manifest.cjs +28 -0
- package/docker/verify-build.cjs +49 -0
- package/docs/releases/2.22.0-validation.md +49 -0
- package/docs/releases/2.22.0.md +54 -0
- package/ecosystem.config.js +10 -1
- package/package.json +11 -6
- package/sample/config.sample.sh +10 -0
- package/sample/notify.js +54 -0
- package/sample/notify.py +37 -0
- package/scripts/benchmark-execution.cjs +96 -0
- package/scripts/write-build-info.cjs +27 -0
- package/shell/api.sh +34 -13
- package/shell/check.sh +59 -19
- package/shell/lang/en.sh +6 -0
- package/shell/lang/zh.sh +6 -0
- package/shell/node_path_cache.sh +128 -0
- package/shell/otask.sh +7 -1
- package/shell/preload/sitecustomize.js +5 -1
- package/shell/share.sh +25 -8
- package/shell/start.sh +6 -3
- package/shell/task.sh +13 -3
- package/shell/update.sh +65 -4
- package/static/build/api/clientIp.js +42 -0
- package/static/build/api/config.js +8 -16
- package/static/build/api/cron.js +38 -2
- package/static/build/api/dashboard.js +37 -0
- package/static/build/api/health.js +2 -2
- package/static/build/api/index.js +4 -0
- package/static/build/api/log.js +30 -19
- package/static/build/api/retention.js +63 -0
- package/static/build/api/script.js +23 -22
- package/static/build/api/subscription.js +16 -2
- package/static/build/api/system.js +25 -2
- package/static/build/api/user.js +75 -15
- package/static/build/app.js +54 -45
- package/static/build/bootstrap/database.js +51 -0
- package/static/build/config/const.js +1 -0
- package/static/build/config/share.js +5 -4
- package/static/build/config/util.js +133 -38
- package/static/build/data/cron.js +1 -0
- package/static/build/data/notify.js +11 -1
- package/static/build/loaders/app.js +2 -0
- package/static/build/loaders/db.js +3 -33
- package/static/build/loaders/deps.js +29 -0
- package/static/build/loaders/express.js +30 -21
- package/static/build/loaders/initData.js +10 -7
- package/static/build/loaders/sock.js +72 -6
- package/static/build/middlewares/monitoring.js +12 -33
- package/static/build/middlewares/protectedPathCase.js +17 -0
- package/static/build/protos/api.js +56 -2
- package/static/build/protos/cron.js +21 -4
- package/static/build/protos/health.js +1 -1
- package/static/build/schedule/addCron.js +9 -0
- package/static/build/schedule/api.js +5 -2
- package/static/build/schedule/client.js +38 -6
- package/static/build/schedule/health.js +72 -7
- package/static/build/services/config.js +5 -42
- package/static/build/services/cron.js +338 -199
- package/static/build/services/dependence.js +47 -0
- package/static/build/services/grpc.js +1 -1
- package/static/build/services/health.js +4 -7
- package/static/build/services/http.js +8 -2
- package/static/build/services/log.js +2 -3
- package/static/build/services/metrics.js +46 -14
- package/static/build/services/notify.js +26 -0
- package/static/build/services/retention.js +123 -0
- package/static/build/services/schedule.js +57 -33
- package/static/build/services/script.js +4 -5
- package/static/build/services/subscription.js +55 -34
- package/static/build/services/system.js +37 -9
- package/static/build/services/user.js +213 -25
- package/static/build/shared/auth.js +18 -5
- package/static/build/shared/authMutation.js +17 -0
- package/static/build/shared/childProcess.js +82 -0
- package/static/build/shared/clientIp.js +27 -0
- package/static/build/shared/errors.js +9 -0
- package/static/build/shared/fileAccess.js +60 -0
- package/static/build/shared/i18n.js +12 -5
- package/static/build/shared/logReader.js +85 -0
- package/static/build/shared/logStreamManager.js +80 -60
- package/static/build/shared/password.js +30 -0
- package/static/build/shared/retention.js +58 -0
- package/static/build/shared/runCron.js +28 -15
- package/static/build/shared/schedulerMutationLock.js +44 -0
- package/static/build/shared/schedulerReadiness.js +82 -0
- package/static/build/shared/schemaMigrations.js +58 -0
- package/static/build/shared/startupProcess.js +48 -0
- package/static/build/shared/store.js +7 -0
- package/static/build/shared/trustProxy.js +119 -0
- package/static/build/validation/schedule.js +3 -3
- package/static/dist/{1885.e1ea09f6.async.js → 1885.b8f427bf.async.js} +1 -1
- package/static/dist/2031.6af40025.async.js +1 -0
- package/static/dist/2693.51c2636b.async.js +1 -0
- package/static/dist/{2890.9e373f5b.async.js → 2890.add55e85.async.js} +1 -1
- package/static/dist/2901.2ca95295.async.js +1 -0
- package/static/dist/445.a65ff63b.async.js +1 -0
- package/static/dist/4736.1d2b5cb6.async.js +1 -0
- package/static/dist/{4859.6592cebb.async.js → 4859.97d6653c.async.js} +1 -1
- package/static/dist/{6013.4e38de36.async.js → 6013.db535339.async.js} +1 -1
- package/static/dist/6212.9e6d9913.async.js +1 -0
- package/static/dist/{6339.ab305e96.async.js → 6431.4603ad0e.async.js} +1 -1
- package/static/dist/{6872.42f939f1.async.js → 6872.a503ef55.async.js} +1 -1
- package/static/dist/7231.f7e5b668.async.js +1 -0
- package/static/dist/{7355.f9f263d8.async.js → 7355.fca746f5.async.js} +1 -1
- package/static/dist/{7508.7dcee91c.async.js → 7508.d90eac63.async.js} +1 -1
- package/static/dist/{7984.594296a5.async.js → 7984.eaac7402.async.js} +1 -1
- package/static/dist/8844.a0fef08e.async.js +1 -0
- package/static/dist/index.html +2 -2
- package/static/dist/layouts__index.633d3553.async.js +1 -0
- package/static/dist/preload_helper.cf7de3fa.js +1 -0
- package/static/dist/{src__pages__config__index.a22ff7dc.async.js → src__pages__config__index.9aba4054.async.js} +1 -1
- package/static/dist/src__pages__crontab__detail.86b2eebb.async.js +1 -0
- package/static/dist/src__pages__crontab__index.ae4e06f2.async.js +1 -0
- package/static/dist/{src__pages__crontab__logModal.831d5e4b.async.js → src__pages__crontab__logModal.930535e2.async.js} +1 -1
- package/static/dist/src__pages__crontab__modal.a2c8fdcc.async.js +1 -0
- package/static/dist/src__pages__crontab__viewCreateModal.7b4f9cbe.async.js +1 -0
- package/static/dist/src__pages__crontab__viewManageModal.cd454ea0.async.js +1 -0
- package/static/dist/src__pages__dashboard__index.243c5a35.async.js +1 -0
- package/static/dist/src__pages__dashboard__taskResultModal.7795d6e1.async.js +1 -0
- package/static/dist/src__pages__dependence__index.874d501f.async.js +1 -0
- package/static/dist/src__pages__dependence__logModal.154efe7a.async.js +1 -0
- package/static/dist/src__pages__dependence__modal.a29c1a0f.async.js +1 -0
- package/static/dist/{src__pages__diff__index.013b7c75.async.js → src__pages__diff__index.1714b941.async.js} +1 -1
- package/static/dist/src__pages__env__editNameModal.c13d47d2.async.js +1 -0
- package/static/dist/src__pages__env__index.fd6fd2b0.async.js +1 -0
- package/static/dist/src__pages__env__modal.4d71adb3.async.js +1 -0
- package/static/dist/src__pages__error__index.aae50c94.async.js +1 -0
- package/static/dist/src__pages__initialization__index.82a2e967.async.js +1 -0
- package/static/dist/src__pages__log__index.71250e0d.async.js +1 -0
- package/static/dist/{src__pages__login__index.8c813eb1.async.js → src__pages__login__index.a0fd5ed8.async.js} +1 -1
- package/static/dist/src__pages__script__editModal.22acdf7c.async.js +1 -0
- package/static/dist/src__pages__script__editNameModal.1a521cc0.async.js +1 -0
- package/static/dist/src__pages__script__index.a18b2692.async.js +1 -0
- package/static/dist/src__pages__script__renameModal.0ab029e7.async.js +1 -0
- package/static/dist/src__pages__script__saveModal.8965b74c.async.js +1 -0
- package/static/dist/src__pages__script__setting.35ad4f02.async.js +1 -0
- package/static/dist/src__pages__setting__appModal.7eaeb9d3.async.js +1 -0
- package/static/dist/{src__pages__setting__checkUpdate.34d773f2.async.js → src__pages__setting__checkUpdate.d175b154.async.js} +1 -1
- package/static/dist/src__pages__setting__clientIp.3a8711ed.async.js +1 -0
- package/static/dist/src__pages__setting__dependence.9c0f749b.async.js +1 -0
- package/static/dist/src__pages__setting__index.cb397741.async.js +1 -0
- package/static/dist/src__pages__setting__loginLog.e0a1f54d.async.js +1 -0
- package/static/dist/src__pages__setting__notification.2ffe4e5a.async.js +1 -0
- package/static/dist/src__pages__setting__other.3d0b8492.async.js +1 -0
- package/static/dist/{src__pages__setting__progress.8823ac90.async.js → src__pages__setting__progress.2ccae3d7.async.js} +1 -1
- package/static/dist/src__pages__setting__security.e2d71ebb.async.js +1 -0
- package/static/dist/src__pages__setting__systemLog.b3046955.async.js +1 -0
- package/static/dist/src__pages__subscription__index.43086a06.async.js +1 -0
- package/static/dist/src__pages__subscription__logModal.cdba5139.async.js +1 -0
- package/static/dist/src__pages__subscription__modal.38991e1e.async.js +1 -0
- package/static/dist/{umi.a54a59f6.js → umi.fc019050.js} +1 -1
- package/test/back/auth-security.test.cjs +74 -0
- package/test/back/build-provenance.test.cjs +150 -0
- package/test/back/cron-log-name.test.cjs +110 -0
- package/test/back/cron-validation.test.cjs +45 -0
- package/test/back/dashboard-failures.test.cjs +173 -0
- package/test/back/database-bootstrap.test.cjs +193 -0
- package/test/back/dependence-cache-status.test.cjs +125 -0
- package/test/back/deprecated-file-routes.test.cjs +82 -0
- package/test/back/ecosystem.test.cjs +28 -0
- package/test/back/env-name-parsing.test.cjs +96 -0
- package/test/back/execution-lifecycle.test.cjs +236 -0
- package/test/back/file-access-security.test.cjs +47 -0
- package/test/back/fileTreeListing.test.cjs +57 -0
- package/test/back/grpc-cron-response.test.cjs +60 -0
- package/test/back/http-exclusive-listen.test.cjs +31 -0
- package/test/back/http-security.test.cjs +213 -0
- package/test/back/listen-security.test.cjs +67 -0
- package/test/back/log-path-security.test.cjs +158 -0
- package/test/back/logReader.test.cjs +72 -0
- package/test/back/manual-execution.test.cjs +85 -0
- package/test/back/manual-stop-claim.test.cjs +220 -0
- package/test/back/metrics.test.cjs +34 -0
- package/test/back/monitoring.test.cjs +73 -0
- package/test/back/node-path-cache.test.cjs +173 -0
- package/test/back/node-path-lock.test.cjs +178 -0
- package/test/back/npm-publication.test.cjs +70 -0
- package/test/back/primary-apm.test.cjs +24 -0
- package/test/back/process-exit-state.test.cjs +81 -0
- package/test/back/process-stop-signal.test.cjs +77 -0
- package/test/back/protected-path-case.test.cjs +58 -0
- package/test/back/qlServiceLogCommand.test.cjs +128 -0
- package/test/back/retention.test.cjs +131 -0
- package/test/back/role-loading.test.cjs +118 -0
- package/test/back/schedule-health.test.cjs +86 -0
- package/test/back/scheduler-file-lock.test.cjs +51 -0
- package/test/back/scheduler-mutation.test.cjs +312 -0
- package/test/back/scheduler-readiness.test.cjs +85 -0
- package/test/back/scheduler-reconciliation.test.cjs +152 -0
- package/test/back/scheduler-rpc-timeout.test.cjs +49 -0
- package/test/back/schema-migrations.test.cjs +127 -0
- package/test/back/shell-api-parsing.test.cjs +184 -0
- package/test/back/sock-polling.test.cjs +297 -0
- package/test/back/sock-security.test.cjs +72 -0
- package/test/back/start-env-preservation.test.cjs +53 -0
- package/test/back/stop-failure-feedback.test.cjs +158 -0
- package/test/back/stop-race.test.cjs +167 -0
- package/test/back/subscription-cleanup.test.cjs +53 -0
- package/test/back/subscription-stop-state.test.cjs +66 -0
- package/test/back/system-dependence-cache.test.cjs +126 -0
- package/test/back/task-time.test.cjs +116 -0
- package/test/back/user-api.test.cjs +99 -0
- package/test/back/user-security.test.cjs +248 -0
- package/test/back/worker-apm.test.cjs +84 -0
- package/test/back/wpush-grpc.test.cjs +115 -0
- package/test/front/cron-log-pagination.test.cjs +214 -0
- package/test/front/http-auth.test.cjs +152 -0
- package/test/front/http-error.test.cjs +29 -0
- package/test/helpers/load-security-module.cjs +42 -0
- package/version.yaml +19 -34
- package/CLAUDE.md +0 -43
- package/static/dist/1147.62793604.async.js +0 -1
- package/static/dist/134.54df9e38.async.js +0 -1
- package/static/dist/2208.85285476.async.js +0 -1
- package/static/dist/2286.f371c743.async.js +0 -1
- package/static/dist/3191.545ab873.async.js +0 -1
- package/static/dist/4902.555f92ab.async.js +0 -1
- package/static/dist/5520.ff2cfd6b.async.js +0 -1
- package/static/dist/6431.c50479be.async.js +0 -1
- package/static/dist/8826.db34ad8d.async.js +0 -1
- package/static/dist/layouts__index.a7a2bfe0.async.js +0 -1
- package/static/dist/preload_helper.3048fe5b.js +0 -1
- package/static/dist/src__pages__crontab__detail.b98f0084.async.js +0 -1
- package/static/dist/src__pages__crontab__index.68e78a33.async.js +0 -1
- package/static/dist/src__pages__crontab__modal.f7041c7c.async.js +0 -1
- package/static/dist/src__pages__crontab__viewCreateModal.4d589f66.async.js +0 -1
- package/static/dist/src__pages__crontab__viewManageModal.0e317746.async.js +0 -1
- package/static/dist/src__pages__dashboard__index.58177357.async.js +0 -1
- package/static/dist/src__pages__dependence__index.b7bbc795.async.js +0 -1
- package/static/dist/src__pages__dependence__logModal.0681830b.async.js +0 -1
- package/static/dist/src__pages__dependence__modal.f7bb47ba.async.js +0 -1
- package/static/dist/src__pages__env__editNameModal.48715576.async.js +0 -1
- package/static/dist/src__pages__env__index.452cdc47.async.js +0 -1
- package/static/dist/src__pages__env__modal.e1234834.async.js +0 -1
- package/static/dist/src__pages__error__index.dedb2b90.async.js +0 -1
- package/static/dist/src__pages__initialization__index.22620a77.async.js +0 -1
- package/static/dist/src__pages__log__index.9c66639f.async.js +0 -1
- package/static/dist/src__pages__script__editModal.cbf4ec0e.async.js +0 -1
- package/static/dist/src__pages__script__editNameModal.532a3044.async.js +0 -1
- package/static/dist/src__pages__script__index.1fc20f22.async.js +0 -1
- package/static/dist/src__pages__script__renameModal.5cdde919.async.js +0 -1
- package/static/dist/src__pages__script__saveModal.5ffed35f.async.js +0 -1
- package/static/dist/src__pages__script__setting.1a82c6d7.async.js +0 -1
- package/static/dist/src__pages__setting__appModal.43b7758a.async.js +0 -1
- package/static/dist/src__pages__setting__dependence.9c04c79a.async.js +0 -1
- package/static/dist/src__pages__setting__index.7e070838.async.js +0 -1
- package/static/dist/src__pages__setting__loginLog.cea6056c.async.js +0 -1
- package/static/dist/src__pages__setting__notification.bac481c2.async.js +0 -1
- package/static/dist/src__pages__setting__other.707cfafe.async.js +0 -1
- package/static/dist/src__pages__setting__security.b7235753.async.js +0 -1
- package/static/dist/src__pages__setting__systemLog.b81a8c1d.async.js +0 -1
- package/static/dist/src__pages__subscription__index.d0ab2abc.async.js +0 -1
- package/static/dist/src__pages__subscription__logModal.3864b37f.async.js +0 -1
- package/static/dist/src__pages__subscription__modal.562448e2.async.js +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.observeChildProcess = exports.asError = void 0;
|
|
11
|
+
function asError(error) {
|
|
12
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
13
|
+
}
|
|
14
|
+
exports.asError = asError;
|
|
15
|
+
/** Attach immediately after spawn, before awaiting database or user callbacks. */
|
|
16
|
+
function observeChildProcess(child, callbacks = {}) {
|
|
17
|
+
let failure;
|
|
18
|
+
const recordError = (error) => {
|
|
19
|
+
failure !== null && failure !== void 0 ? failure : (failure = asError(error));
|
|
20
|
+
};
|
|
21
|
+
const spawned = new Promise((resolve, reject) => {
|
|
22
|
+
child.once('spawn', resolve);
|
|
23
|
+
// Keep the listener through close: errors can occur after a successful spawn.
|
|
24
|
+
child.on('error', (error) => {
|
|
25
|
+
recordError(error);
|
|
26
|
+
reject(error);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
const closed = new Promise((resolve) => {
|
|
30
|
+
child.once('close', (code, signal) => resolve({ code, signal }));
|
|
31
|
+
});
|
|
32
|
+
const started = spawned.then(async () => {
|
|
33
|
+
var _a;
|
|
34
|
+
await ((_a = callbacks.onStart) === null || _a === void 0 ? void 0 : _a.call(callbacks));
|
|
35
|
+
return child.pid;
|
|
36
|
+
});
|
|
37
|
+
// The caller can ask only for completion, without an unhandled start rejection.
|
|
38
|
+
const ready = started.catch(recordError);
|
|
39
|
+
const consume = async (stream, callback) => {
|
|
40
|
+
var _a, e_1, _b, _c;
|
|
41
|
+
// StringDecoder in Readable preserves UTF-8 characters split across chunks.
|
|
42
|
+
stream.setEncoding('utf8');
|
|
43
|
+
let callbackFailed = false;
|
|
44
|
+
try {
|
|
45
|
+
try {
|
|
46
|
+
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = await stream_1.next(), _a = stream_1_1.done, !_a; _d = true) {
|
|
47
|
+
_c = stream_1_1.value;
|
|
48
|
+
_d = false;
|
|
49
|
+
const chunk = _c;
|
|
50
|
+
await ready;
|
|
51
|
+
if (!callbackFailed && callback) {
|
|
52
|
+
try {
|
|
53
|
+
await callback(String(chunk));
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
recordError(error);
|
|
57
|
+
callbackFailed = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
63
|
+
finally {
|
|
64
|
+
try {
|
|
65
|
+
if (!_d && !_a && (_b = stream_1.return)) await _b.call(stream_1);
|
|
66
|
+
}
|
|
67
|
+
finally { if (e_1) throw e_1.error; }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
recordError(error);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const output = Promise.all([
|
|
75
|
+
consume(child.stdout, callbacks.onStdout),
|
|
76
|
+
consume(child.stderr, callbacks.onStderr),
|
|
77
|
+
]);
|
|
78
|
+
const completed = Promise.all([closed, ready, output]).then(([result]) => (Object.assign(Object.assign({}, result), { error: failure })));
|
|
79
|
+
return { started, completed };
|
|
80
|
+
}
|
|
81
|
+
exports.observeChildProcess = observeChildProcess;
|
|
82
|
+
//# sourceMappingURL=childProcess.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClientIp = exports.normalizeClientIp = void 0;
|
|
4
|
+
const IPV4_MAPPED_PREFIX = '::ffff:';
|
|
5
|
+
function normalizeClientIp(value) {
|
|
6
|
+
let ip = (value || '').trim().toLowerCase();
|
|
7
|
+
if (!ip) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
if (ip.startsWith('[') && ip.endsWith(']')) {
|
|
11
|
+
ip = ip.slice(1, -1);
|
|
12
|
+
}
|
|
13
|
+
const zoneIndex = ip.indexOf('%');
|
|
14
|
+
if (zoneIndex !== -1) {
|
|
15
|
+
ip = ip.slice(0, zoneIndex);
|
|
16
|
+
}
|
|
17
|
+
if (ip.startsWith(IPV4_MAPPED_PREFIX)) {
|
|
18
|
+
return ip.slice(IPV4_MAPPED_PREFIX.length);
|
|
19
|
+
}
|
|
20
|
+
return ip;
|
|
21
|
+
}
|
|
22
|
+
exports.normalizeClientIp = normalizeClientIp;
|
|
23
|
+
function getClientIp(req) {
|
|
24
|
+
return normalizeClientIp(req.ip || req.socket.remoteAddress);
|
|
25
|
+
}
|
|
26
|
+
exports.getClientIp = getClientIp;
|
|
27
|
+
//# sourceMappingURL=clientIp.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errStack = void 0;
|
|
4
|
+
// Keep error formatting independent of database, HTTP and gRPC dependencies.
|
|
5
|
+
function errStack(error) {
|
|
6
|
+
return error instanceof Error && error.stack ? error.stack : String(error);
|
|
7
|
+
}
|
|
8
|
+
exports.errStack = errStack;
|
|
9
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveFileAccess = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function isWithin(root, target) {
|
|
10
|
+
const relative = path_1.default.relative(root, target);
|
|
11
|
+
return (relative === '' ||
|
|
12
|
+
(!relative.startsWith(`..${path_1.default.sep}`) &&
|
|
13
|
+
relative !== '..' &&
|
|
14
|
+
!path_1.default.isAbsolute(relative)));
|
|
15
|
+
}
|
|
16
|
+
/** Resolve existing files and not-yet-created children without following an
|
|
17
|
+
* existing symlink outside the root. Blacklisted directories cover descendants. */
|
|
18
|
+
function resolveFileAccess(root, parts, blacklist = []) {
|
|
19
|
+
if (parts.some((part) => typeof part !== 'string' || part.includes('\0'))) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
const resolvedRoot = path_1.default.resolve(root);
|
|
23
|
+
const target = path_1.default.resolve(resolvedRoot, ...parts);
|
|
24
|
+
if (target === resolvedRoot || !isWithin(resolvedRoot, target))
|
|
25
|
+
return '';
|
|
26
|
+
const isBlocked = (relative) => relative.split(path_1.default.sep).some((part) => blacklist.includes(part));
|
|
27
|
+
if (isBlocked(path_1.default.relative(resolvedRoot, target)))
|
|
28
|
+
return '';
|
|
29
|
+
try {
|
|
30
|
+
const realRoot = fs_1.default.realpathSync(resolvedRoot);
|
|
31
|
+
let existing = target;
|
|
32
|
+
const missing = [];
|
|
33
|
+
while (!fs_1.default.existsSync(existing)) {
|
|
34
|
+
// existsSync is false for a dangling symlink; never treat one as absent.
|
|
35
|
+
try {
|
|
36
|
+
fs_1.default.lstatSync(existing);
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.code !== 'ENOENT')
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
if (existing === resolvedRoot)
|
|
44
|
+
return '';
|
|
45
|
+
missing.unshift(path_1.default.basename(existing));
|
|
46
|
+
existing = path_1.default.dirname(existing);
|
|
47
|
+
}
|
|
48
|
+
const realTarget = path_1.default.resolve(fs_1.default.realpathSync(existing), ...missing);
|
|
49
|
+
if (!isWithin(realRoot, realTarget) ||
|
|
50
|
+
isBlocked(path_1.default.relative(realRoot, realTarget))) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.resolveFileAccess = resolveFileAccess;
|
|
60
|
+
//# sourceMappingURL=fileAccess.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tf = exports.t = exports.
|
|
3
|
+
exports.tf = exports.t = exports.systemLang = exports.setLang = void 0;
|
|
4
|
+
const store_1 = require("./store");
|
|
4
5
|
const messages = {
|
|
5
6
|
zh: {},
|
|
6
7
|
en: {
|
|
@@ -94,9 +95,12 @@ const messages = {
|
|
|
94
95
|
'日志设置为忽略': 'Log set to ignore',
|
|
95
96
|
'定时规则不能为空': 'Schedule rule cannot be empty',
|
|
96
97
|
'无效的定时规则': 'Invalid schedule rule',
|
|
97
|
-
'
|
|
98
|
+
'日志名称只能包含中文、字母、数字、下划线、连字符、点和路径分隔符': 'Log name can only contain Chinese characters, letters, numbers, underscores, hyphens, dots, and path separators',
|
|
98
99
|
'日志名称不能超过100个字符': 'Log name cannot exceed 100 characters',
|
|
99
100
|
'错误的用户名密码,请重试': 'Incorrect username or password, please try again',
|
|
101
|
+
'该 IP 已被列入黑名单': 'This IP address has been blocked',
|
|
102
|
+
'已加入 IP 黑名单': 'IP address added to the blacklist',
|
|
103
|
+
'已移出 IP 黑名单': 'IP address removed from the blacklist',
|
|
100
104
|
'青龙快讯': 'QingLong',
|
|
101
105
|
'登录通知': 'Login Notification',
|
|
102
106
|
'你于': 'You at ',
|
|
@@ -135,12 +139,15 @@ const messages = {
|
|
|
135
139
|
let currentLang = 'zh';
|
|
136
140
|
function setLang(lang) {
|
|
137
141
|
currentLang = lang || 'zh';
|
|
142
|
+
store_1.shareStore.setLang(currentLang);
|
|
138
143
|
}
|
|
139
144
|
exports.setLang = setLang;
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
/** 系统默认语言:Intl 检测 → 'zh'(仅返回 zh/en) */
|
|
146
|
+
function systemLang() {
|
|
147
|
+
const prefix = Intl.DateTimeFormat().resolvedOptions().locale.split('-')[0];
|
|
148
|
+
return prefix === 'en' ? 'en' : 'zh';
|
|
142
149
|
}
|
|
143
|
-
exports.
|
|
150
|
+
exports.systemLang = systemLang;
|
|
144
151
|
function t(key, lang) {
|
|
145
152
|
const effectiveLang = lang || currentLang;
|
|
146
153
|
if (effectiveLang === 'en' && messages.en[key]) {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readLogChunk = exports.MAX_LOG_CHUNK_BYTES = exports.DEFAULT_LOG_CHUNK_BYTES = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
exports.DEFAULT_LOG_CHUNK_BYTES = 256 * 1024;
|
|
9
|
+
exports.MAX_LOG_CHUNK_BYTES = 1024 * 1024;
|
|
10
|
+
function normalizeLimit(limit) {
|
|
11
|
+
if (!Number.isFinite(limit))
|
|
12
|
+
return exports.DEFAULT_LOG_CHUNK_BYTES;
|
|
13
|
+
return Math.min(Math.max(Math.trunc(limit), 4), exports.MAX_LOG_CHUNK_BYTES);
|
|
14
|
+
}
|
|
15
|
+
function isUtf8ContinuationByte(byte) {
|
|
16
|
+
return (byte & 0xc0) === 0x80;
|
|
17
|
+
}
|
|
18
|
+
function completeUtf8End(buffer, start, end) {
|
|
19
|
+
if (end <= start)
|
|
20
|
+
return start;
|
|
21
|
+
let sequenceStart = end - 1;
|
|
22
|
+
while (sequenceStart > start &&
|
|
23
|
+
isUtf8ContinuationByte(buffer[sequenceStart])) {
|
|
24
|
+
sequenceStart--;
|
|
25
|
+
}
|
|
26
|
+
const firstByte = buffer[sequenceStart];
|
|
27
|
+
const expectedLength = firstByte < 0x80
|
|
28
|
+
? 1
|
|
29
|
+
: firstByte < 0xe0
|
|
30
|
+
? 2
|
|
31
|
+
: firstByte < 0xf0
|
|
32
|
+
? 3
|
|
33
|
+
: 4;
|
|
34
|
+
return end - sequenceStart < expectedLength ? sequenceStart : end;
|
|
35
|
+
}
|
|
36
|
+
async function readLogChunk(filePath, options = {}) {
|
|
37
|
+
let handle;
|
|
38
|
+
try {
|
|
39
|
+
handle = await promises_1.default.open(filePath, 'r');
|
|
40
|
+
const { size: total } = await handle.stat();
|
|
41
|
+
const limit = normalizeLimit(options.limit);
|
|
42
|
+
const requestedOffset = Number.isFinite(options.offset)
|
|
43
|
+
? Math.trunc(options.offset)
|
|
44
|
+
: undefined;
|
|
45
|
+
const requestedStart = options.tail || requestedOffset === undefined
|
|
46
|
+
? Math.max(total - limit, 0)
|
|
47
|
+
: Math.min(Math.max(requestedOffset, 0), total);
|
|
48
|
+
const length = Math.min(limit + 3, total - requestedStart);
|
|
49
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
50
|
+
const { bytesRead } = await handle.read(buffer, 0, length, requestedStart);
|
|
51
|
+
let leadingBytes = 0;
|
|
52
|
+
while (leadingBytes < bytesRead &&
|
|
53
|
+
isUtf8ContinuationByte(buffer[leadingBytes])) {
|
|
54
|
+
leadingBytes++;
|
|
55
|
+
}
|
|
56
|
+
const offset = requestedStart + leadingBytes;
|
|
57
|
+
const candidateEnd = Math.min(leadingBytes + limit, bytesRead);
|
|
58
|
+
const contentEnd = completeUtf8End(buffer, leadingBytes, candidateEnd);
|
|
59
|
+
const nextOffset = requestedStart + contentEnd;
|
|
60
|
+
return {
|
|
61
|
+
content: buffer.subarray(leadingBytes, contentEnd).toString('utf8'),
|
|
62
|
+
offset,
|
|
63
|
+
nextOffset,
|
|
64
|
+
total,
|
|
65
|
+
truncated: offset > 0 || nextOffset < total,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 'ENOENT') {
|
|
70
|
+
return {
|
|
71
|
+
content: '',
|
|
72
|
+
offset: 0,
|
|
73
|
+
nextOffset: 0,
|
|
74
|
+
total: 0,
|
|
75
|
+
truncated: false,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
await (handle === null || handle === void 0 ? void 0 : handle.close());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.readLogChunk = readLogChunk;
|
|
85
|
+
//# sourceMappingURL=logReader.js.map
|
|
@@ -1,94 +1,114 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.logStreamManager = exports.LogStreamManager = void 0;
|
|
4
7
|
const fs_1 = require("fs");
|
|
5
8
|
const events_1 = require("events");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const config_1 = __importDefault(require("../config"));
|
|
11
|
+
const fileAccess_1 = require("./fileAccess");
|
|
6
12
|
/**
|
|
7
13
|
* Manages write streams for log files to improve performance by avoiding repeated file opens
|
|
8
14
|
*/
|
|
9
15
|
class LogStreamManager extends events_1.EventEmitter {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(
|
|
16
|
+
constructor(logRoot = config_1.default.logPath) {
|
|
17
|
+
super();
|
|
18
|
+
this.logRoot = logRoot;
|
|
12
19
|
this.streams = new Map();
|
|
13
20
|
this.pendingWrites = new Map();
|
|
21
|
+
this.closingStreams = new Map();
|
|
22
|
+
this.closedStreams = new WeakSet();
|
|
23
|
+
this.streamErrors = new Map();
|
|
14
24
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Write data to a log file using a managed stream
|
|
17
|
-
* @param filePath - Absolute path to the log file
|
|
18
|
-
* @param data - Data to write to the log file
|
|
19
|
-
*/
|
|
25
|
+
/** Register each write synchronously, so concurrent callers cannot lose the tail. */
|
|
20
26
|
async write(filePath, data) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (pending) {
|
|
24
|
-
await pending;
|
|
27
|
+
if (this.closingStreams.has(filePath)) {
|
|
28
|
+
throw new Error(`Log stream is closing: ${filePath}`);
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
const
|
|
30
|
+
const previous = this.pendingWrites.get(filePath) || Promise.resolve();
|
|
31
|
+
const pending = previous.then(() => new Promise((resolve, reject) => {
|
|
32
|
+
const failure = this.streamErrors.get(filePath);
|
|
33
|
+
if (failure)
|
|
34
|
+
return reject(failure);
|
|
28
35
|
let stream = this.streams.get(filePath);
|
|
29
36
|
if (!stream) {
|
|
30
|
-
//
|
|
31
|
-
|
|
37
|
+
// Validate only when opening: subsequent chunks reuse the same descriptor.
|
|
38
|
+
const root = path_1.default.resolve(this.logRoot);
|
|
39
|
+
const target = path_1.default.resolve(filePath);
|
|
40
|
+
if (!target.startsWith(root + path_1.default.sep) ||
|
|
41
|
+
!(0, fileAccess_1.resolveFileAccess)(root, [target])) {
|
|
42
|
+
return reject(new Error('Log path is outside the log directory'));
|
|
43
|
+
}
|
|
44
|
+
stream = (0, fs_1.createWriteStream)(target, { flags: 'a' });
|
|
32
45
|
this.streams.set(filePath, stream);
|
|
33
|
-
|
|
46
|
+
const current = stream;
|
|
47
|
+
stream.once('close', () => this.closedStreams.add(current));
|
|
34
48
|
stream.on('error', (error) => {
|
|
35
|
-
this.
|
|
36
|
-
//
|
|
37
|
-
this.
|
|
38
|
-
|
|
49
|
+
this.streamErrors.set(filePath, error);
|
|
50
|
+
// EventEmitter's unobserved "error" event would crash the caller.
|
|
51
|
+
if (this.listenerCount('error') > 0)
|
|
52
|
+
this.emit('error', { filePath, error });
|
|
39
53
|
});
|
|
40
54
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
stream.write(data, 'utf8', (error) => error ? reject(error) : resolve());
|
|
56
|
+
}));
|
|
57
|
+
this.pendingWrites.set(filePath, pending);
|
|
58
|
+
// Keep the tail until close, including failures; never reopen a failed log mid-run.
|
|
59
|
+
return pending;
|
|
60
|
+
}
|
|
61
|
+
async closeStream(filePath) {
|
|
62
|
+
const closing = this.closingStreams.get(filePath);
|
|
63
|
+
if (closing)
|
|
64
|
+
return closing;
|
|
65
|
+
const pending = this.pendingWrites.get(filePath);
|
|
66
|
+
const result = (async () => {
|
|
67
|
+
let failure;
|
|
68
|
+
try {
|
|
69
|
+
await pending;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
failure = error;
|
|
73
|
+
}
|
|
74
|
+
const stream = this.streams.get(filePath);
|
|
75
|
+
try {
|
|
76
|
+
if (stream && !this.closedStreams.has(stream)) {
|
|
77
|
+
await new Promise((resolve) => {
|
|
78
|
+
stream.once('close', resolve);
|
|
79
|
+
if (failure || stream.destroyed)
|
|
80
|
+
stream.destroy();
|
|
81
|
+
else
|
|
82
|
+
stream.end();
|
|
83
|
+
});
|
|
48
84
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
85
|
+
failure || (failure = this.streamErrors.get(filePath));
|
|
86
|
+
if (failure)
|
|
87
|
+
throw failure;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
this.streams.delete(filePath);
|
|
91
|
+
this.pendingWrites.delete(filePath);
|
|
92
|
+
this.streamErrors.delete(filePath);
|
|
55
93
|
}
|
|
56
|
-
});
|
|
57
|
-
this.
|
|
94
|
+
})();
|
|
95
|
+
this.closingStreams.set(filePath, result);
|
|
58
96
|
try {
|
|
59
|
-
await
|
|
97
|
+
await result;
|
|
60
98
|
}
|
|
61
99
|
finally {
|
|
62
|
-
this.
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Close the stream for a specific file path
|
|
67
|
-
* @param filePath - Absolute path to the log file
|
|
68
|
-
*/
|
|
69
|
-
async closeStream(filePath) {
|
|
70
|
-
// Wait for any pending writes to complete
|
|
71
|
-
const pending = this.pendingWrites.get(filePath);
|
|
72
|
-
if (pending) {
|
|
73
|
-
await pending.catch(() => {
|
|
74
|
-
// Ignore errors on pending writes during close
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const stream = this.streams.get(filePath);
|
|
78
|
-
if (stream) {
|
|
79
|
-
return new Promise((resolve) => {
|
|
80
|
-
stream.end(() => {
|
|
81
|
-
this.streams.delete(filePath);
|
|
82
|
-
resolve();
|
|
83
|
-
});
|
|
84
|
-
});
|
|
100
|
+
this.closingStreams.delete(filePath);
|
|
85
101
|
}
|
|
86
102
|
}
|
|
87
103
|
/**
|
|
88
104
|
* Close all open streams
|
|
89
105
|
*/
|
|
90
106
|
async closeAll() {
|
|
91
|
-
const
|
|
107
|
+
const paths = new Set([
|
|
108
|
+
...this.streams.keys(),
|
|
109
|
+
...this.pendingWrites.keys(),
|
|
110
|
+
]);
|
|
111
|
+
const closePromises = Array.from(paths).map((filePath) => this.closeStream(filePath));
|
|
92
112
|
await Promise.all(closePromises);
|
|
93
113
|
}
|
|
94
114
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyPassword = exports.isPasswordHash = exports.hashPassword = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
const deriveKey = (0, util_1.promisify)(crypto_1.scrypt);
|
|
7
|
+
const HASH_PREFIX = 'scrypt$';
|
|
8
|
+
async function hashPassword(password) {
|
|
9
|
+
const salt = (0, crypto_1.randomBytes)(16).toString('hex');
|
|
10
|
+
const key = (await deriveKey(password, salt, 64));
|
|
11
|
+
return `${HASH_PREFIX}${salt}$${key.toString('hex')}`;
|
|
12
|
+
}
|
|
13
|
+
exports.hashPassword = hashPassword;
|
|
14
|
+
function isPasswordHash(password) {
|
|
15
|
+
return /^scrypt\$[a-f0-9]{32}\$[a-f0-9]{128}$/.test(password);
|
|
16
|
+
}
|
|
17
|
+
exports.isPasswordHash = isPasswordHash;
|
|
18
|
+
async function verifyPassword(password, stored) {
|
|
19
|
+
if (!isPasswordHash(stored)) {
|
|
20
|
+
// Existing installations migrate after a successful password check.
|
|
21
|
+
const input = Buffer.from(password);
|
|
22
|
+
const expected = Buffer.from(stored);
|
|
23
|
+
return input.length === expected.length && (0, crypto_1.timingSafeEqual)(input, expected);
|
|
24
|
+
}
|
|
25
|
+
const [, salt, hash] = stored.split('$');
|
|
26
|
+
const key = (await deriveKey(password, salt, 64));
|
|
27
|
+
return (0, crypto_1.timingSafeEqual)(key, Buffer.from(hash, 'hex'));
|
|
28
|
+
}
|
|
29
|
+
exports.verifyPassword = verifyPassword;
|
|
30
|
+
//# sourceMappingURL=password.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDirectorySize = exports.isDependenceCacheType = exports.normalizeRetentionPolicy = exports.normalizeRetentionDays = exports.DEPENDENCE_CACHE_TYPES = exports.MAX_RETENTION_DAYS = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
exports.MAX_RETENTION_DAYS = 3650;
|
|
10
|
+
exports.DEPENDENCE_CACHE_TYPES = ['node', 'python3'];
|
|
11
|
+
function normalizeRetentionDays(value) {
|
|
12
|
+
const days = Number(value);
|
|
13
|
+
if (!Number.isFinite(days))
|
|
14
|
+
return 0;
|
|
15
|
+
return Math.min(Math.max(Math.trunc(days), 0), exports.MAX_RETENTION_DAYS);
|
|
16
|
+
}
|
|
17
|
+
exports.normalizeRetentionDays = normalizeRetentionDays;
|
|
18
|
+
function normalizeRetentionPolicy(policy) {
|
|
19
|
+
return {
|
|
20
|
+
runningInstanceRetentionDays: normalizeRetentionDays(policy.runningInstanceRetentionDays),
|
|
21
|
+
cronStatRetentionDays: normalizeRetentionDays(policy.cronStatRetentionDays),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.normalizeRetentionPolicy = normalizeRetentionPolicy;
|
|
25
|
+
function isDependenceCacheType(value) {
|
|
26
|
+
return exports.DEPENDENCE_CACHE_TYPES.includes(value);
|
|
27
|
+
}
|
|
28
|
+
exports.isDependenceCacheType = isDependenceCacheType;
|
|
29
|
+
async function getDirectorySize(rootPath) {
|
|
30
|
+
const pending = [rootPath];
|
|
31
|
+
let total = 0;
|
|
32
|
+
while (pending.length > 0) {
|
|
33
|
+
const currentPath = pending.pop();
|
|
34
|
+
let entries;
|
|
35
|
+
try {
|
|
36
|
+
entries = await promises_1.default.readdir(currentPath, { withFileTypes: true });
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 'ENOENT')
|
|
40
|
+
continue;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry.isSymbolicLink())
|
|
45
|
+
continue;
|
|
46
|
+
const entryPath = path_1.default.join(currentPath, entry.name);
|
|
47
|
+
if (entry.isDirectory()) {
|
|
48
|
+
pending.push(entryPath);
|
|
49
|
+
}
|
|
50
|
+
else if (entry.isFile()) {
|
|
51
|
+
total += (await promises_1.default.stat(entryPath)).size;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return total;
|
|
56
|
+
}
|
|
57
|
+
exports.getDirectorySize = getDirectorySize;
|
|
58
|
+
//# sourceMappingURL=retention.js.map
|
|
@@ -11,9 +11,10 @@ const cron_1 = require("../data/cron");
|
|
|
11
11
|
const util_1 = require("../config/util");
|
|
12
12
|
const runningInstance_1 = require("../data/runningInstance");
|
|
13
13
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
14
|
+
const childProcess_1 = require("./childProcess");
|
|
14
15
|
function runCron(cmd, cron) {
|
|
15
|
-
return pLimit_1.default.runWithCronLimit(cron, () => {
|
|
16
|
-
|
|
16
|
+
return pLimit_1.default.runWithCronLimit(cron, async () => {
|
|
17
|
+
try {
|
|
17
18
|
// Check if the cron is already running and stop it (only if multiple instances are not allowed)
|
|
18
19
|
try {
|
|
19
20
|
const existingCron = await cron_1.CrontabModel.findOne({
|
|
@@ -27,31 +28,43 @@ function runCron(cmd, cron) {
|
|
|
27
28
|
(existingCron.status === cron_1.CrontabStatus.running ||
|
|
28
29
|
existingCron.status === cron_1.CrontabStatus.queued)) {
|
|
29
30
|
logger_1.default.info(`[schedule][停止已运行任务] 任务ID: ${cron.id}, PID: ${existingCron.pid}`);
|
|
30
|
-
await (0, util_1.killTask)(existingCron.pid);
|
|
31
|
+
await (0, util_1.killTask)(existingCron.pid, true);
|
|
31
32
|
// Mark old running instances as stopped
|
|
32
33
|
const stoppedAt = (0, dayjs_1.default)().unix();
|
|
33
|
-
await runningInstance_1.RunningInstanceModel.update({ status: runningInstance_1.InstanceStatus.stopped, finished_at: stoppedAt }, {
|
|
34
|
+
await runningInstance_1.RunningInstanceModel.update({ status: runningInstance_1.InstanceStatus.stopped, finished_at: stoppedAt }, {
|
|
35
|
+
where: {
|
|
36
|
+
cron_id: Number(cron.id),
|
|
37
|
+
status: runningInstance_1.InstanceStatus.running,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
34
40
|
// Update the status to idle after killing
|
|
35
41
|
await cron_1.CrontabModel.update({ status: cron_1.CrontabStatus.idle, pid: undefined }, { where: { id: Number(cron.id) } });
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
catch (error) {
|
|
39
45
|
logger_1.default.error(`[schedule][检查已运行任务失败] 任务ID: ${cron.id}, 错误: ${error}`);
|
|
46
|
+
throw error;
|
|
40
47
|
}
|
|
41
48
|
logger_1.default.info(`[schedule][开始执行任务] 参数 ${JSON.stringify(Object.assign(Object.assign({}, cron), { command: cmd }))}`);
|
|
42
49
|
const cp = (0, cross_spawn_1.spawn)(cmd, { shell: '/bin/bash' });
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
const { completed } = (0, childProcess_1.observeChildProcess)(cp, {
|
|
51
|
+
onStderr: async (message) => {
|
|
52
|
+
logger_1.default.info('[schedule][任务标准错误] 命令: %s, 信息: %s', cmd, message);
|
|
53
|
+
},
|
|
45
54
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const result = await completed;
|
|
56
|
+
if (result.error) {
|
|
57
|
+
logger_1.default.error('[schedule][执行任务失败] 命令: %s, 错误: %s', cmd, result.error.message);
|
|
58
|
+
}
|
|
59
|
+
logger_1.default.info('[schedule][执行任务结束] 任务ID: %s, 退出码: %j', cron.id, result.code);
|
|
60
|
+
return Object.assign(Object.assign(Object.assign({}, cron), { command: cmd, pid: cp.pid }), result);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
logger_1.default.error('[schedule][创建任务失败] 命令: %s, 错误: %s', cmd, (0, childProcess_1.asError)(error).message);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
pLimit_1.default.removeQueuedCron(cron.id);
|
|
67
|
+
}
|
|
55
68
|
});
|
|
56
69
|
}
|
|
57
70
|
exports.runCron = runCron;
|