Stage 9: ban history — backend service, router, frontend history page

- history.py models: HistoryBanItem, HistoryListResponse, IpTimelineEvent, IpDetailResponse
- history_service.py: list_history() with dynamic WHERE clauses (range/jail/ip
  prefix/all-time), get_ip_detail() with timeline aggregation
- history.py router: GET /api/history + GET /api/history/{ip} (404 for unknown)
- Fixed latent bug in ban_service._parse_data_json: json.loads('null') -> None
  -> AttributeError; now checks isinstance(parsed, dict) before assigning obj
- 317 tests pass (27 new), ruff + mypy clean (46 files)
- types/history.ts, api/history.ts, hooks/useHistory.ts created
- HistoryPage.tsx: filter bar (time range/jail/IP), DataGrid table,
  high-ban-count row highlighting, per-IP IpDetailView with timeline,
  pagination
- Frontend tsc + ESLint clean (0 errors/warnings)
- Tasks.md Stage 9 marked done
This commit is contained in:
2026-03-01 15:09:22 +01:00
parent 54313fd3e0
commit b8f3a1c562
12 changed files with 2050 additions and 50 deletions

View File

@@ -0,0 +1,53 @@
/**
* API functions for the ban history endpoints.
*/
import { get } from "./client";
import { ENDPOINTS } from "./endpoints";
import type {
HistoryListResponse,
HistoryQuery,
IpDetailResponse,
} from "../types/history";
/**
* Fetch a paginated list of historical bans with optional filters.
*/
export async function fetchHistory(
query: HistoryQuery = {},
): Promise<HistoryListResponse> {
const params = new URLSearchParams();
if (query.range) params.set("range", query.range);
if (query.jail) params.set("jail", query.jail);
if (query.ip) params.set("ip", query.ip);
if (query.page !== undefined) params.set("page", String(query.page));
if (query.page_size !== undefined)
params.set("page_size", String(query.page_size));
const qs = params.toString();
const url = qs
? `${ENDPOINTS.history}?${qs}`
: ENDPOINTS.history;
return get<HistoryListResponse>(url);
}
/**
* Fetch the full ban history for a single IP address.
*
* @returns null when the server returns 404 (no history for this IP).
*/
export async function fetchIpHistory(ip: string): Promise<IpDetailResponse | null> {
try {
return await get<IpDetailResponse>(ENDPOINTS.historyIp(ip));
} catch (err: unknown) {
if (
typeof err === "object" &&
err !== null &&
"status" in err &&
(err as { status: number }).status === 404
) {
return null;
}
throw err;
}
}