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

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) => {
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 });
});
});

View File

@ -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<any> {
return new Promise((resolve) => {
fs.readFile(config.authConfigFile, 'utf8', (err, data) => {
if (err) console.log(err);
resolve(JSON.parse(data));
});
});
public async getUserInfo(): Promise<any> {
const authFileExist = await fileExist(config.authConfigFile);
if (!authFileExist) {
fs.writeFileSync(
config.authConfigFile,
JSON.stringify({
username: 'admin',
password: 'admin',
}),
);
}
return this.getAuthInfo();
}
public initTwoFactor() {

View File

@ -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') {

View File

@ -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);

View File

@ -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 = () => {
<div className="browser-markup"></div>
<Alert
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
/>
<Typography.Paragraph className="log">{data}</Typography.Paragraph>
<Typography.Paragraph code className="log">
{data}
</Typography.Paragraph>
</div>
) : (
<PageLoading tip="启动中,请稍后..." />

View File

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