Split frontend config API into file_config, server, and health modules
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* API functions for the configuration and server settings endpoints.
|
||||
* API functions for the configuration endpoints.
|
||||
*/
|
||||
|
||||
import { del, get, post, put } from "./client";
|
||||
@@ -41,8 +41,6 @@ import type {
|
||||
MapColorThresholdsUpdate,
|
||||
RegexTestRequest,
|
||||
RegexTestResponse,
|
||||
ServerSettingsResponse,
|
||||
ServerSettingsUpdate,
|
||||
JailFileConfig,
|
||||
JailFileConfigUpdate,
|
||||
ServiceStatusResponse,
|
||||
@@ -139,30 +137,6 @@ export async function previewLog(
|
||||
return post<LogPreviewResponse>(ENDPOINTS.configPreviewLog, req);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Server settings
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function fetchServerSettings(
|
||||
): Promise<ServerSettingsResponse> {
|
||||
return get<ServerSettingsResponse>(ENDPOINTS.serverSettings);
|
||||
}
|
||||
|
||||
export async function updateServerSettings(
|
||||
update: ServerSettingsUpdate
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.serverSettings, update);
|
||||
}
|
||||
|
||||
export async function flushLogs(
|
||||
): Promise<string> {
|
||||
const resp = await post<{ message: string }>(
|
||||
ENDPOINTS.serverFlushLogs,
|
||||
undefined,
|
||||
);
|
||||
return resp.message;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Map color thresholds
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
102
frontend/src/api/file_config.ts
Normal file
102
frontend/src/api/file_config.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { get, post, put } from "./client";
|
||||
import { ENDPOINTS } from "./endpoints";
|
||||
import type {
|
||||
ActionListResponse,
|
||||
ConfFileContent,
|
||||
ConfFileCreateRequest,
|
||||
ConfFileUpdateRequest,
|
||||
ConfFilesResponse,
|
||||
FilterListResponse,
|
||||
JailConfigFileContent,
|
||||
JailConfigFilesResponse,
|
||||
} from "../types/config";
|
||||
|
||||
export async function fetchJailConfigFiles(): Promise<JailConfigFilesResponse> {
|
||||
return get<JailConfigFilesResponse>(ENDPOINTS.configJailFiles);
|
||||
}
|
||||
|
||||
export async function createJailConfigFile(
|
||||
req: ConfFileCreateRequest,
|
||||
): Promise<ConfFileContent> {
|
||||
return post<ConfFileContent>(ENDPOINTS.configJailFiles, req);
|
||||
}
|
||||
|
||||
export async function fetchJailConfigFileContent(
|
||||
filename: string,
|
||||
): Promise<JailConfigFileContent> {
|
||||
return get<JailConfigFileContent>(ENDPOINTS.configJailFile(filename));
|
||||
}
|
||||
|
||||
export async function updateJailConfigFile(
|
||||
filename: string,
|
||||
req: ConfFileUpdateRequest,
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.configJailFile(filename), req);
|
||||
}
|
||||
|
||||
export async function setJailConfigFileEnabled(
|
||||
filename: string,
|
||||
update: { enabled: boolean },
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.configJailFileEnabled(filename), update);
|
||||
}
|
||||
|
||||
export async function fetchFilterFiles(): Promise<ConfFilesResponse> {
|
||||
const result = await get<FilterListResponse>(ENDPOINTS.configFilters);
|
||||
return {
|
||||
files: result.filters.map((filter) => ({
|
||||
name: filter.name,
|
||||
filename: filter.filename,
|
||||
})),
|
||||
total: result.total,
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchFilterFile(
|
||||
name: string,
|
||||
): Promise<ConfFileContent> {
|
||||
return get<ConfFileContent>(ENDPOINTS.configFilterRaw(name));
|
||||
}
|
||||
|
||||
export async function updateFilterFile(
|
||||
name: string,
|
||||
req: ConfFileUpdateRequest,
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.configFilterRaw(name), req);
|
||||
}
|
||||
|
||||
export async function createFilterFile(
|
||||
req: ConfFileCreateRequest,
|
||||
): Promise<ConfFileContent> {
|
||||
return post<ConfFileContent>(ENDPOINTS.configFiltersRaw, req);
|
||||
}
|
||||
|
||||
export async function fetchActionFiles(): Promise<ConfFilesResponse> {
|
||||
const result = await get<ActionListResponse>(ENDPOINTS.configActions);
|
||||
return {
|
||||
files: result.actions.map((action) => ({
|
||||
name: action.name,
|
||||
filename: action.filename,
|
||||
})),
|
||||
total: result.total,
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchActionFile(
|
||||
name: string,
|
||||
): Promise<ConfFileContent> {
|
||||
return get<ConfFileContent>(ENDPOINTS.configActionRaw(name));
|
||||
}
|
||||
|
||||
export async function updateActionFile(
|
||||
name: string,
|
||||
req: ConfFileUpdateRequest,
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.configActionRaw(name), req);
|
||||
}
|
||||
|
||||
export async function createActionFile(
|
||||
req: ConfFileCreateRequest,
|
||||
): Promise<ConfFileContent> {
|
||||
return post<ConfFileContent>(ENDPOINTS.configActions, req);
|
||||
}
|
||||
7
frontend/src/api/health.ts
Normal file
7
frontend/src/api/health.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { get } from "./client";
|
||||
import { ENDPOINTS } from "./endpoints";
|
||||
import type { HealthResponse } from "../types/server";
|
||||
|
||||
export async function fetchHealth(): Promise<HealthResponse> {
|
||||
return get<HealthResponse>(ENDPOINTS.health);
|
||||
}
|
||||
24
frontend/src/api/server.ts
Normal file
24
frontend/src/api/server.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { get, post, put } from "./client";
|
||||
import { ENDPOINTS } from "./endpoints";
|
||||
import type {
|
||||
ServerSettingsResponse,
|
||||
ServerSettingsUpdate,
|
||||
} from "../types/config";
|
||||
|
||||
export async function fetchServerSettings(): Promise<ServerSettingsResponse> {
|
||||
return get<ServerSettingsResponse>(ENDPOINTS.serverSettings);
|
||||
}
|
||||
|
||||
export async function updateServerSettings(
|
||||
update: ServerSettingsUpdate,
|
||||
): Promise<void> {
|
||||
await put<undefined>(ENDPOINTS.serverSettings, update);
|
||||
}
|
||||
|
||||
export async function flushLogs(): Promise<string> {
|
||||
const resp = await post<{ message: string }>(
|
||||
ENDPOINTS.serverFlushLogs,
|
||||
undefined,
|
||||
);
|
||||
return resp.message;
|
||||
}
|
||||
Reference in New Issue
Block a user