修复系统通知错误提示,gotifyPriority 配置参数

This commit is contained in:
whyour 2023-05-03 18:18:28 +08:00
parent 77dc7817fb
commit 9db0095e29
3 changed files with 246 additions and 169 deletions

View File

@ -36,7 +36,7 @@ export default class NotificationService {
private content = '';
private params!: Omit<NotificationInfo, 'type'>;
private gotOption = {
timeout: 30000,
timeout: 10000,
retry: 1,
};
@ -78,7 +78,8 @@ export default class NotificationService {
}
private async gotify() {
const { gotifyUrl, gotifyToken, gotifyPriority } = this.params;
const { gotifyUrl, gotifyToken, gotifyPriority = 1 } = this.params;
try {
const res: any = await got
.post(`${gotifyUrl}/message?token=${gotifyToken}`, {
...this.gotOption,
@ -93,10 +94,14 @@ export default class NotificationService {
})
.json();
return typeof res.id === 'number';
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async goCqHttpBot() {
const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params;
try {
const res: any = await got
.post(`${goCqHttpBotUrl}?${goCqHttpBotQq}`, {
...this.gotOption,
@ -105,6 +110,9 @@ export default class NotificationService {
})
.json();
return res.retcode === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async serverChan() {
@ -112,6 +120,7 @@ export default class NotificationService {
const url = serverChanKey.startsWith('SCT')
? `https://sctapi.ftqq.com/${serverChanKey}.send`
: `https://sc.ftqq.com/${serverChanKey}.send`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -120,11 +129,15 @@ export default class NotificationService {
})
.json();
return res.errno === 0 || res.data.errno === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async pushDeer() {
const { pushDeerKey, pushDeerUrl } = this.params;
const url = pushDeerUrl || `https://api2.pushdeer.com/message/push`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -137,11 +150,15 @@ export default class NotificationService {
return (
res.content.result.length !== undefined && res.content.result.length > 0
);
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async chat() {
const { chatUrl, chatToken } = this.params;
const url = `${chatUrl}${chatToken}`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -150,11 +167,14 @@ export default class NotificationService {
})
.json();
return res.success;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async bark() {
let { barkPush, barkIcon, barkSound, barkGroup } = this.params;
if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) {
if (!barkPush.startsWith('http')) {
barkPush = `https://api.day.app/${barkPush}`;
}
const url = `${barkPush}/${encodeURIComponent(
@ -162,6 +182,8 @@ export default class NotificationService {
)}/${encodeURIComponent(
this.content,
)}?icon=${barkIcon}&sound=${barkSound}&group=${barkGroup}`;
try {
const res: any = await got
.get(url, {
...this.gotOption,
@ -169,6 +191,9 @@ export default class NotificationService {
})
.json();
return res.code === 200;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async telegramBot() {
@ -200,6 +225,7 @@ export default class NotificationService {
https: httpsAgent,
};
}
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -209,6 +235,9 @@ export default class NotificationService {
})
.json();
return !!res.ok;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async dingtalkBot() {
@ -222,6 +251,7 @@ export default class NotificationService {
secretParam = `&timestamp=${dateNow}&sign=${result}`;
}
const url = `https://oapi.dingtalk.com/robot/send?access_token=${dingtalkBotToken}${secretParam}`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -234,11 +264,15 @@ export default class NotificationService {
})
.json();
return res.errcode === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async weWorkBot() {
const { weWorkBotKey } = this.params;
const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${weWorkBotKey}`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -251,6 +285,9 @@ export default class NotificationService {
})
.json();
return res.errcode === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async weWorkApp() {
@ -306,6 +343,7 @@ export default class NotificationService {
break;
}
try {
const res: any = await got
.post(
`https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${tokenRes.access_token}`,
@ -322,6 +360,9 @@ export default class NotificationService {
.json();
return res.errcode === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async aibotk() {
@ -353,6 +394,7 @@ export default class NotificationService {
break;
}
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -363,11 +405,15 @@ export default class NotificationService {
.json();
return res.code === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async iGot() {
const { iGotPushKey } = this.params;
const url = `https://push.hellyw.com/${iGotPushKey.toLowerCase()}`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -377,11 +423,15 @@ export default class NotificationService {
.json();
return res.ret === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async pushPlus() {
const { pushPlusToken, pushPlusUser } = this.params;
const url = `https://www.pushplus.plus/send`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
@ -395,12 +445,21 @@ export default class NotificationService {
.json();
return res.code === 200;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async lark() {
const { larkKey } = this.params;
let { larkKey } = this.params;
if (!larkKey.startsWith('http')) {
larkKey = `https://open.feishu.cn/open-apis/bot/v2/hook/${larkKey}`;
}
try {
const res: any = await got
.post(`https://open.feishu.cn/open-apis/bot/v2/hook/${larkKey}`, {
.post(larkKey, {
...this.gotOption,
json: {
msg_type: 'text',
@ -410,10 +469,15 @@ export default class NotificationService {
})
.json();
return res.StatusCode === 0;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async email() {
const { emailPass, emailService, emailUser } = this.params;
try {
const transporter = nodemailer.createTransport({
service: emailService,
auth: {
@ -432,6 +496,9 @@ export default class NotificationService {
transporter.close();
return !!info.messageId;
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async webhook() {
@ -460,8 +527,12 @@ export default class NotificationService {
allowGetBody: true,
...bodyParam,
};
try {
const res = await got(formatUrl, options);
return String(res.statusCode).startsWith('20');
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private formatBody(contentType: string, body: any): object {

View File

@ -449,7 +449,7 @@ patch_version() {
fi
if [[ $NpmMirror ]]; then
cd && pnpm config set registry $NpmMirror
pnpm install -g --prefer-offline --force
pnpm install -g --force
fi
git config --global pull.rebase false

View File

@ -12,6 +12,7 @@ const NotificationSetting = ({ data }: any) => {
const [form] = Form.useForm();
const handleOk = (values: any) => {
setLoading(true);
const { type } = values;
if (type == 'closed') {
values.type = '';
@ -30,7 +31,8 @@ const NotificationSetting = ({ data }: any) => {
})
.catch((error: any) => {
console.log(error);
});
})
.finally(() => setLoading(false));
};
const notificationModeChange = (value: string) => {
@ -56,7 +58,7 @@ const NotificationSetting = ({ data }: any) => {
style={{ maxWidth: 400 }}
initialValue={notificationMode}
>
<Select onChange={notificationModeChange}>
<Select onChange={notificationModeChange} disabled={loading}>
{config.notificationModes.map((x) => (
<Option key={x.value} value={x.value}>
{x.label}
@ -74,7 +76,10 @@ const NotificationSetting = ({ data }: any) => {
style={{ maxWidth: 400 }}
>
{x.items ? (
<Select placeholder={x.placeholder || `请选择${x.label}`}>
<Select
placeholder={x.placeholder || `请选择${x.label}`}
disabled={loading}
>
{x.items.map((y) => (
<Option key={y.value} value={y.value}>
{y.label || y.value}
@ -83,14 +88,15 @@ const NotificationSetting = ({ data }: any) => {
</Select>
) : (
<Input.TextArea
disabled={loading}
autoSize={true}
placeholder={x.placeholder || `请输入${x.label}`}
/>
)}
</Form.Item>
))}
<Button type="primary" htmlType="submit">
<Button type="primary" htmlType="submit" disabled={loading}>
{loading ? '测试中...' : '保存'}
</Button>
</Form>
</div>