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; export async function requestRecentFurniResync( fetcher: AdminFetcher, ): Promise { const response = await fetcher(RECENT_FURNI_RESYNC_URL, { method: "POST" }); const payload = (await response.json()) as Record; 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, }; }