Notify Add Lark

This commit is contained in:
g1335333249 2024-10-17 12:39:18 +08:00
parent a035ba192a
commit 004c6a8506
11 changed files with 497 additions and 333 deletions

1
go.mod
View File

@ -30,6 +30,7 @@ require (
github.com/alibabacloud-go/tea-oss-sdk v1.1.3 // indirect
github.com/alibabacloud-go/tea-oss-utils v1.1.0 // indirect
github.com/blinkbean/dingtalk v1.1.3 // indirect
github.com/go-lark/lark v1.14.1 // indirect
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.114 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect

3
go.sum
View File

@ -178,6 +178,8 @@ github.com/go-acme/lego/v4 v4.19.2/go.mod h1:wtDe3dDkmV4/oI2nydpNXSJpvV10J9RCyZ6
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-jose/go-jose/v4 v4.0.4 h1:VsjPI33J0SB9vQM6PLmNjoHqMQNGPiZ0rHL7Ni7Q6/E=
github.com/go-jose/go-jose/v4 v4.0.4/go.mod h1:NKb5HO1EZccyMpiZNbdUw/14tiXNyUJh188dfnMCAfc=
github.com/go-lark/lark v1.14.1 h1:qWYQTk6wLwf/08u8WbdNAHNmfqavdOvmsENlQ+Cb8aY=
github.com/go-lark/lark v1.14.1/go.mod h1:6ltbSztPZRT6IaO9ZIQyVaY5pVp/KeMizDYtfZkU+vM=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@ -271,6 +273,7 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=

View File

@ -3,6 +3,7 @@ package notify
import (
"context"
"fmt"
"github.com/nikoksr/notify/service/lark"
"strconv"
notifyPackage "github.com/nikoksr/notify"
@ -17,6 +18,7 @@ const (
notifyChannelDingtalk = "dingtalk"
notifyChannelWebhook = "webhook"
notifyChannelTelegram = "telegram"
notifyChannelLark = "lark"
)
func Send(title, content string) error {
@ -67,6 +69,8 @@ func getNotifiers() ([]notifyPackage.Notifier, error) {
notifiers = append(notifiers, temp)
case notifyChannelDingtalk:
notifiers = append(notifiers, getDingTalkNotifier(v))
case notifyChannelLark:
notifiers = append(notifiers, getLarkNotifier(v))
case notifyChannelWebhook:
notifiers = append(notifiers, getWebhookNotifier(v))
}
@ -108,6 +112,10 @@ func getDingTalkNotifier(conf map[string]any) notifyPackage.Notifier {
})
}
func getLarkNotifier(conf map[string]any) notifyPackage.Notifier {
return lark.NewWebhookService(getString(conf, "webhookUrl"))
}
func getString(conf map[string]any, key string) string {
if _, ok := conf[key]; !ok {
return ""

File diff suppressed because one or more lines are too long

329
ui/dist/assets/index-C4I3lphu.js vendored Normal file

File diff suppressed because one or more lines are too long

2
ui/dist/index.html vendored
View File

@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Certimate - Your Trusted SSL Automation Partner</title>
<script type="module" crossorigin src="/assets/index-BTjl7ZFn.js"></script>
<script type="module" crossorigin src="/assets/index-C4I3lphu.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-YqBWA4KK.css">
</head>
<body class="bg-background">

View File

@ -0,0 +1,136 @@
import { Input } from "../ui/input";
import { Button } from "../ui/button";
import { Switch } from "../ui/switch";
import { Label } from "../ui/label";
import { useNotify } from "@/providers/notify";
import { NotifyChannelLark, NotifyChannels } from "@/domain/settings";
import { useEffect, useState } from "react";
import { update } from "@/repository/settings";
import { getErrMessage } from "@/lib/error";
import { useToast } from "../ui/use-toast";
import { useTranslation } from "react-i18next";
type LarkSetting = {
id: string;
name: string;
data: NotifyChannelLark;
};
const Lark = () => {
const { config, setChannels } = useNotify();
const { t } = useTranslation();
const [lark, setLark] = useState<LarkSetting>({
id: config.id ?? "",
name: "notifyChannels",
data: {
webhookUrl: "",
enabled: false,
},
});
useEffect(() => {
const getDetailLark = () => {
const df: NotifyChannelLark = {
webhookUrl: "",
enabled: false,
};
if (!config.content) {
return df;
}
const chanels = config.content as NotifyChannels;
if (!chanels.lark) {
return df;
}
return chanels.lark as NotifyChannelLark;
};
const data = getDetailLark();
setLark({
id: config.id ?? "",
name: "lark",
data,
});
}, [config]);
const { toast } = useToast();
const handleSaveClick = async () => {
try {
const resp = await update({
...config,
name: "notifyChannels",
content: {
...config.content,
lark: {
...lark.data,
},
},
});
setChannels(resp);
toast({
title: t("common.save.succeeded.message"),
description: t("settings.notification.config.saved.message"),
});
} catch (e) {
const msg = getErrMessage(e);
toast({
title: t("common.save.failed.message"),
description: `${t(
"settings.notification.config.failed.message"
)}: ${msg}`,
variant: "destructive",
});
}
};
return (
<div>
<Input
placeholder="Webhook Url"
value={lark.data.webhookUrl}
onChange={(e) => {
setLark({
...lark,
data: {
...lark.data,
webhookUrl: e.target.value,
},
});
}}
/>
<div className="flex items-center space-x-1 mt-2">
<Switch
id="airplane-mode"
checked={lark.data.enabled}
onCheckedChange={() => {
setLark({
...lark,
data: {
...lark.data,
enabled: !lark.data.enabled,
},
});
}}
/>
<Label htmlFor="airplane-mode">
{t("settings.notification.config.enable")}
</Label>
</div>
<div className="flex justify-end mt-2">
<Button
onClick={() => {
handleSaveClick();
}}
>
{t("common.save")}
</Button>
</div>
</div>
);
};
export default Lark;

View File

@ -19,11 +19,12 @@ export type NotifyTemplate = {
export type NotifyChannels = {
dingtalk?: NotifyChannel;
lark?: NotifyChannel;
telegram?: NotifyChannel;
webhook?: NotifyChannel;
};
export type NotifyChannel = NotifyChannelDingTalk | NotifyChannelTelegram | NotifyChannelWebhook;
export type NotifyChannel = NotifyChannelDingTalk | NotifyChannelLark | NotifyChannelTelegram | NotifyChannelWebhook;
export type NotifyChannelDingTalk = {
accessToken: string;
@ -31,6 +32,11 @@ export type NotifyChannelDingTalk = {
enabled: boolean;
};
export type NotifyChannelLark = {
webhookUrl: string;
enabled: boolean;
};
export type NotifyChannelTelegram = {
apiToken: string;
chatId: string;

View File

@ -68,5 +68,6 @@
"common.provider.ssh": "SSH Deployment",
"common.provider.webhook": "Webhook",
"common.provider.dingtalk": "DingTalk",
"common.provider.telegram": "Telegram"
"common.provider.telegram": "Telegram",
"common.provider.lark": "Lark"
}

View File

@ -68,5 +68,6 @@
"common.provider.ssh": "SSH 部署",
"common.provider.webhook": "Webhook",
"common.provider.dingtalk": "钉钉",
"common.provider.telegram": "Telegram"
"common.provider.telegram": "Telegram",
"common.provider.lark": "飞书"
}

View File

@ -2,6 +2,7 @@ import { useTranslation } from "react-i18next";
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
import DingTalk from "@/components/notify/DingTalk";
import Lark from "@/components/notify/Lark";
import NotifyTemplate from "@/components/notify/NotifyTemplate";
import Telegram from "@/components/notify/Telegram";
import Webhook from "@/components/notify/Webhook";
@ -32,6 +33,13 @@ const Notify = () => {
</AccordionContent>
</AccordionItem>
<AccordionItem value="item-3" className="dark:border-stone-200">
<AccordionTrigger>{t("common.provider.lark")}</AccordionTrigger>
<AccordionContent>
<Lark />
</AccordionContent>
</AccordionItem>
<AccordionItem value="item-4" className="dark:border-stone-200">
<AccordionTrigger>{t("common.provider.telegram")}</AccordionTrigger>
<AccordionContent>