feat: add webhookSignature in feed channel

This commit is contained in:
moonrailgun 2024-10-29 03:41:45 +08:00
parent f592466d62
commit 6b3631eae1
7 changed files with 64 additions and 8 deletions

View File

@ -275,6 +275,9 @@ importers:
lucide-react:
specifier: ^0.358.0
version: 0.358.0(react@18.2.0)
md5:
specifier: ^2.3.0
version: 2.3.0
millify:
specifier: ^6.1.0
version: 6.1.0
@ -378,6 +381,9 @@ importers:
'@types/lodash-es':
specifier: ^4.17.12
version: 4.17.12
'@types/md5':
specifier: ^2.3.5
version: 2.3.5
'@types/react':
specifier: ^18.2.22
version: 18.2.78

View File

@ -24,9 +24,13 @@ import {
SelectValue,
} from '../ui/select';
import { NotificationPicker } from '../notification/NotificationPicker';
import { LuRefreshCcw } from 'react-icons/lu';
import md5 from 'md5';
import dayjs from 'dayjs';
const addFormSchema = z.object({
name: z.string(),
webhookSignature: z.string().optional(),
notificationIds: z.array(z.string()).default([]),
notifyFrequency: z.enum(['none', 'event', 'day', 'week', 'month']),
});
@ -79,6 +83,38 @@ export const FeedChannelEditForm: React.FC<FeedChannelEditFormProps> =
)}
/>
<FormField
control={form.control}
name="webhookSignature"
render={({ field }) => (
<FormItem>
<FormLabel optional={true}>
{t('Webhook Signature')}
</FormLabel>
<FormControl>
<div className="flex">
<Input className="rounded-r-none" {...field} />
<Button
className="rounded-l-none"
type="button"
Icon={LuRefreshCcw}
onClick={() => {
form.setValue(
'webhookSignature',
md5(dayjs().valueOf().toString())
);
}}
/>
</div>
</FormControl>
<FormDescription>
{t('Optional, Webhook Signature for Incoming Webhook')}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="notificationIds"

View File

@ -70,6 +70,7 @@
"leaflet": "^1.9.4",
"lodash-es": "^4.17.21",
"lucide-react": "^0.358.0",
"md5": "^2.3.0",
"millify": "^6.1.0",
"next-themes": "^0.2.1",
"pretty-ms": "^9.0.0",
@ -106,6 +107,7 @@
"@types/leaflet": "^1.9.8",
"@types/loadable__component": "^5.13.8",
"@types/lodash-es": "^4.17.12",
"@types/md5": "^2.3.5",
"@types/react": "^18.2.22",
"@types/react-beautiful-dnd": "^13.1.8",
"@types/react-dom": "^18.2.7",

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "FeedChannel" ADD COLUMN "webhookSignature" VARCHAR(100) NOT NULL DEFAULT '';

View File

@ -540,12 +540,13 @@ enum FeedChannelNotifyFrequency {
}
model FeedChannel {
id String @id @default(cuid()) @db.VarChar(30)
workspaceId String @db.VarChar(30)
name String
notifyFrequency FeedChannelNotifyFrequency @default(day)
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @updatedAt @db.Timestamptz(6)
id String @id @default(cuid()) @db.VarChar(30)
workspaceId String @db.VarChar(30)
name String
webhookSignature String @default("") @db.VarChar(100)
notifyFrequency FeedChannelNotifyFrequency @default(day)
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @updatedAt @db.Timestamptz(6)
workspace Workspace @relation(fields: [workspaceId], references: [id], onUpdate: Cascade, onDelete: Cascade)
events FeedEvent[]

View File

@ -7,6 +7,7 @@ export const FeedChannelModelSchema = z.object({
id: z.string(),
workspaceId: z.string(),
name: z.string(),
webhookSignature: z.string(),
notifyFrequency: z.nativeEnum(FeedChannelNotifyFrequency),
createdAt: z.date(),
updatedAt: z.date(),

View File

@ -124,6 +124,7 @@ export const feedRouter = router({
.merge(
FeedChannelModelSchema.pick({
name: true,
webhookSignature: true,
notifyFrequency: true,
})
)
@ -137,8 +138,14 @@ export const feedRouter = router({
.nullable()
)
.mutation(async ({ input }) => {
const { channelId, workspaceId, name, notifyFrequency, notificationIds } =
input;
const {
channelId,
workspaceId,
name,
webhookSignature,
notifyFrequency,
notificationIds,
} = input;
const channel = await prisma.feedChannel.update({
where: {
@ -147,6 +154,7 @@ export const feedRouter = router({
},
data: {
name,
webhookSignature,
notifyFrequency,
notifications: {
set: notificationIds.map((id) => ({