Enhance the message notification feature
This commit is contained in:
@@ -23,6 +23,7 @@ const Telegram = () => {
|
||||
name: "notifyChannels",
|
||||
data: {
|
||||
apiToken: "",
|
||||
chatId: "",
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
@@ -31,6 +32,7 @@ const Telegram = () => {
|
||||
const getDetailTelegram = () => {
|
||||
const df: NotifyChannelTelegram = {
|
||||
apiToken: "",
|
||||
chatId: "",
|
||||
enabled: false,
|
||||
};
|
||||
if (!config.content) {
|
||||
@@ -98,6 +100,20 @@ const Telegram = () => {
|
||||
}}
|
||||
/>
|
||||
|
||||
<Input
|
||||
placeholder="ChatId"
|
||||
value={telegram.data.chatId}
|
||||
onChange={(e) => {
|
||||
setTelegram({
|
||||
...telegram,
|
||||
data: {
|
||||
...telegram.data,
|
||||
chatId: e.target.value,
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className="flex items-center space-x-1 mt-2">
|
||||
<Switch
|
||||
id="airplane-mode"
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useEffect, useState } from "react";
|
||||
import { update } from "@/repository/settings";
|
||||
import { getErrMessage } from "@/lib/error";
|
||||
import { useToast } from "../ui/use-toast";
|
||||
import { isValidURL } from "@/lib/url";
|
||||
|
||||
type WebhookSetting = {
|
||||
id: string;
|
||||
@@ -55,6 +56,16 @@ const Webhook = () => {
|
||||
|
||||
const handleSaveClick = async () => {
|
||||
try {
|
||||
webhook.data.url = webhook.data.url.trim();
|
||||
if (!isValidURL(webhook.data.url)) {
|
||||
toast({
|
||||
title: "保存失败",
|
||||
description: "Url格式不正确",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const resp = await update({
|
||||
...config,
|
||||
name: "notifyChannels",
|
||||
|
||||
@@ -36,6 +36,7 @@ export type NotifyChannelDingTalk = {
|
||||
|
||||
export type NotifyChannelTelegram = {
|
||||
apiToken: string;
|
||||
chatId: string;
|
||||
enabled: boolean;
|
||||
};
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const version = "Certimate v0.1.10";
|
||||
export const version = "Certimate v0.1.11";
|
||||
|
||||
8
ui/src/lib/url.ts
Normal file
8
ui/src/lib/url.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export function isValidURL(url: string): boolean {
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ const Notify = () => {
|
||||
</Accordion>
|
||||
</div>
|
||||
<div className="border rounded-md p-5 mt-7 shadow-lg">
|
||||
<Accordion type={"multiple"} className="dark:text-stone-200">
|
||||
<Accordion type={"single"} className="dark:text-stone-200">
|
||||
<AccordionItem value="item-2" className="dark:border-stone-200">
|
||||
<AccordionTrigger>钉钉</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
|
||||
Reference in New Issue
Block a user