diff --git a/back/api/config.ts b/back/api/config.ts index 07473196..eaa4c4c5 100644 --- a/back/api/config.ts +++ b/back/api/config.ts @@ -48,27 +48,24 @@ export default (app: Router) => { ); route.get( - '/:file', + '/detail', async (req: Request, res: Response, next: NextFunction) => { const logger: Logger = Container.get('logger'); try { let content = ''; - if (config.blackFileList.includes(req.params.file)) { + const _path = req.query.path as string; + if (config.blackFileList.includes(_path) || !_path) { res.send({ code: 403, message: '文件无法访问' }); } - if (req.params.file.startsWith('sample/')) { + if (_path.startsWith('sample/')) { const res = await got.get( - `https://gitlab.com/whyour/qinglong/-/raw/master/${req.params.file}`, + `https://gitlab.com/whyour/qinglong/-/raw/master/${_path}`, ); content = res.body; - } else if (req.params.file.startsWith('data/scripts/')) { - content = await getFileContentByName( - join(config.rootPath, req.params.file), - ); + } else if (_path.startsWith('data/scripts/')) { + content = await getFileContentByName(join(config.rootPath, _path)); } else { - content = await getFileContentByName( - join(config.configPath, req.params.file), - ); + content = await getFileContentByName(join(config.configPath, _path)); } res.send({ code: 200, data: content }); } catch (e) { diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 75ed464c..db3032f0 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -9,6 +9,7 @@ import { Op } from 'sequelize'; import config from '../config'; import { CrontabViewModel, CronViewType } from '../data/cronView'; import { initPosition } from '../data/env'; +import { AuthDataType, SystemModel } from '../data/system'; export default async () => { const cronService = Container.get(CronService); @@ -127,4 +128,7 @@ export default async () => { // 初始化保存一次ck和定时任务数据 await cronService.autosave_crontab(); await envService.set_envs(); + + // 初始化增加系统配置 + await SystemModel.upsert({ type: AuthDataType.systemConfig }); }; diff --git a/back/services/system.ts b/back/services/system.ts index ba48ae3a..fbb3e433 100644 --- a/back/services/system.ts +++ b/back/services/system.ts @@ -284,7 +284,7 @@ export default class SystemService { } public async updateSystem() { - const cp = spawn('no_tee=true ql update false', { shell: '/bin/bash' }); + const cp = spawn('real_time=true ql update false', { shell: '/bin/bash' }); cp.stdout.on('data', (data) => { this.sockService.sendMessage({ @@ -311,7 +311,7 @@ export default class SystemService { } public async reloadSystem(target: 'system' | 'data') { - const cmd = `no_tee=true ql reload ${target || ''}`; + const cmd = `real_time=true ql reload ${target || ''}`; const cp = spawn(cmd, { shell: '/bin/bash' }); cp.stdout.on('data', (data) => { diff --git a/docker/Dockerfile b/docker/Dockerfile index 0231c523..c333fc3b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -40,6 +40,7 @@ RUN set -x \ openssh \ procps \ netcat-openbsd \ + unzip \ npm \ && rm -rf /var/cache/apk/* \ && apk update \ diff --git a/shell/update.sh b/shell/update.sh index 0fb280bc..4293e35f 100755 --- a/shell/update.sh +++ b/shell/update.sh @@ -476,6 +476,9 @@ main() { if [[ "$no_tee" == "true" ]]; then cmd=">> $file_path 2>&1" fi + if [[ "$real_time" == "true" ]]; then + cmd="" + fi local time_format="%Y-%m-%d %H:%M:%S" local time=$(date "+$time_format") diff --git a/src/pages/config/index.tsx b/src/pages/config/index.tsx index cf308882..cafc132d 100644 --- a/src/pages/config/index.tsx +++ b/src/pages/config/index.tsx @@ -30,11 +30,13 @@ const Config = () => { const [language, setLanguage] = useState('shell'); const getConfig = (name: string) => { - request.get(`${config.apiPrefix}configs/${name}`).then(({ code, data }) => { - if (code === 200) { - setValue(data); - } - }); + request + .get(`${config.apiPrefix}configs/detail?path=${encodeURIComponent(name)}`) + .then(({ code, data }) => { + if (code === 200) { + setValue(data); + } + }); }; const getFiles = () => { diff --git a/src/pages/diff/index.tsx b/src/pages/diff/index.tsx index d47b0cfa..5897cb2e 100644 --- a/src/pages/diff/index.tsx +++ b/src/pages/diff/index.tsx @@ -26,7 +26,7 @@ const Diff = () => { const getConfig = () => { request - .get(`${config.apiPrefix}configs/${encodeURIComponent(current)}`) + .get(`${config.apiPrefix}configs/detail?path=${encodeURIComponent(current)}`) .then(({ code, data }) => { if (code === 200) { setCurrentValue(data); @@ -36,7 +36,7 @@ const Diff = () => { const getSample = () => { request - .get(`${config.apiPrefix}configs/${encodeURIComponent(origin)}`) + .get(`${config.apiPrefix}configs/detail?path=${encodeURIComponent(origin)}`) .then(({ code, data }) => { if (code === 200) { setOriginValue(data); diff --git a/src/utils/config.ts b/src/utils/config.ts index 4d92e2df..2104082d 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -3,6 +3,7 @@ const baseUrl = window.__ENV__QlBaseUrl || '/'; export default { siteName: intl.get('青龙'), + baseUrl, apiPrefix: `${baseUrl}api/`, authKey: 'token', diff --git a/src/utils/init.ts b/src/utils/init.ts index 25743654..e7ff2ae2 100644 --- a/src/utils/init.ts +++ b/src/utils/init.ts @@ -1,5 +1,6 @@ import * as Sentry from '@sentry/react'; import { loader } from '@monaco-editor/react'; +import config from './config'; export function init(version: string) { // sentry监控 init @@ -26,7 +27,7 @@ export function init(version: string) { // monaco 编辑器配置cdn和locale loader.config({ paths: { - vs: '/monaco-editor/min/vs', + vs: `${config.baseUrl}monaco-editor/min/vs`, }, 'vs/nls': { availableLanguages: {