Add AbortController cleanup to async frontend effects
This commit is contained in:
@@ -68,8 +68,8 @@ export async function runImportNow(): Promise<ImportRunResult> {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Fetch the current schedule config and next/last run times. */
|
||||
export async function fetchSchedule(): Promise<ScheduleInfo> {
|
||||
return get<ScheduleInfo>(ENDPOINTS.blocklistsSchedule);
|
||||
export async function fetchSchedule(signal?: AbortSignal): Promise<ScheduleInfo> {
|
||||
return get<ScheduleInfo>(ENDPOINTS.blocklistsSchedule, signal);
|
||||
}
|
||||
|
||||
/** Update the import schedule. */
|
||||
|
||||
@@ -84,8 +84,8 @@ async function request<T>(url: string, options: RequestInit = {}): Promise<T> {
|
||||
* @param path - API path relative to `BASE_URL`, e.g. `"/jails"`.
|
||||
* @returns Parsed response body typed as `T`.
|
||||
*/
|
||||
export async function get<T>(path: string): Promise<T> {
|
||||
return request<T>(`${BASE_URL}${path}`);
|
||||
export async function get<T>(path: string, signal?: AbortSignal): Promise<T> {
|
||||
return request<T>(`${BASE_URL}${path}`, { signal });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,12 +93,14 @@ export async function get<T>(path: string): Promise<T> {
|
||||
*
|
||||
* @param path - API path relative to `BASE_URL`.
|
||||
* @param body - Request payload to serialise as JSON.
|
||||
* @param signal - Optional abort signal for request cancellation.
|
||||
* @returns Parsed response body typed as `T`.
|
||||
*/
|
||||
export async function post<T>(path: string, body: unknown): Promise<T> {
|
||||
export async function post<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T> {
|
||||
return request<T>(`${BASE_URL}${path}`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -107,12 +109,14 @@ export async function post<T>(path: string, body: unknown): Promise<T> {
|
||||
*
|
||||
* @param path - API path relative to `BASE_URL`.
|
||||
* @param body - Request payload to serialise as JSON.
|
||||
* @param signal - Optional abort signal for request cancellation.
|
||||
* @returns Parsed response body typed as `T`.
|
||||
*/
|
||||
export async function put<T>(path: string, body: unknown): Promise<T> {
|
||||
export async function put<T>(path: string, body: unknown, signal?: AbortSignal): Promise<T> {
|
||||
return request<T>(`${BASE_URL}${path}`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -121,12 +125,14 @@ export async function put<T>(path: string, body: unknown): Promise<T> {
|
||||
*
|
||||
* @param path - API path relative to `BASE_URL`.
|
||||
* @param body - Optional request payload.
|
||||
* @param signal - Optional abort signal for request cancellation.
|
||||
* @returns Parsed response body typed as `T`.
|
||||
*/
|
||||
export async function del<T>(path: string, body?: unknown): Promise<T> {
|
||||
export async function del<T>(path: string, body?: unknown, signal?: AbortSignal): Promise<T> {
|
||||
return request<T>(`${BASE_URL}${path}`, {
|
||||
method: "DELETE",
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -142,8 +142,9 @@ export async function previewLog(
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchMapColorThresholds(
|
||||
signal?: AbortSignal,
|
||||
): Promise<MapColorThresholdsResponse> {
|
||||
return get<MapColorThresholdsResponse>(ENDPOINTS.configMapColorThresholds);
|
||||
return get<MapColorThresholdsResponse>(ENDPOINTS.configMapColorThresholds, signal);
|
||||
}
|
||||
|
||||
export async function updateMapColorThresholds(
|
||||
@@ -257,8 +258,8 @@ export async function createActionFile(
|
||||
// Parsed filter config (Task 2.2 / legacy /parsed endpoint)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchParsedFilter(name: string): Promise<FilterConfig> {
|
||||
return get<FilterConfig>(ENDPOINTS.configFilterParsed(name));
|
||||
export async function fetchParsedFilter(name: string, signal?: AbortSignal): Promise<FilterConfig> {
|
||||
return get<FilterConfig>(ENDPOINTS.configFilterParsed(name), signal);
|
||||
}
|
||||
|
||||
export async function updateParsedFilter(
|
||||
@@ -394,8 +395,8 @@ export async function fetchActions(): Promise<ActionListResponse> {
|
||||
* @param name - Action base name (e.g. "iptables" or "iptables.conf").
|
||||
* @returns ActionConfig with active, used_by_jails, source_file populated.
|
||||
*/
|
||||
export async function fetchAction(name: string): Promise<ActionConfig> {
|
||||
return get<ActionConfig>(ENDPOINTS.configAction(name));
|
||||
export async function fetchAction(name: string, signal?: AbortSignal): Promise<ActionConfig> {
|
||||
return get<ActionConfig>(ENDPOINTS.configAction(name), signal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -478,8 +479,8 @@ export async function removeActionFromJail(
|
||||
// Parsed jail file config (Task 6.1 / 6.2)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchParsedJailFile(filename: string): Promise<JailFileConfig> {
|
||||
return get<JailFileConfig>(ENDPOINTS.configJailFileParsed(filename));
|
||||
export async function fetchParsedJailFile(filename: string, signal?: AbortSignal): Promise<JailFileConfig> {
|
||||
return get<JailFileConfig>(ENDPOINTS.configJailFileParsed(filename), signal);
|
||||
}
|
||||
|
||||
export async function updateParsedJailFile(
|
||||
|
||||
@@ -43,6 +43,7 @@ export async function fetchBans(
|
||||
pageSize = 100,
|
||||
origin: BanOriginFilter = "all",
|
||||
source: "fail2ban" | "archive" = "fail2ban",
|
||||
signal?: AbortSignal,
|
||||
): Promise<DashboardBanListResponse> {
|
||||
const params = new URLSearchParams({
|
||||
range,
|
||||
@@ -55,7 +56,7 @@ export async function fetchBans(
|
||||
if (source !== "fail2ban") {
|
||||
params.set("source", source);
|
||||
}
|
||||
return get<DashboardBanListResponse>(`${ENDPOINTS.dashboardBans}?${params.toString()}`);
|
||||
return get<DashboardBanListResponse>(`${ENDPOINTS.dashboardBans}?${params.toString()}`, signal);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,6 @@ export async function submitSetup(data: SetupRequest): Promise<SetupResponse> {
|
||||
*
|
||||
* @returns The configured timezone identifier (e.g. `"Europe/Berlin"`).
|
||||
*/
|
||||
export async function fetchTimezone(): Promise<SetupTimezoneResponse> {
|
||||
return api.get<SetupTimezoneResponse>(ENDPOINTS.setupTimezone);
|
||||
export async function fetchTimezone(signal?: AbortSignal): Promise<SetupTimezoneResponse> {
|
||||
return api.get<SetupTimezoneResponse>(ENDPOINTS.setupTimezone, signal);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user