feat(web): 前端逻辑骨架——http/router/stores/queries 与薄壳路由
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import type { AuditLogItem, Paginated } from "@new-api-key-usage/core";
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export async function fetchAuditLogs(params: {
|
||||
page: number;
|
||||
page_size: number;
|
||||
domain?: string;
|
||||
}): Promise<Paginated<AuditLogItem>> {
|
||||
const { data } = await adminHttp.get<Paginated<AuditLogItem>>("/audit-logs", {
|
||||
params,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { EngineStatus, QpuLatest } from "@new-api-key-usage/core";
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export async function fetchEngine(): Promise<EngineStatus> {
|
||||
const { data } = await adminHttp.get<EngineStatus>("/engine");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchQpuLatest(): Promise<QpuLatest> {
|
||||
const { data } = await adminHttp.get<QpuLatest>("/qpu/latest");
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { KeyItem } from "@new-api-key-usage/core";
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export type KeyListFilters = {
|
||||
member_id?: number | "unassigned";
|
||||
status?: "active" | "disabled";
|
||||
recent_failed?: boolean;
|
||||
};
|
||||
|
||||
export async function fetchKeys(filters: KeyListFilters = {}): Promise<KeyItem[]> {
|
||||
const { data } = await adminHttp.get<KeyItem[]>("/keys", { params: filters });
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function registerKey(body: {
|
||||
sk_key: string;
|
||||
member_id?: number | null;
|
||||
}): Promise<KeyItem> {
|
||||
const { data } = await adminHttp.post<KeyItem>("/keys", body);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function patchKey(
|
||||
id: number,
|
||||
body: { status?: "active" | "disabled"; member_id?: number | null },
|
||||
): Promise<KeyItem> {
|
||||
const { data } = await adminHttp.patch<KeyItem>(`/keys/${id}`, body);
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { LogItem, Paginated } from "@new-api-key-usage/core";
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export async function fetchLogs(
|
||||
range: { from: string; to: string; page: number; page_size: number },
|
||||
): Promise<Paginated<LogItem>> {
|
||||
const { data } = await adminHttp.get<Paginated<LogItem>>("/logs", {
|
||||
params: range,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { MemberItem } from "@new-api-key-usage/core";
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export async function fetchMembers(): Promise<MemberItem[]> {
|
||||
const { data } = await adminHttp.get<MemberItem[]>("/members");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createMember(body: {
|
||||
name: string;
|
||||
remark?: string;
|
||||
}): Promise<MemberItem> {
|
||||
const { data } = await adminHttp.post<MemberItem>("/members", body);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function patchMember(
|
||||
id: number,
|
||||
body: { status: "active" | "disabled" },
|
||||
): Promise<MemberItem> {
|
||||
const { data } = await adminHttp.patch<MemberItem>(`/members/${id}`, body);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function issueMemberToken(id: number): Promise<{ token: string }> {
|
||||
const { data } = await adminHttp.post<{ token: string }>(`/members/${id}/token`);
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { UsageTotals, UnixSec } from "@new-api-key-usage/core";
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export type AdminOverview = {
|
||||
data_cutoff: UnixSec | null;
|
||||
unassigned_subscription: UsageTotals;
|
||||
by_source: Array<{
|
||||
billing_source: string;
|
||||
count: number;
|
||||
quota: number;
|
||||
quota_usd: string;
|
||||
}>;
|
||||
by_member: Array<{
|
||||
member_id: number | null;
|
||||
member_name: string | null;
|
||||
key_count: number;
|
||||
data_cutoff: UnixSec | null;
|
||||
usage: UsageTotals;
|
||||
}>;
|
||||
by_key: Array<{
|
||||
key_id: number;
|
||||
token_name: string;
|
||||
member_id: number | null;
|
||||
status: string;
|
||||
data_cutoff: UnixSec | null;
|
||||
usage: UsageTotals;
|
||||
}>;
|
||||
};
|
||||
|
||||
export async function fetchOverview(range: {
|
||||
from: string;
|
||||
to: string;
|
||||
}): Promise<AdminOverview> {
|
||||
const { data } = await adminHttp.get<AdminOverview>("/overview", {
|
||||
params: range,
|
||||
});
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { PaymentItem } from "@new-api-key-usage/core";
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export type PaymentBody = Record<string, unknown>;
|
||||
|
||||
export async function fetchPayments(): Promise<PaymentItem[]> {
|
||||
const { data } = await adminHttp.get<PaymentItem[]>("/payments");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function createPayment(body: PaymentBody): Promise<PaymentItem> {
|
||||
const { data } = await adminHttp.post<PaymentItem>("/payments", body);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function updatePayment(
|
||||
id: number,
|
||||
body: PaymentBody,
|
||||
): Promise<PaymentItem> {
|
||||
const { data } = await adminHttp.put<PaymentItem>(`/payments/${id}`, body);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function deletePayment(id: number): Promise<void> {
|
||||
await adminHttp.delete(`/payments/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { adminHttp } from "../http.ts";
|
||||
|
||||
export type SetupState = { initialized: boolean };
|
||||
export type UsernameBody = { username: string };
|
||||
|
||||
export async function fetchSetupState(): Promise<SetupState> {
|
||||
const { data } = await adminHttp.get<SetupState>("/setup-state");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function setup(body: {
|
||||
username: string;
|
||||
password: string;
|
||||
}): Promise<UsernameBody> {
|
||||
const { data } = await adminHttp.post<UsernameBody>("/setup", body);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function login(body: {
|
||||
username: string;
|
||||
password: string;
|
||||
}): Promise<UsernameBody> {
|
||||
const { data } = await adminHttp.post<UsernameBody>("/session", body);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function fetchSession(): Promise<UsernameBody> {
|
||||
const { data } = await adminHttp.get<UsernameBody>("/session");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function logout(): Promise<void> {
|
||||
await adminHttp.delete("/session");
|
||||
}
|
||||
|
||||
export async function changePassword(body: {
|
||||
old_password: string;
|
||||
new_password: string;
|
||||
}): Promise<void> {
|
||||
await adminHttp.put("/password", body);
|
||||
}
|
||||
Reference in New Issue
Block a user