mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
Add a field filter type reading any payload value by JSONPath with array expansion, 12 comparison operators (eq/ne/contains/startsWith/endsWith/regex/gt/gte/lt/lte/in/exists), a visual AST builder (all/any/not) in the route editor, chip-based multi-value input, a stateless POST /admin/api/test-match dry-run, and named filter fragments stored in D1 (d1_fragments, migration 0010) inlined into route ASTs on insert.
34 lines
1 KiB
TypeScript
34 lines
1 KiB
TypeScript
import type { NamedFragment } from "~/types";
|
|
|
|
export function useFragmentsApi() {
|
|
const { needLogin } = useAuthState();
|
|
const fragments = ref<NamedFragment[]>([]);
|
|
const loading = ref(false);
|
|
const error = ref("");
|
|
|
|
async function load(groupId: string): Promise<void> {
|
|
loading.value = true;
|
|
error.value = "";
|
|
needLogin.value = false;
|
|
try {
|
|
const data = await apiFetch<{ fragments?: NamedFragment[] }>(
|
|
`/admin/api/groups/${encodeURIComponent(groupId)}/fragments`,
|
|
);
|
|
fragments.value = data.fragments ?? [];
|
|
} catch (err) {
|
|
if (!needLogin.value) error.value = err instanceof Error ? err.message : String(err);
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
|
|
async function save(groupId: string, next: NamedFragment[]): Promise<void> {
|
|
await apiFetch(`/admin/api/groups/${encodeURIComponent(groupId)}/fragments`, {
|
|
method: "PUT",
|
|
body: JSON.stringify({ fragments: next }),
|
|
});
|
|
fragments.value = next;
|
|
}
|
|
|
|
return { fragments, loading, needLogin, error, load, save };
|
|
}
|