Files
UHD_Media_Tool/apps/web/app/api/cache.ts
T
rootandClaude Opus 5.5 7862573944 feat(cache): TMDB image proxy, posters, cache admin API and settings cards
GET /img/tmdb/{size}/{file} ported from MP ImageHelper / fetch_image
(sanitized cache path under DATA_DIR/cache/images, GLOBAL_IMAGE_CACHE
read switch, md5 ETag / 304, day-based cleanup job). Cache module adds
cache.sweep / cache.images_clean jobs and /cache/tmdb, /cache/images
list and clear endpoints. Library list/detail and the search palette
show posters with the neutral placeholder as fallback; metadata settings
get TMDB cache and image cache cards. Runbook docs/runbook/cache.md and
porting notes docs/porting/moviepilot-tmdb-cache.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-28 22:26:29 +08:00

38 lines
1.2 KiB
TypeScript

import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type { CacheClearResult, ImageCacheStatus, TmdbCacheList } from "@umt/contracts";
import { apiData } from "~/lib/api.ts";
// C2-A 缓存管理:TMDB 缓存(条数 / 上限 / TTL / 清空)、图片代理缓存(用量 / 清空)
const keys = { tmdb: ["cache", "tmdb"] as const, images: ["cache", "images"] as const };
export function useTmdbCache() {
return useQuery({
queryKey: keys.tmdb,
queryFn: ({ signal }) => apiData<TmdbCacheList>("/cache/tmdb?limit=1", { signal }),
});
}
export function useClearTmdbCache() {
const qc = useQueryClient();
return useMutation({
mutationFn: () => apiData<CacheClearResult>("/cache/tmdb/clear", { method: "POST" }),
onSuccess: () => qc.invalidateQueries({ queryKey: keys.tmdb }),
});
}
export function useImageCache() {
return useQuery({
queryKey: keys.images,
queryFn: ({ signal }) => apiData<ImageCacheStatus>("/cache/images", { signal }),
});
}
export function useClearImageCache() {
const qc = useQueryClient();
return useMutation({
mutationFn: () => apiData<CacheClearResult>("/cache/images/clear", { method: "POST" }),
onSuccess: () => qc.invalidateQueries({ queryKey: keys.images }),
});
}