mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-29 20:26:11 +08:00
检测更新增加强制更新
This commit is contained in:
parent
7cba2cf76c
commit
e19d2412fc
|
@ -5,7 +5,7 @@ import { createRandomString } from './util';
|
||||||
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
const lastVersionFile =
|
const lastVersionFile =
|
||||||
'https://ghproxy.com/https://raw.githubusercontent.com/whyour/qinglong/master/src/version.ts';
|
'https://raw.githubusercontent.com/whyour/qinglong/master/src/version.ts';
|
||||||
|
|
||||||
const envFound = dotenv.config();
|
const envFound = dotenv.config();
|
||||||
const rootPath = process.cwd();
|
const rootPath = process.cwd();
|
||||||
|
|
|
@ -403,13 +403,22 @@ export default class UserService {
|
||||||
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
|
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
|
||||||
const currentVersion = currentVersionFile.match(versionRegx)![1];
|
const currentVersion = currentVersionFile.match(versionRegx)![1];
|
||||||
|
|
||||||
const lastVersionFileContent = await (
|
let lastVersion = '';
|
||||||
await got.get(config.lastVersionFile)
|
let lastLog = '';
|
||||||
).body;
|
try {
|
||||||
const lastVersion = lastVersionFileContent.match(versionRegx)![1];
|
const result = await Promise.race([
|
||||||
const lastLog = lastVersionFileContent.match(logRegx)
|
got.get(config.lastVersionFile, { timeout: 1000, retry: 0 }),
|
||||||
? lastVersionFileContent.match(logRegx)![1]
|
got.get(`https://ghproxy.com/${config.lastVersionFile}`, {
|
||||||
: '';
|
timeout: 5000,
|
||||||
|
retry: 0,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
const lastVersionFileContent = result.body;
|
||||||
|
lastVersion = lastVersionFileContent.match(versionRegx)![1];
|
||||||
|
lastLog = lastVersionFileContent.match(logRegx)
|
||||||
|
? lastVersionFileContent.match(logRegx)![1]
|
||||||
|
: '';
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
|
|
|
@ -24,7 +24,7 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
||||||
if (data.hasNewVersion) {
|
if (data.hasNewVersion) {
|
||||||
showConfirmUpdateModal(data);
|
showConfirmUpdateModal(data);
|
||||||
} else {
|
} else {
|
||||||
message.success('已经是最新版了!');
|
showForceUpdateModal();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message.error(data);
|
message.error(data);
|
||||||
|
@ -39,6 +39,32 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showForceUpdateModal = () => {
|
||||||
|
Modal.confirm({
|
||||||
|
width: 500,
|
||||||
|
title: '更新',
|
||||||
|
content: (
|
||||||
|
<>
|
||||||
|
<div>已经是最新版了!</div>
|
||||||
|
<div style={{ fontSize: 12, fontWeight: 400, marginTop: 5 }}>
|
||||||
|
青龙 {version} 是目前检测到的最新可用版本了。
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
okText: '确认',
|
||||||
|
cancelText: '强制更新',
|
||||||
|
onCancel() {
|
||||||
|
showUpdatingModal();
|
||||||
|
request
|
||||||
|
.put(`${config.apiPrefix}system/update`)
|
||||||
|
.then((_data: any) => {})
|
||||||
|
.catch((error: any) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const showConfirmUpdateModal = (data: any) => {
|
const showConfirmUpdateModal = (data: any) => {
|
||||||
const { lastVersion, lastLog } = data;
|
const { lastVersion, lastLog } = data;
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user