diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index db3032f0..59bdf357 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -10,11 +10,31 @@ import config from '../config'; import { CrontabViewModel, CronViewType } from '../data/cronView'; import { initPosition } from '../data/env'; import { AuthDataType, SystemModel } from '../data/system'; +import SystemService from '../services/system'; export default async () => { const cronService = Container.get(CronService); const envService = Container.get(EnvService); const dependenceService = Container.get(DependenceService); + const systemService = Container.get(SystemService); + + // 初始化更新 linux/python/nodejs 镜像源配置 + const systemConfig = await systemService.getSystemConfig(); + if (systemConfig.info?.pythonMirror) { + systemService.updatePythonMirror({ + linuxMirror: systemConfig.info?.linuxMirror, + }); + } + if (systemConfig.info?.linuxMirror) { + systemService.updateLinuxMirror({ + linuxMirror: systemConfig.info?.linuxMirror, + }); + } + if (systemConfig.info?.nodeMirror) { + systemService.updateNodeMirror({ + linuxMirror: systemConfig.info?.linuxMirror, + }); + } // 初始化新增默认全部任务视图 CrontabViewModel.findAll({ @@ -46,7 +66,9 @@ export default async () => { { status: DependenceStatus.queued, log: [] }, { where: { id: docs.map((x) => x.id!) } }, ); - dependenceService.installDependenceOneByOne(docs); + setTimeout(() => { + dependenceService.installDependenceOneByOne(docs); + }, 5000); }); // 初始化时执行一次所有的 ql repo 任务 diff --git a/back/services/system.ts b/back/services/system.ts index fbb3e433..09cf6ee0 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -126,7 +126,7 @@ export default class SystemService { return { code: 200, data: info }; } - public async updateNodeMirror(info: SystemModelInfo, res: Response) { + public async updateNodeMirror(info: SystemModelInfo, res?: Response) { const oDoc = await this.getSystemConfig(); await this.updateAuthDb({ ...oDoc, @@ -141,8 +141,8 @@ export default class SystemService { command, { onStart: async (cp) => { - res.setHeader('QL-Task-Pid', `${cp.pid}`); - res.end(); + res?.setHeader('QL-Task-Pid', `${cp.pid}`); + res?.end(); }, onEnd: async () => { this.sockService.sendMessage({ @@ -177,7 +177,7 @@ export default class SystemService { return { code: 200, data: info }; } - public async updateLinuxMirror(info: SystemModelInfo, res: Response) { + public async updateLinuxMirror(info: SystemModelInfo, res?: Response) { const oDoc = await this.getSystemConfig(); await this.updateAuthDb({ ...oDoc, @@ -203,8 +203,8 @@ export default class SystemService { command, { onStart: async (cp) => { - res.setHeader('QL-Task-Pid', `${cp.pid}`); - res.end(); + res?.setHeader('QL-Task-Pid', `${cp.pid}`); + res?.end(); }, onEnd: async () => { this.sockService.sendMessage({