feat: webhook action setting

This commit is contained in:
DIYgod 2024-09-29 04:17:51 +08:00
parent 31591d68d5
commit 0016a0742b
No known key found for this signature in database
6 changed files with 110 additions and 52 deletions

View File

@ -84,3 +84,27 @@ export type MediaModel = Exclude<
ExtractBizResponse<typeof apiClient.entries.$get>["data"],
undefined
>["entries"]["media"]
export type ActionsInput = {
name: string
condition: {
field?: ActionFeedField
operator?: ActionOperation
value?: string
}[]
result: {
translation?: string
summary?: boolean
readability?: boolean
rewriteRules?: {
from: string
to: string
}[]
blockRules?: {
field?: ActionEntryField
operator?: ActionOperation
value?: string | number
}[]
webhooks?: string[]
}
}[]

View File

@ -27,35 +27,7 @@ import {
import { ViewSelectContent } from "~/components/view-select-content"
import { stopPropagation } from "~/lib/dom"
import { cn } from "~/lib/utils"
import type {
ActionEntryField,
ActionFeedField,
ActionOperation,
SupportedLanguages,
} from "~/models"
type ActionsInput = {
name: string
condition: {
field?: ActionFeedField
operator?: ActionOperation
value?: string
}[]
result: {
translation?: string
summary?: boolean
readability?: boolean
rewriteRules?: {
from: string
to: string
}[]
blockRules?: {
field?: ActionEntryField
operator?: ActionOperation
value?: string | number
}[]
}
}[]
import type { ActionFeedField, ActionOperation, ActionsInput, SupportedLanguages } from "~/models"
const TransitionOptions: {
name: string
@ -620,6 +592,56 @@ export function ActionCard({
</>
)}
</SettingCollapsible>
<Divider />
<SettingCollapsible
title={t("actions.action_card.webhooks")}
open={!!data.result.webhooks}
onOpenChange={(open) => {
if (open) {
data.result.webhooks = [""]
} else {
delete data.result.webhooks
}
onChange(data)
}}
>
{data.result.webhooks && data.result.webhooks.length > 0 && (
<>
{data.result.webhooks.map((webhook, rewriteIdx) => {
return (
<div key={rewriteIdx} className="flex items-center gap-2">
<DeleteTableCell
onClick={() => {
if (data.result.webhooks?.length === 1) {
delete data.result.webhooks
} else {
data.result.webhooks?.splice(rewriteIdx, 1)
}
onChange(data)
}}
/>
<Input
value={webhook}
className="h-8"
placeholder="https://"
onChange={(e) => {
data.result.webhooks![rewriteIdx] = e.target.value
onChange(data)
}}
/>
</div>
)
})}
<AddTableRow
onClick={() => {
data.result.webhooks!.push("")
onChange(data)
}}
/>
</>
)}
</SettingCollapsible>
</div>
</div>
</div>

View File

@ -7,7 +7,7 @@ import { Button } from "~/components/ui/button"
import { useAuthQuery } from "~/hooks/common"
import { apiClient } from "~/lib/api-fetch"
import { toastFetchError } from "~/lib/error-parser"
import type { ActionEntryField, ActionFeedField, ActionOperation, ActionsResponse } from "~/models"
import type { ActionsInput, ActionsResponse } from "~/models"
import { ActionCard } from "~/modules/settings/action-card"
import { SettingsTitle } from "~/modules/settings/title"
import { defineSettingPageData } from "~/modules/settings/utils"
@ -22,28 +22,6 @@ export const loader = defineSettingPageData({
priority,
})
type ActionsInput = {
name: string
condition: {
field?: ActionFeedField
operator?: ActionOperation
value?: string
}[]
result: {
translation?: string
summary?: boolean
rewriteRules?: {
from: string
to: string
}[]
blockRules?: {
field?: ActionEntryField
operator?: ActionOperation
value?: string | number
}[]
}
}[]
export function Component() {
const { t } = useTranslation("settings")
const actions = useAuthQuery(Queries.action.getAll())
@ -63,6 +41,7 @@ export function Component() {
action.result.blockRules = action.result.blockRules?.filter(
(r) => r.field && r.operator && r.value,
)
action.result.webhooks = action.result.webhooks?.filter((w) => w)
})
await apiClient.actions.$put({
json: {

View File

@ -4,6 +4,7 @@
"1001": "create session failed",
"1002": "Invalid parameter",
"1003": "Invalid invitation",
"1004": "No permission",
"2000": "Only admins can refresh feeds",
"2001": "Feed not found",
"2002": "feedId or url required",

View File

@ -39,6 +39,7 @@
"actions.action_card.to": "To",
"actions.action_card.translate_into": "Translate into",
"actions.action_card.value": "Value",
"actions.action_card.webhooks": "Webhooks",
"actions.action_card.when_feeds_match": "When feeds match…",
"actions.newRule": "New Rule",
"actions.save": "Save",

View File

@ -224,6 +224,7 @@ declare const actions: drizzle_orm_pg_core.PgTableWithColumns<{
operator: z.infer<typeof ruleOperatorSchema>;
value: string | number;
}[];
webhooks?: string[];
};
}[];
driverParam: unknown;
@ -281,6 +282,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}>, "many">>;
webhooks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
@ -294,6 +296,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
@ -307,6 +310,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}>;
}, "strip", z.ZodTypeAny, {
name: string;
@ -323,6 +327,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
@ -344,6 +349,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
@ -401,6 +407,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}>, "many">>;
webhooks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
@ -414,6 +421,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
@ -427,6 +435,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}>;
}, "strip", z.ZodTypeAny, {
name: string;
@ -443,6 +452,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
@ -464,6 +474,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
@ -488,6 +499,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
@ -512,6 +524,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
@ -3211,6 +3224,21 @@ declare const feedPowerTokensRelations: drizzle_orm.Relations<"feedPowerTokens",
}>;
declare const _routes: hono_hono_base.HonoBase<Env, {
"/admin/clean": {
$post: {
input: {
json: {
type: string;
};
};
output: {
code: 0;
};
outputFormat: "json" | "text";
status: 200;
};
};
} & {
"/lists": {
$get: {
input: {
@ -4382,6 +4410,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
from: string;
to: string;
}[] | undefined;
webhooks?: string[] | undefined;
} | undefined;
}[] | undefined;
total?: number | undefined;
@ -4878,6 +4907,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
@ -4908,6 +4938,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;