修改初始系统状态逻辑已经错误页面

This commit is contained in:
whyour 2023-05-07 23:40:37 +08:00
parent 481646501c
commit f66390eabd
6 changed files with 69 additions and 24 deletions

View File

@ -13,9 +13,9 @@ const client = new HealthClient(
app.get('/api/health', (req, res) => { app.get('/api/health', (req, res) => {
client.check({ service: 'cron' }, (err, response) => { client.check({ service: 'cron' }, (err, response) => {
if (err) { 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 });
}); });
}); });

View File

@ -1,6 +1,11 @@
import { Service, Inject } from 'typedi'; import { Service, Inject } from 'typedi';
import winston from 'winston'; import winston from 'winston';
import { createRandomString, getNetIp, getPlatform } from '../config/util'; import {
createRandomString,
fileExist,
getNetIp,
getPlatform,
} from '../config/util';
import config from '../config'; import config from '../config';
import * as fs from 'fs'; import * as fs from 'fs';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
@ -205,17 +210,16 @@ export default class UserService {
} }
private initAuthInfo() { private initAuthInfo() {
const newPassword = createRandomString(16, 22);
fs.writeFileSync( fs.writeFileSync(
config.authConfigFile, config.authConfigFile,
JSON.stringify({ JSON.stringify({
username: 'admin', username: 'admin',
password: newPassword, password: 'admin',
}), }),
); );
return { return {
code: 100, code: 100,
message: '已初始化密码请前往auth.json查看并重新登录', message: '未找到认证文件,重新初始化',
}; };
} }
@ -240,13 +244,18 @@ export default class UserService {
return { code: 200, data: avatar, message: '更新成功' }; return { code: 200, data: avatar, message: '更新成功' };
} }
public getUserInfo(): Promise<any> { public async getUserInfo(): Promise<any> {
return new Promise((resolve) => { const authFileExist = await fileExist(config.authConfigFile);
fs.readFile(config.authConfigFile, 'utf8', (err, data) => { if (!authFileExist) {
if (err) console.log(err); fs.writeFileSync(
resolve(JSON.parse(data)); config.authConfigFile,
}); JSON.stringify({
}); username: 'admin',
password: 'admin',
}),
);
}
return this.getAuthInfo();
} }
public initTwoFactor() { public initTwoFactor() {

View File

@ -98,8 +98,7 @@ export default function () {
}) })
.catch((error) => { .catch((error) => {
console.log(error); console.log(error);
}) });
.finally(() => setInitLoading(false));
}; };
const getUser = (needLoading = true) => { 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) => { const reloadUser = (needLoading = false) => {
getUser(needLoading); getUser(needLoading);
}; };
@ -131,10 +146,8 @@ export default function () {
}, [location.pathname]); }, [location.pathname]);
useEffect(() => { useEffect(() => {
if (!systemInfo) { getHealthStatus();
getSystemInfo(); }, []);
}
}, [systemInfo]);
useEffect(() => { useEffect(() => {
if (theme === 'vs-dark') { if (theme === 'vs-dark') {

View File

@ -13,7 +13,8 @@
.code-box { .code-box {
position: relative; position: relative;
display: inline-block; display: inline-block;
width: 80%; width: 80vw;
height: 90vh;
margin: 16px; margin: 16px;
background-color: #ffffff; background-color: #ffffff;
border: 1px solid rgba(5, 5, 5, 0.06); border: 1px solid rgba(5, 5, 5, 0.06);

View File

@ -17,7 +17,7 @@ const Error = () => {
needLoading && setLoading(true); needLoading && setLoading(true);
request request
.get(`${config.apiPrefix}public/health`) .get(`${config.apiPrefix}public/health`)
.then(({ status, error }) => { .then(({ error, status }) => {
if (status === 1) { if (status === 1) {
return reloadUser(); return reloadUser();
} }
@ -53,10 +53,32 @@ const Error = () => {
<div className="browser-markup"></div> <div className="browser-markup"></div>
<Alert <Alert
type="error" type="error"
message="服务启动超时,请检查如下日志或者进入容器执行 ql -l check 后刷新再试" message={
<Typography.Title level={5} type="danger">
</Typography.Title>
}
description={
<Typography.Text type="danger">
<div>
<Typography.Link href="https://github.com/whyour/qinglong/issues/new?assignees=&labels=&template=bug_report.yml">
issue
</Typography.Link>
</div>
<div>
1. 宿 docker run --rm -v
/var/run/docker.sock:/var/run/docker.sock
containrrr/watchtower -cR &lt;&gt;
</div>
<div>2. ql -l checkql -l update</div>
</Typography.Text>
}
banner banner
/> />
<Typography.Paragraph className="log">{data}</Typography.Paragraph> <Typography.Paragraph code className="log">
{data}
</Typography.Paragraph>
</div> </div>
) : ( ) : (
<PageLoading tip="启动中,请稍后..." /> <PageLoading tip="启动中,请稍后..." />

View File

@ -219,7 +219,7 @@ const Initialization = () => {
<Button <Button
type="primary" type="primary"
onClick={() => { onClick={() => {
history.push('/login'); window.location.reload();
}} }}
> >