97 lines
2.1 KiB
TypeScript
97 lines
2.1 KiB
TypeScript
// metainfo.json 缓存 (7天)
|
|
interface MetaInfoCacheEntry {
|
|
expiresAt: number;
|
|
data: MetaInfo;
|
|
}
|
|
|
|
// videoinfo.json 缓存 (1天)
|
|
interface VideoInfoCacheEntry {
|
|
expiresAt: number;
|
|
data: VideoInfo;
|
|
}
|
|
|
|
const METAINFO_CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7天
|
|
const VIDEOINFO_CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 1天
|
|
|
|
const METAINFO_CACHE: Map<string, MetaInfoCacheEntry> = new Map();
|
|
const VIDEOINFO_CACHE: Map<string, VideoInfoCacheEntry> = new Map();
|
|
|
|
export interface MetaInfo {
|
|
folders: {
|
|
[folderName: string]: {
|
|
tmdb_id: number;
|
|
title: string;
|
|
poster_path: string | null;
|
|
release_date: string;
|
|
overview: string;
|
|
vote_average: number;
|
|
media_type: 'movie' | 'tv';
|
|
last_updated: number;
|
|
};
|
|
};
|
|
last_refresh: number;
|
|
}
|
|
|
|
export interface VideoInfo {
|
|
episodes: {
|
|
[fileName: string]: {
|
|
episode: number;
|
|
season?: number;
|
|
title?: string;
|
|
parsed_from: 'videoinfo' | 'filename';
|
|
};
|
|
};
|
|
last_updated: number;
|
|
}
|
|
|
|
// MetaInfo 缓存操作
|
|
export function getCachedMetaInfo(rootPath: string): MetaInfo | null {
|
|
const entry = METAINFO_CACHE.get(rootPath);
|
|
if (!entry) return null;
|
|
|
|
if (entry.expiresAt <= Date.now()) {
|
|
METAINFO_CACHE.delete(rootPath);
|
|
return null;
|
|
}
|
|
|
|
return entry.data;
|
|
}
|
|
|
|
export function setCachedMetaInfo(rootPath: string, data: MetaInfo): void {
|
|
METAINFO_CACHE.set(rootPath, {
|
|
expiresAt: Date.now() + METAINFO_CACHE_TTL_MS,
|
|
data,
|
|
});
|
|
}
|
|
|
|
export function invalidateMetaInfoCache(rootPath: string): void {
|
|
METAINFO_CACHE.delete(rootPath);
|
|
}
|
|
|
|
// VideoInfo 缓存操作
|
|
export function getCachedVideoInfo(folderPath: string): VideoInfo | null {
|
|
const entry = VIDEOINFO_CACHE.get(folderPath);
|
|
if (!entry) return null;
|
|
|
|
if (entry.expiresAt <= Date.now()) {
|
|
VIDEOINFO_CACHE.delete(folderPath);
|
|
return null;
|
|
}
|
|
|
|
return entry.data;
|
|
}
|
|
|
|
export function setCachedVideoInfo(
|
|
folderPath: string,
|
|
data: VideoInfo
|
|
): void {
|
|
VIDEOINFO_CACHE.set(folderPath, {
|
|
expiresAt: Date.now() + VIDEOINFO_CACHE_TTL_MS,
|
|
data,
|
|
});
|
|
}
|
|
|
|
export function invalidateVideoInfoCache(folderPath: string): void {
|
|
VIDEOINFO_CACHE.delete(folderPath);
|
|
}
|