Download webui/src/features/rules/api.ts from xjackkx/rg: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/xjackkx/rg/resolve/main/webui/src/features/rules/api.ts
- Command line
-
hf download hf://spaces/xjackkx/rg/webui/src/features/rules/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/xjackkx/rg/resolve/main/webui/src/features/rules/api.ts
1.62 kB
| import { apiRequest } from "../../lib/api-client"; | |
| import type { PageResponse, ResolveResult, Rule } from "./types"; | |
| const basePath = "/api/v1/account-header-rules"; | |
| function normalizeRule(raw: Rule): Rule { | |
| return { | |
| ...raw, | |
| headers: Array.isArray(raw.headers) ? raw.headers : [], | |
| }; | |
| } | |
| export async function listRules(keyword?: string): Promise<Rule[]> { | |
| const query = new URLSearchParams({ | |
| limit: "1000", | |
| offset: "0", | |
| }); | |
| const trimmedKeyword = keyword?.trim(); | |
| if (trimmedKeyword) { | |
| query.set("keyword", trimmedKeyword); | |
| } | |
| const data = await apiRequest<PageResponse<Rule>>(`${basePath}?${query.toString()}`); | |
| return data.items.map(normalizeRule); | |
| } | |
| function encodeRulePrefix(prefix: string): string { | |
| return encodeURIComponent(prefix); | |
| } | |
| export async function upsertRule(prefix: string, headers: string[]): Promise<Rule> { | |
| const encodedPrefix = encodeRulePrefix(prefix); | |
| const data = await apiRequest<Rule>(`${basePath}/${encodedPrefix}`, { | |
| method: "PUT", | |
| body: { headers }, | |
| }); | |
| return normalizeRule(data); | |
| } | |
| export async function deleteRule(prefix: string): Promise<void> { | |
| const encodedPrefix = encodeRulePrefix(prefix); | |
| await apiRequest<void>(`${basePath}/${encodedPrefix}`, { | |
| method: "DELETE", | |
| }); | |
| } | |
| export async function resolveRule(url: string): Promise<ResolveResult> { | |
| const data = await apiRequest<ResolveResult>("/api/v1/account-header-rules:resolve", { | |
| method: "POST", | |
| body: { url }, | |
| }); | |
| return { | |
| matched_url_prefix: data.matched_url_prefix || "", | |
| headers: Array.isArray(data.headers) ? data.headers : [], | |
| }; | |
| } | |