From 07951964a112e4facbc4314f811a38d0632531b8 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 26 Oct 2025 22:32:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A8=A1=E5=9D=97=E6=B3=A8?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/app.ts | 9 ++-- back/loaders/deps.ts | 10 ++-- back/loaders/initData.ts | 3 +- back/schedule/addCron.ts | 4 +- back/schedule/delCron.ts | 2 +- back/services/cron.ts | 2 +- back/services/schedule.ts | 8 ++-- back/services/sshKey.ts | 8 +++- back/services/subscription.ts | 2 +- package.json | 8 ++-- pnpm-lock.yaml | 86 ++++++++--------------------------- 11 files changed, 50 insertions(+), 92 deletions(-) diff --git a/back/app.ts b/back/app.ts index 2b01de26..35042d0c 100644 --- a/back/app.ts +++ b/back/app.ts @@ -91,7 +91,8 @@ class Application { } private async initializeDatabase() { - await require('./loaders/db').default(); + const dbLoader = await import('./loaders/db'); + await dbLoader.default(); } private setupMiddlewares() { @@ -181,14 +182,16 @@ class Application { const { HttpServerService } = await import('./services/http'); this.httpServerService = Container.get(HttpServerService); - await require('./loaders/app').default({ app: this.app }); + const appLoader = await import('./loaders/app'); + await appLoader.default({ app: this.app }); const server = await this.httpServerService.initialize( this.app, config.port, ); - await require('./loaders/server').default({ server }); + const serverLoader = await import('./loaders/server'); + await (serverLoader.default as any)({ server }); this.setupWorkerShutdown('http'); } diff --git a/back/loaders/deps.ts b/back/loaders/deps.ts index 4f81a4f4..767b9dfd 100644 --- a/back/loaders/deps.ts +++ b/back/loaders/deps.ts @@ -36,10 +36,12 @@ async function linkCommand() { const source = path.join(config.rootPath, 'shell', link.src); const target = path.join(commandDir, link.dest); const tmpTarget = path.join(commandDir, link.tmp); - const stats = await fs.lstat(tmpTarget); - if (stats) { - await fs.unlink(tmpTarget); - } + try { + const stats = await fs.lstat(tmpTarget); + if (stats) { + await fs.unlink(tmpTarget); + } + } catch (error) { } await fs.symlink(source, tmpTarget); await fs.rename(tmpTarget, target); } diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 31f59811..f8b5315a 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -89,7 +89,8 @@ export default async () => { setTimeout(async () => { await dependenceService.installDependenceOneByOne(docs); - require('./bootAfter').default(); + const bootAfterLoader = await import('./bootAfter'); + bootAfterLoader.default(); }, 5000); }; diff --git a/back/schedule/addCron.ts b/back/schedule/addCron.ts index 69f641d6..a8e2e9fb 100644 --- a/back/schedule/addCron.ts +++ b/back/schedule/addCron.ts @@ -16,7 +16,7 @@ const addCron = ( } Logger.info( - '[schedule][创建定时任务], 任务ID: %s, 名称: %s, cron: %s, 执行命令: %s', + '[schedule][创建定时任务] 任务ID: %s, 名称: %s, cron: %s, 执行命令: %s', id, name, schedule, @@ -26,7 +26,7 @@ const addCron = ( if (extra_schedules?.length) { extra_schedules.forEach((x) => { Logger.info( - '[schedule][创建定时任务], 任务ID: %s, 名称: %s, cron: %s, 执行命令: %s', + '[schedule][创建定时任务] 任务ID: %s, 名称: %s, cron: %s, 执行命令: %s', id, name, x.schedule, diff --git a/back/schedule/delCron.ts b/back/schedule/delCron.ts index 91daee32..6e35c080 100644 --- a/back/schedule/delCron.ts +++ b/back/schedule/delCron.ts @@ -10,7 +10,7 @@ const delCron = ( for (const id of call.request.ids) { if (scheduleStacks.has(id)) { Logger.info( - '[schedule][取消定时任务], 任务ID: %s', + '[schedule][取消定时任务] 任务ID: %s', id, ); scheduleStacks.get(id)?.forEach(x => x.cancel()); diff --git a/back/services/cron.ts b/back/services/cron.ts index 28cad2cd..a838ce9e 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -593,7 +593,7 @@ export default class CronService { files.map(async (x) => ({ filename: x, directory: relativeDir.replace(config.logPath, ''), - time: (await fs.lstat(`${dir}/${x}`)).mtime.getTime(), + time: (await fs.lstat(`${dir}/${x}`)).birthtimeMs, })), ) ).sort((a, b) => b.time - a.time); diff --git a/back/services/schedule.ts b/back/services/schedule.ts index fb68af43..df938674 100644 --- a/back/services/schedule.ts +++ b/back/services/schedule.ts @@ -139,7 +139,7 @@ export default class ScheduleService { ) { const _id = this.formatId(id); this.logger.info( - '[panel][创建cron任务], 任务ID: %s, cron: %s, 任务名: %s, 执行命令: %s', + '[panel][创建cron任务] 任务ID: %s, cron: %s, 任务名: %s, 执行命令: %s', _id, schedule, name, @@ -172,7 +172,7 @@ export default class ScheduleService { async cancelCronTask({ id = 0, name }: ScheduleTaskType) { const _id = this.formatId(id); - this.logger.info('[panel][取消定时任务], 任务名: %s', name); + this.logger.info('[panel][取消定时任务] 任务名: %s', name); if (this.scheduleStacks.has(_id)) { this.scheduleStacks.get(_id)?.cancel(); this.scheduleStacks.delete(_id); @@ -187,7 +187,7 @@ export default class ScheduleService { ) { const _id = this.formatId(id); this.logger.info( - '[panel][创建interval任务], 任务ID: %s, 任务名: %s, 执行命令: %s', + '[panel][创建interval任务] 任务ID: %s, 任务名: %s, 执行命令: %s', _id, name, command, @@ -232,7 +232,7 @@ export default class ScheduleService { async cancelIntervalTask({ id = 0, name }: ScheduleTaskType) { const _id = this.formatId(id); this.logger.info( - '[panel][取消interval任务], 任务ID: %s, 任务名: %s', + '[panel][取消interval任务] 任务ID: %s, 任务名: %s', _id, name, ); diff --git a/back/services/sshKey.ts b/back/services/sshKey.ts index 0a2824c9..a453e34d 100644 --- a/back/services/sshKey.ts +++ b/back/services/sshKey.ts @@ -26,12 +26,13 @@ export default class SshKeyService { if (_exist) { config = await fs.readFile(this.sshConfigFilePath, { encoding: 'utf-8' }); } else { - await writeFileWithLock(this.sshConfigFilePath, ''); + await writeFileWithLock(this.sshConfigFilePath, '', { mode: '600' }); } if (!config.includes(this.sshConfigHeader)) { await writeFileWithLock( this.sshConfigFilePath, `${this.sshConfigHeader}\n\n${config}`, + { mode: '600' }, ); } } @@ -45,7 +46,6 @@ export default class SshKeyService { path.join(this.sshPath, alias), `${key}${os.EOL}`, { - encoding: 'utf8', mode: '400', }, ); @@ -81,6 +81,10 @@ export default class SshKeyService { await writeFileWithLock( `${path.join(this.sshPath, `${alias}.config`)}`, config, + { + encoding: 'utf8', + mode: '600', + }, ); } diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 039b0819..5b13161b 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -384,7 +384,7 @@ export default class SubscriptionService { files.map(async (x) => ({ filename: x, directory: relativeDir.replace(config.logPath, ''), - time: (await fs.lstat(`${dir}/${x}`)).mtime.getTime(), + time: (await fs.lstat(`${dir}/${x}`)).birthtimeMs, })), ) ).sort((a, b) => b.time - a.time); diff --git a/package.json b/package.json index d566efa6..9bec3428 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "build:back": "tsc -p back/tsconfig.json", "panel": "npm run build:back && node static/build/app.js", "gen:proto": "protoc --experimental_allow_proto3_optional --plugin=./node_modules/.bin/protoc-gen-ts_proto ./back/protos/*.proto --ts_proto_out=./ --ts_proto_opt=outputServices=grpc-js,env=node,esModuleInterop=true,snakeToCamel=false", - "gen:api": "python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. ./back/protos/api.proto", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", "postinstall": "max setup 2>/dev/null || true", "test": "umi-test", @@ -55,8 +54,8 @@ } }, "dependencies": { - "@grpc/grpc-js": "^1.12.3", - "@grpc/proto-loader": "^0.7.13", + "@grpc/grpc-js": "^1.14.0", + "@grpc/proto-loader": "^0.8.0", "@otplib/preset-default": "^12.0.1", "body-parser": "^1.20.3", "celebrate": "^15.0.3", @@ -81,11 +80,10 @@ "node-schedule": "^2.1.0", "nodemailer": "^6.9.16", "p-queue-cjs": "7.3.4", - "@bufbuild/protobuf": "^2.2.3", + "@bufbuild/protobuf": "^2.10.0", "ps-tree": "^1.2.0", "reflect-metadata": "^0.2.2", "sequelize": "^6.37.5", - "serve-handler": "^6.1.6", "sockjs": "^0.3.24", "sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.3", "toad-scheduler": "^3.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 200f7938..5177ec06 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,14 +9,14 @@ overrides: dependencies: '@bufbuild/protobuf': - specifier: ^2.2.3 - version: 2.2.3 + specifier: ^2.10.0 + version: 2.10.0 '@grpc/grpc-js': - specifier: ^1.12.3 - version: 1.12.3 + specifier: ^1.14.0 + version: 1.14.0 '@grpc/proto-loader': - specifier: ^0.7.13 - version: 0.7.13 + specifier: ^0.8.0 + version: 0.8.0 '@keyv/sqlite': specifier: ^4.0.1 version: 4.0.1 @@ -116,9 +116,6 @@ dependencies: sequelize: specifier: ^6.37.5 version: 6.37.5(@whyour/sqlite3@1.0.3) - serve-handler: - specifier: ^6.1.6 - version: 6.1.6 sockjs: specifier: ^0.3.24 version: 0.3.24 @@ -1389,8 +1386,8 @@ packages: resolution: {integrity: sha512-h0OYmPR3A5Dfbetra/GzxBAzQk8sH7LhRkRUTdagX6nrtlUgJGYCTv4bBK33jsTQw9HDd8PE2x1Ma+iRKEDUsw==} dev: true - /@bufbuild/protobuf@2.2.3: - resolution: {integrity: sha512-tFQoXHJdkEOSwj5tRIZSPNUuXK3RaR7T1nUrPgbYX1pUbvqqaaZAsfo+NXBPsz5rZMSKVFrgK1WL8Q/MSLvprg==} + /@bufbuild/protobuf@2.10.0: + resolution: {integrity: sha512-fdRs9PSrBF7QUntpZpq6BTw58fhgGJojgg39m9oFOJGZT+nip9b0so5cYY1oWl5pvemDLr0cPPsH46vwThEbpQ==} /@chenshuai2144/sketch-color@1.0.9(react@18.3.1): resolution: {integrity: sha512-obzSy26cb7Pm7OprWyVpgMpIlrZpZ0B7vbrU0RMbvRg0YAI890S5Xy02Aj1Nhl4+KTbi1lVYHt6HQP8Hm9s+1w==} @@ -2585,22 +2582,22 @@ packages: dev: false optional: true - /@grpc/grpc-js@1.12.3: - resolution: {integrity: sha512-iaxAZnANdCwMNpJlyhkI1W1jQZIDZKFNtU2OpQDdgd+pBcU3t7G+PT7svobkW4WSZTdis+CVV6y8KIwu83HDYQ==} + /@grpc/grpc-js@1.14.0: + resolution: {integrity: sha512-N8Jx6PaYzcTRNzirReJCtADVoq4z7+1KQ4E70jTg/koQiMoUSN1kbNjPOqpPbhMFhfU1/l7ixspPl8dNY+FoUg==} engines: {node: '>=12.10.0'} dependencies: - '@grpc/proto-loader': 0.7.13 + '@grpc/proto-loader': 0.8.0 '@js-sdsl/ordered-map': 4.4.2 dev: false - /@grpc/proto-loader@0.7.13: - resolution: {integrity: sha512-AiXO/bfe9bmxBjxxtYxFAXGZvMaN5s8kO+jBHAJCON8rJoB5YS/D6X7ZNc6XQkuHNmyl4CYaMI1fJ/Gn27RGGw==} + /@grpc/proto-loader@0.8.0: + resolution: {integrity: sha512-rc1hOQtjIWGxcxpb9aHAfLpIctjEnsDehj0DAiVfBlmT84uvR0uUtN2hEi/ecvWVjXUGf5qPF4qEgiLOx1YIMQ==} engines: {node: '>=6'} hasBin: true dependencies: lodash.camelcase: 4.3.0 long: 5.2.3 - protobufjs: 7.4.0 + protobufjs: 7.5.4 yargs: 17.7.2 dev: false @@ -5962,11 +5959,6 @@ packages: streamsearch: 1.1.0 dev: false - /bytes@3.0.0: - resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==} - engines: {node: '>= 0.8'} - dev: false - /bytes@3.1.2: resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==} engines: {node: '>= 0.8'} @@ -6384,11 +6376,6 @@ packages: resolution: {integrity: sha512-xFxOwqIzR/e1k1gLiWEophSCMqXcwVHIH7akf7b/vxcUeGunlj3hvZaaqxwHsTgn+IndtkQJgSztIDWeumWJDQ==} dev: true - /content-disposition@0.5.2: - resolution: {integrity: sha512-kRGRZw3bLlFISDBgwTSA1TMBFN6J6GWDeubmDE3AF+3+yXL8hTWv8r5rkLbqYXY4RjPk/EzHnClI3zQf1cFmHA==} - engines: {node: '>= 0.6'} - dev: false - /content-disposition@0.5.4: resolution: {integrity: sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==} engines: {node: '>= 0.6'} @@ -9961,11 +9948,6 @@ packages: brorand: 1.1.0 dev: true - /mime-db@1.33.0: - resolution: {integrity: sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==} - engines: {node: '>= 0.6'} - dev: false - /mime-db@1.52.0: resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} engines: {node: '>= 0.6'} @@ -9974,13 +9956,6 @@ packages: resolution: {integrity: sha512-oHlN/w+3MQ3rba9rqFr6V/ypF10LSkdwUysQL7GkXoTgIWeV+tcXGA852TBxH+gsh8UWoyhR1hKcoMJTuWflpg==} engines: {node: '>= 0.6'} - /mime-types@2.1.18: - resolution: {integrity: sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==} - engines: {node: '>= 0.6'} - dependencies: - mime-db: 1.33.0 - dev: false - /mime-types@2.1.35: resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} engines: {node: '>= 0.6'} @@ -10776,10 +10751,6 @@ packages: engines: {node: '>=0.10.0'} requiresBuild: true - /path-is-inside@1.0.2: - resolution: {integrity: sha512-DUWJr3+ULp4zXmol/SZkFf3JGsS9/SIv+Y3Rt93/UjPpDpklB5f1er4O3POIbUuUJ3FXgqte2Q7SrU6zAqwk8w==} - dev: false - /path-key@3.1.1: resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} engines: {node: '>=8'} @@ -10814,10 +10785,6 @@ packages: resolution: {integrity: sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==} dev: true - /path-to-regexp@3.3.0: - resolution: {integrity: sha512-qyCH421YQPS2WFDxDjftfc1ZR5WKQzVzqsp4n9M2kQhVOo/ByahFoUNJfl58kOcEGfQ//7weFTDhm+ss8Ecxgw==} - dev: false - /path-to-regexp@6.3.0: resolution: {integrity: sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==} dev: false @@ -11603,8 +11570,8 @@ packages: signal-exit: 3.0.7 dev: false - /protobufjs@7.4.0: - resolution: {integrity: sha512-mRUWCc3KUU4w1jU8sGxICXH/gNS94DvI1gxqDvBzhj1JpcsimQkYiOJfwsPUykUI5ZaspFbSgmBLER8IrQ3tqw==} + /protobufjs@7.5.4: + resolution: {integrity: sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg==} engines: {node: '>=12.0.0'} requiresBuild: true dependencies: @@ -11808,11 +11775,6 @@ packages: safe-buffer: 5.2.1 dev: true - /range-parser@1.2.0: - resolution: {integrity: sha512-kA5WQoNVo4t9lNx2kQNFCxKeBl5IbbSNBl1M/tLkw9WCn+hxNBAW5Qh8gdhs63CJnhjJ2zQWFoqPJP2sK1AV5A==} - engines: {node: '>= 0.6'} - dev: false - /range-parser@1.2.1: resolution: {integrity: sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==} engines: {node: '>= 0.6'} @@ -13412,18 +13374,6 @@ packages: randombytes: 2.1.0 dev: true - /serve-handler@6.1.6: - resolution: {integrity: sha512-x5RL9Y2p5+Sh3D38Fh9i/iQ5ZK+e4xuXRd/pGbM4D13tgo/MGwbttUk8emytcr1YYzBYs+apnUngBDFYfpjPuQ==} - dependencies: - bytes: 3.0.0 - content-disposition: 0.5.2 - mime-types: 2.1.18 - minimatch: 3.1.2 - path-is-inside: 1.0.2 - path-to-regexp: 3.3.0 - range-parser: 1.2.0 - dev: false - /serve-static@1.16.2: resolution: {integrity: sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==} engines: {node: '>= 0.8.0'} @@ -14383,14 +14333,14 @@ packages: /ts-proto-descriptors@2.0.0: resolution: {integrity: sha512-wHcTH3xIv11jxgkX5OyCSFfw27agpInAd6yh89hKG6zqIXnjW9SYqSER2CVQxdPj4czeOhGagNvZBEbJPy7qkw==} dependencies: - '@bufbuild/protobuf': 2.2.3 + '@bufbuild/protobuf': 2.10.0 dev: true /ts-proto@2.6.1: resolution: {integrity: sha512-4LTT99MkwkF1+fIA0b2mZu/58Qlpq3Q1g53TwEMZZgR1w/uX00PoVT4Z8aKJxMw0LeKQD4s9NrJYsF27Clckrg==} hasBin: true dependencies: - '@bufbuild/protobuf': 2.2.3 + '@bufbuild/protobuf': 2.10.0 case-anything: 2.1.13 ts-poet: 6.9.0 ts-proto-descriptors: 2.0.0