diff --git a/back/services/user.ts b/back/services/user.ts index 74a95c67..80408cc4 100644 --- a/back/services/user.ts +++ b/back/services/user.ts @@ -351,7 +351,7 @@ export default class UserService { public async getNotificationMode(): Promise { const doc = await this.getDb({ type: AuthDataType.notification }); - return doc.info as NotificationInfo; + return (doc.info || {}) as NotificationInfo; } private async updateAuthDb(payload: SystemInfo): Promise { diff --git a/sample/notify.js b/sample/notify.js index 0379fba6..9a2ca41a 100644 --- a/sample/notify.js +++ b/sample/notify.js @@ -97,7 +97,6 @@ const push_config = { WEBHOOK_CONTENT_TYPE: '', // 自定义通知 content-type }; -// 首先读取 面板变量 或者 github action 运行变量 for (const key in push_config) { const v = process.env[key]; if (v) { @@ -1290,7 +1289,7 @@ async function sendNotify(text, desp, params = {}) { } } - if (push_config.HITOKOTO) { + if (push_config.HITOKOTO !== 'false') { desp += '\n\n' + (await one()); } diff --git a/sample/notify.py b/sample/notify.py index fe3bb53e..4c87cd9b 100644 --- a/sample/notify.py +++ b/sample/notify.py @@ -120,7 +120,6 @@ push_config = { } # fmt: on -# 首先读取 面板变量 或者 github action 运行变量 for k in push_config: if os.getenv(k): v = os.getenv(k) @@ -962,7 +961,7 @@ def send(title: str, content: str, ignore_default_config: bool = False, **kwargs return hitokoto = push_config.get("HITOKOTO") - content += "\n\n" + one() if hitokoto else "" + content += "\n\n" + one() if hitokoto != "false" else "" notify_function = add_notify_function() ts = [ diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 4aa3ee02..c83ff1a2 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -57,6 +57,7 @@ import { useVT } from 'virtualizedtableforantd4'; import { ICrontab, OperationName, OperationPath, CrontabStatus } from './type'; import Name from '@/components/name'; import dayjs from 'dayjs'; +import { noop } from 'lodash'; const { Text, Paragraph, Link } = Typography; const { Search } = Input; @@ -76,7 +77,7 @@ const Crontab = () => { wordBreak: 'break-all', marginBottom: 0, color: '#1890ff', - cursor: 'pointer' + cursor: 'pointer', }} ellipsis={{ tooltip: text, rows: 2 }} onClick={() => { @@ -270,9 +271,14 @@ const Crontab = () => { record.sub_id ? ( - request.get(`${config.apiPrefix}subscriptions/${record.sub_id}`) + request.get(`${config.apiPrefix}subscriptions/${record.sub_id}`, { + onError: noop, + }) } - options={{ ready: record?.sub_id, cacheKey: record.sub_id }} + options={{ + ready: record?.sub_id, + cacheKey: record.sub_id, + }} /> ) : ( '-' diff --git a/src/utils/http.ts b/src/utils/http.ts index cee0fd00..e276ecdd 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -1,29 +1,44 @@ -import intl from 'react-intl-universal' +import intl from 'react-intl-universal'; import { message } from 'antd'; import config from './config'; import { history } from '@umijs/max'; -import axios, { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios'; +import axios, { + AxiosError, + AxiosInstance, + AxiosRequestConfig, + AxiosResponse, + InternalAxiosRequestConfig, +} from 'axios'; -interface IResponseData { +export interface IResponseData { code?: number; data?: any; message?: string; error?: any; } -type Override< +export type Override< T, K extends Partial<{ [P in keyof T]: any }> | string, > = K extends string ? Omit & { [P in keyof T]: T[P] | unknown } : Omit & K; +export interface ICustomConfig { + onError?: (res: AxiosResponse) => void; +} + message.config({ duration: 2, }); const time = Date.now(); -const errorHandler = function (error: AxiosError) { +const errorHandler = function ( + error: Override< + AxiosError, + { config: InternalAxiosRequestConfig & ICustomConfig } + >, +) { if (error.response) { const msg = error.response.data ? error.response.data.message || error.message || error.response.data @@ -38,6 +53,10 @@ const errorHandler = function (error: AxiosError) { history.push('/login'); } } else { + if (typeof error.config?.onError === 'function') { + return error.config?.onError(error.response); + } + message.error({ content: msg, style: { maxWidth: 500, margin: '0 auto' }, @@ -105,21 +124,21 @@ export const request = _request as Override< { get( url: string, - config?: AxiosRequestConfig, + config?: AxiosRequestConfig & ICustomConfig, ): Promise; delete( url: string, - config?: AxiosRequestConfig, + config?: AxiosRequestConfig & ICustomConfig, ): Promise; post( url: string, data?: D, - config?: AxiosRequestConfig, + config?: AxiosRequestConfig & ICustomConfig, ): Promise; put( url: string, data?: D, - config?: AxiosRequestConfig, + config?: AxiosRequestConfig & ICustomConfig, ): Promise; } >;