diff --git a/back/config/index.ts b/back/config/index.ts index 61e89eb5..e5ac7562 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -5,7 +5,7 @@ import { createRandomString } from './util'; process.env.NODE_ENV = process.env.NODE_ENV || 'development'; 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 rootPath = process.cwd(); diff --git a/back/services/user.ts b/back/services/user.ts index 37996613..31ca8ea2 100644 --- a/back/services/user.ts +++ b/back/services/user.ts @@ -403,13 +403,22 @@ export default class UserService { const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8'); const currentVersion = currentVersionFile.match(versionRegx)![1]; - const lastVersionFileContent = await ( - await got.get(config.lastVersionFile) - ).body; - const lastVersion = lastVersionFileContent.match(versionRegx)![1]; - const lastLog = lastVersionFileContent.match(logRegx) - ? lastVersionFileContent.match(logRegx)![1] - : ''; + let lastVersion = ''; + let lastLog = ''; + try { + const result = await Promise.race([ + got.get(config.lastVersionFile, { timeout: 1000, retry: 0 }), + 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 { code: 200, diff --git a/src/pages/setting/checkUpdate.tsx b/src/pages/setting/checkUpdate.tsx index cc12ca6b..4eb6a928 100644 --- a/src/pages/setting/checkUpdate.tsx +++ b/src/pages/setting/checkUpdate.tsx @@ -24,7 +24,7 @@ const CheckUpdate = ({ socketMessage }: any) => { if (data.hasNewVersion) { showConfirmUpdateModal(data); } else { - message.success('已经是最新版了!'); + showForceUpdateModal(); } } else { message.error(data); @@ -39,6 +39,32 @@ const CheckUpdate = ({ socketMessage }: any) => { }); }; + const showForceUpdateModal = () => { + Modal.confirm({ + width: 500, + title: '更新', + content: ( + <> +