From 9ac6704bbaf5982abcd4ab1d6f62c182d894a7d9 Mon Sep 17 00:00:00 2001 From: lenafx Date: Tue, 13 Jan 2026 00:41:52 +0100 Subject: [PATCH] empty data or errors from extensions are not cached now --- desktop/src/api/anime/anime.service.ts | 33 +++++++++++++++++++---- desktop/src/api/books/books.service.ts | 36 +++++++++++++++++++------- desktop/src/api/types.ts | 1 + docker/src/api/anime/anime.service.ts | 33 +++++++++++++++++++---- docker/src/api/books/books.service.ts | 30 ++++++++++++++++----- docker/src/api/types.ts | 1 + 6 files changed, 109 insertions(+), 25 deletions(-) diff --git a/desktop/src/api/anime/anime.service.ts b/desktop/src/api/anime/anime.service.ts index 5151fb4..990a186 100644 --- a/desktop/src/api/anime/anime.service.ts +++ b/desktop/src/api/anime/anime.service.ts @@ -181,7 +181,9 @@ export async function getAnimeById(id: string | number): Promise 0) { + await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS); + } return result; } catch (e) { @@ -598,10 +605,26 @@ export async function getStreamData(extension: Extension, episode: string, id: s throw new Error("Episode not found"); } - const streamData = await extension.findEpisodeServer(targetEp, server, category); + let streamData: StreamData; + + try { + streamData = await extension.findEpisodeServer(targetEp, server, category); + } catch (e) { + console.error(`[${providerName}] findEpisodeServer failed`, e); + throw e; + } + + if ( + !streamData || + !Array.isArray(streamData.videoSources) || + streamData.videoSources.length === 0 + ) { + throw new Error("Empty stream data"); + } await setCache(cacheKey, streamData, CACHE_TTL_MS); return streamData; + } function similarity(s1: string, s2: string): number { diff --git a/desktop/src/api/books/books.service.ts b/desktop/src/api/books/books.service.ts index c3f8cef..ef68d7e 100644 --- a/desktop/src/api/books/books.service.ts +++ b/desktop/src/api/books/books.service.ts @@ -123,10 +123,10 @@ export async function getBookById(id: string | number): Promise m.id && m.title); + if (!clean.length) return []; return matches.map(m => ({ id: m.id, extensionName: name, @@ -459,10 +466,13 @@ async function searchChaptersInExtension(ext: Extension, name: string, lookupId: language: ch.language ?? null, })); - await setCache(cacheKey, { - mediaId, - chapters: result - }, CACHE_TTL_MS); + if (result.length > 0) { + await setCache(cacheKey, { + mediaId, + chapters: result + }, CACHE_TTL_MS); + } + return result; } catch (e) { @@ -599,7 +609,15 @@ export async function getChapterContent(bookId: string, chapterId: string, provi throw new Error("Unknown mediaType"); } - await setCache(contentCacheKey, contentResult, CACHE_TTL_MS); + if ( + contentResult && + ( + (contentResult.type === "manga" && contentResult.pages?.length) || + (contentResult.type === "ln" && contentResult.content) + ) + ) { + await setCache(contentCacheKey, contentResult, CACHE_TTL_MS); + } return contentResult; } catch (err) { diff --git a/desktop/src/api/types.ts b/desktop/src/api/types.ts index 512811e..fea1088 100644 --- a/desktop/src/api/types.ts +++ b/desktop/src/api/types.ts @@ -111,6 +111,7 @@ export interface ExtensionSettings { } export interface StreamData { + videoSources: any; url?: string; sources?: any[]; subtitles?: any[]; diff --git a/docker/src/api/anime/anime.service.ts b/docker/src/api/anime/anime.service.ts index 5151fb4..990a186 100644 --- a/docker/src/api/anime/anime.service.ts +++ b/docker/src/api/anime/anime.service.ts @@ -181,7 +181,9 @@ export async function getAnimeById(id: string | number): Promise 0) { + await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS); + } return result; } catch (e) { @@ -598,10 +605,26 @@ export async function getStreamData(extension: Extension, episode: string, id: s throw new Error("Episode not found"); } - const streamData = await extension.findEpisodeServer(targetEp, server, category); + let streamData: StreamData; + + try { + streamData = await extension.findEpisodeServer(targetEp, server, category); + } catch (e) { + console.error(`[${providerName}] findEpisodeServer failed`, e); + throw e; + } + + if ( + !streamData || + !Array.isArray(streamData.videoSources) || + streamData.videoSources.length === 0 + ) { + throw new Error("Empty stream data"); + } await setCache(cacheKey, streamData, CACHE_TTL_MS); return streamData; + } function similarity(s1: string, s2: string): number { diff --git a/docker/src/api/books/books.service.ts b/docker/src/api/books/books.service.ts index 9e2ff96..ef68d7e 100644 --- a/docker/src/api/books/books.service.ts +++ b/docker/src/api/books/books.service.ts @@ -275,7 +275,12 @@ export async function getBookInfoExtension(ext: Extension | null, id: string): P try { const info = await ext.getMetadata(id); - if (info) { + if ( + info && + info.title && + info.title !== "" && + info.title !== "Unknown" + ) { const normalized = { id: info.id ?? id, title: info.title ?? "", @@ -320,6 +325,8 @@ export async function searchBooksInExtension(ext: Extension | null, name: string }); if (matches?.length) { + const clean = matches.filter(m => m.id && m.title); + if (!clean.length) return []; return matches.map(m => ({ id: m.id, extensionName: name, @@ -459,10 +466,13 @@ async function searchChaptersInExtension(ext: Extension, name: string, lookupId: language: ch.language ?? null, })); - await setCache(cacheKey, { - mediaId, - chapters: result - }, CACHE_TTL_MS); + if (result.length > 0) { + await setCache(cacheKey, { + mediaId, + chapters: result + }, CACHE_TTL_MS); + } + return result; } catch (e) { @@ -599,7 +609,15 @@ export async function getChapterContent(bookId: string, chapterId: string, provi throw new Error("Unknown mediaType"); } - await setCache(contentCacheKey, contentResult, CACHE_TTL_MS); + if ( + contentResult && + ( + (contentResult.type === "manga" && contentResult.pages?.length) || + (contentResult.type === "ln" && contentResult.content) + ) + ) { + await setCache(contentCacheKey, contentResult, CACHE_TTL_MS); + } return contentResult; } catch (err) { diff --git a/docker/src/api/types.ts b/docker/src/api/types.ts index 512811e..fea1088 100644 --- a/docker/src/api/types.ts +++ b/docker/src/api/types.ts @@ -111,6 +111,7 @@ export interface ExtensionSettings { } export interface StreamData { + videoSources: any; url?: string; sources?: any[]; subtitles?: any[];