diff --git a/back/config/util.ts b/back/config/util.ts index 6e82ed3a..952ebf89 100644 --- a/back/config/util.ts +++ b/back/config/util.ts @@ -387,28 +387,22 @@ export function emptyDir(path: string) { fs.rmdirSync(path); } -export function promiseExec(command: string): Promise { - return new Promise((resolve, reject) => { - exec( - command, - { maxBuffer: 200 * 1024 * 1024, encoding: 'utf8' }, - (err, stdout, stderr) => { - resolve(stdout || stderr || JSON.stringify(err)); - }, - ); - }); +export async function promiseExec(command: string): Promise { + try { + const { stderr, stdout } = await promisify(exec)(command, { maxBuffer: 200 * 1024 * 1024, encoding: 'utf8' }); + return stdout || stderr; + } catch (error) { + return JSON.stringify(error); + } } -export function promiseExecSuccess(command: string): Promise { - return new Promise((resolve) => { - exec( - command, - { maxBuffer: 200 * 1024 * 1024, encoding: 'utf8' }, - (err, stdout, stderr) => { - resolve(stdout || ''); - }, - ); - }); +export async function promiseExecSuccess(command: string): Promise { + try { + const { stdout } = await promisify(exec)(command, { maxBuffer: 200 * 1024 * 1024, encoding: 'utf8' }); + return stdout || ''; + } catch (error) { + return ''; + } } export function parseHeaders(headers: string) { @@ -501,7 +495,7 @@ export async function killTask(pid: number) { [pid, ...pids].forEach((x) => { process.kill(x, 2); }); - } catch (error) {} + } catch (error) { } } else { process.kill(pid, 2); } diff --git a/back/loaders/deps.ts b/back/loaders/deps.ts index 3da8bfe8..26f450a8 100644 --- a/back/loaders/deps.ts +++ b/back/loaders/deps.ts @@ -37,7 +37,7 @@ async function linkCommand() { if (fs.existsSync(target)) { fs.unlinkSync(target); } - fs.symlink(source, target, (err) => {}); + fs.symlink(source, target, (err) => { }); } } diff --git a/back/schedule/health.ts b/back/schedule/health.ts index ddc8b5c6..bda0ec9b 100644 --- a/back/schedule/health.ts +++ b/back/schedule/health.ts @@ -24,7 +24,7 @@ const check = async ( `tail -n 300 ~/.pm2/logs/schedule-error.log`, ); return callback( - new Error(`${scheduleErrLog || ''}\n${panelErrLog || ''}\n${res}`), + new Error(`${scheduleErrLog || ''}\n${panelErrLog || ''}\n${res}`.trim()), ); default: diff --git a/src/app.ts b/src/app.ts index 4339670e..aae44ab3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -3,13 +3,17 @@ import intl from 'react-intl-universal'; export function rootContainer(container: any) { const locales = { - 'en-US': require('./locales/en-US.json'), - 'zh-CN': require('./locales/zh-CN.json'), + 'en': require('./locales/en-US.json'), + 'zh': require('./locales/zh-CN.json'), }; let currentLocale = intl.determineLocale({ urlLocaleKey: 'lang', cookieLocaleKey: 'lang', - }); + }).slice(0, 2); + + if (!currentLocale || !Object.keys(locales).includes(currentLocale)) { + currentLocale = 'zh'; + } intl.init({ currentLocale, locales }); return container; diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index b9a7d58e..5c3d95c3 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -47,7 +47,7 @@ const CronLogModal = ({ const log = data as string; setValue(log || intl.get('暂无日志')); const hasNext = Boolean( - log && !logEnded(log) && !log.includes(intl.get('任务未运行')), + log && !logEnded(log) && !log.includes('任务未运行'), ); setExecuting(hasNext); autoScroll(); diff --git a/src/pages/error/index.tsx b/src/pages/error/index.tsx index eff9af5b..30a5cc88 100644 --- a/src/pages/error/index.tsx +++ b/src/pages/error/index.tsx @@ -9,17 +9,22 @@ import { SharedContext } from '@/layouts'; import { Alert, Typography } from 'antd'; const Error = () => { - const { user, theme, reloadUser } = useOutletContext(); + const { user } = useOutletContext(); const [loading, setLoading] = useState(false); const [data, setData] = useState(intl.get('暂无日志')); const retryTimes = useRef(1); - const getLog = (needLoading: boolean = true) => { + const getHealthStatus = (needLoading: boolean = true) => { needLoading && setLoading(true); request .get(`${config.apiPrefix}public/health`) .then(({ error, data }) => { if (data?.status === 1) { + if (retryTimes.current > 1) { + setTimeout(() => { + window.location.reload(); + }); + } return; } if (retryTimes.current > 3) { @@ -28,7 +33,7 @@ const Error = () => { } retryTimes.current += 1; setTimeout(() => { - getLog(false); + getHealthStatus(false); }, 3000); }) .finally(() => needLoading && setLoading(false)); @@ -41,7 +46,7 @@ const Error = () => { }, [user]); useEffect(() => { - getLog(); + getHealthStatus(); }, []); return (