diff --git a/apps/backoffice/lib/api.ts b/apps/backoffice/lib/api.ts index 8c99f9d..627dc30 100644 --- a/apps/backoffice/lib/api.ts +++ b/apps/backoffice/lib/api.ts @@ -141,7 +141,7 @@ export function config() { export async function apiFetch( path: string, - init?: RequestInit, + init?: RequestInit & { next?: { revalidate?: number; tags?: string[] } }, ): Promise { const { baseUrl, token } = config(); const headers = new Headers(init?.headers || {}); @@ -150,10 +150,12 @@ export async function apiFetch( headers.set("Content-Type", "application/json"); } + const { next: nextOptions, ...restInit } = init ?? {}; + const res = await fetch(`${baseUrl}${path}`, { - ...init, + ...restInit, headers, - cache: "no-store", + ...(nextOptions ? { next: nextOptions } : { cache: "no-store" as const }), }); if (!res.ok) { @@ -168,7 +170,7 @@ export async function apiFetch( } export async function fetchLibraries() { - return apiFetch("/libraries"); + return apiFetch("/libraries", { next: { revalidate: 30 } }); } export async function createLibrary(name: string, rootPath: string) { @@ -356,7 +358,7 @@ export async function fetchAllSeries( } export async function fetchSeriesStatuses(): Promise { - return apiFetch("/series/statuses"); + return apiFetch("/series/statuses", { next: { revalidate: 300 } }); } export async function searchBooks( @@ -421,7 +423,7 @@ export type ThumbnailStats = { }; export async function getSettings() { - return apiFetch("/settings"); + return apiFetch("/settings", { next: { revalidate: 60 } }); } export async function updateSetting(key: string, value: unknown) { @@ -432,7 +434,7 @@ export async function updateSetting(key: string, value: unknown) { } export async function getCacheStats() { - return apiFetch("/settings/cache/stats"); + return apiFetch("/settings/cache/stats", { next: { revalidate: 30 } }); } export async function clearCache() { @@ -442,7 +444,7 @@ export async function clearCache() { } export async function getThumbnailStats() { - return apiFetch("/settings/thumbnail/stats"); + return apiFetch("/settings/thumbnail/stats", { next: { revalidate: 30 } }); } // Status mappings @@ -453,7 +455,7 @@ export type StatusMappingDto = { }; export async function fetchStatusMappings(): Promise { - return apiFetch("/settings/status-mappings"); + return apiFetch("/settings/status-mappings", { next: { revalidate: 60 } }); } export async function upsertStatusMapping(provider_status: string, mapped_status: string): Promise { @@ -558,7 +560,7 @@ export type StatsResponse = { }; export async function fetchStats() { - return apiFetch("/stats"); + return apiFetch("/stats", { next: { revalidate: 30 } }); } // ---------------------------------------------------------------------------