50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
export const RECENT_FURNI_RESYNC_URL = "/api/admin/import/furni/resync?days=7";
|
|
|
|
export interface RecentFurniResyncError {
|
|
classname: string;
|
|
message: string;
|
|
}
|
|
|
|
export interface RecentFurniResyncResult {
|
|
examined: number;
|
|
resynced: number;
|
|
failed: number;
|
|
rconOk: boolean;
|
|
errors: RecentFurniResyncError[];
|
|
}
|
|
|
|
type AdminFetcher = (
|
|
input: RequestInfo | URL,
|
|
init?: RequestInit,
|
|
) => Promise<Response>;
|
|
|
|
export async function requestRecentFurniResync(
|
|
fetcher: AdminFetcher,
|
|
): Promise<RecentFurniResyncResult> {
|
|
const response = await fetcher(RECENT_FURNI_RESYNC_URL, { method: "POST" });
|
|
const payload = (await response.json()) as Record<string, unknown>;
|
|
if (!response.ok) {
|
|
throw new Error(
|
|
typeof payload.error === "string" ? payload.error : "Furni resync failed",
|
|
);
|
|
}
|
|
|
|
const errors = Array.isArray(payload.errors)
|
|
? payload.errors.filter(
|
|
(value): value is RecentFurniResyncError =>
|
|
typeof value === "object" &&
|
|
value !== null &&
|
|
typeof (value as RecentFurniResyncError).classname === "string" &&
|
|
typeof (value as RecentFurniResyncError).message === "string",
|
|
)
|
|
: [];
|
|
|
|
return {
|
|
examined: Number(payload.examined) || 0,
|
|
resynced: Number(payload.resynced) || 0,
|
|
failed: Number(payload.failed) || 0,
|
|
rconOk: payload.rconOk === true,
|
|
errors,
|
|
};
|
|
}
|