diff --git a/back/public.ts b/back/public.ts index 35f326e0..d9eb1cc7 100644 --- a/back/public.ts +++ b/back/public.ts @@ -13,9 +13,9 @@ const client = new HealthClient( app.get('/api/health', (req, res) => { client.check({ service: 'cron' }, (err, response) => { if (err) { - return res.status(500).send({ error: err }); + return res.status(500).send({ code: 500, error: err }); } - return res.status(200).send({ data: response }); + return res.status(200).send({ code: 200, data: response }); }); }); diff --git a/back/services/user.ts b/back/services/user.ts index 3eac0b76..c9fcd77f 100644 --- a/back/services/user.ts +++ b/back/services/user.ts @@ -1,6 +1,11 @@ import { Service, Inject } from 'typedi'; import winston from 'winston'; -import { createRandomString, getNetIp, getPlatform } from '../config/util'; +import { + createRandomString, + fileExist, + getNetIp, + getPlatform, +} from '../config/util'; import config from '../config'; import * as fs from 'fs'; import jwt from 'jsonwebtoken'; @@ -205,17 +210,16 @@ export default class UserService { } private initAuthInfo() { - const newPassword = createRandomString(16, 22); fs.writeFileSync( config.authConfigFile, JSON.stringify({ username: 'admin', - password: newPassword, + password: 'admin', }), ); return { code: 100, - message: '已初始化密码,请前往auth.json查看并重新登录', + message: '未找到认证文件,重新初始化', }; } @@ -240,13 +244,18 @@ export default class UserService { return { code: 200, data: avatar, message: '更新成功' }; } - public getUserInfo(): Promise { - return new Promise((resolve) => { - fs.readFile(config.authConfigFile, 'utf8', (err, data) => { - if (err) console.log(err); - resolve(JSON.parse(data)); - }); - }); + public async getUserInfo(): Promise { + const authFileExist = await fileExist(config.authConfigFile); + if (!authFileExist) { + fs.writeFileSync( + config.authConfigFile, + JSON.stringify({ + username: 'admin', + password: 'admin', + }), + ); + } + return this.getAuthInfo(); } public initTwoFactor() { diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index 484ebf27..cd78b04e 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -98,8 +98,7 @@ export default function () { }) .catch((error) => { console.log(error); - }) - .finally(() => setInitLoading(false)); + }); }; const getUser = (needLoading = true) => { @@ -120,6 +119,22 @@ export default function () { }); }; + const getHealthStatus = () => { + request + .get(`${config.apiPrefix}public/health`) + .then((res) => { + if (res?.data?.status === 1) { + getSystemInfo(); + } else { + history.push('/error'); + } + }) + .catch((error) => { + history.push('/error'); + }) + .finally(() => setInitLoading(false)); + }; + const reloadUser = (needLoading = false) => { getUser(needLoading); }; @@ -131,10 +146,8 @@ export default function () { }, [location.pathname]); useEffect(() => { - if (!systemInfo) { - getSystemInfo(); - } - }, [systemInfo]); + getHealthStatus(); + }, []); useEffect(() => { if (theme === 'vs-dark') { diff --git a/src/pages/error/index.less b/src/pages/error/index.less index 398773f6..7022be15 100644 --- a/src/pages/error/index.less +++ b/src/pages/error/index.less @@ -13,7 +13,8 @@ .code-box { position: relative; display: inline-block; - width: 80%; + width: 80vw; + height: 90vh; margin: 16px; background-color: #ffffff; border: 1px solid rgba(5, 5, 5, 0.06); diff --git a/src/pages/error/index.tsx b/src/pages/error/index.tsx index 9c899f22..0fe5f817 100644 --- a/src/pages/error/index.tsx +++ b/src/pages/error/index.tsx @@ -17,7 +17,7 @@ const Error = () => { needLoading && setLoading(true); request .get(`${config.apiPrefix}public/health`) - .then(({ status, error }) => { + .then(({ error, status }) => { if (status === 1) { return reloadUser(); } @@ -53,10 +53,32 @@ const Error = () => {
+ 服务启动超时 + + } + description={ + +
+ 请先按如下方式修复,如果无法解决,可结合日志 + + 提交 issue + +
+
+ 1. 宿主机执行 docker run --rm -v + /var/run/docker.sock:/var/run/docker.sock + containrrr/watchtower -cR <容器名> +
+
2. 容器内执行 ql -l check、ql -l update
+
+ } banner /> - {data} + + {data} + ) : ( diff --git a/src/pages/initialization/index.tsx b/src/pages/initialization/index.tsx index 2f1270fc..c45824a4 100644 --- a/src/pages/initialization/index.tsx +++ b/src/pages/initialization/index.tsx @@ -219,7 +219,7 @@ const Initialization = () => {