empty data or errors from extensions are not cached now
This commit is contained in:
@@ -181,7 +181,9 @@ export async function getAnimeById(id: string | number): Promise<Anime | { error
|
||||
`;
|
||||
|
||||
const data = await fetchAniList(query, { id: Number(id) });
|
||||
if (!data?.Media) return { error: "Anime not found" };
|
||||
if (!data?.Media || !data.Media.title) {
|
||||
return { error: "Anime not found" };
|
||||
}
|
||||
|
||||
await queryOne(
|
||||
"INSERT INTO anime (id, title, updatedAt, full_data) VALUES (?, ?, ?, ?)",
|
||||
@@ -354,7 +356,11 @@ export async function getAnimeInfoExtension(ext: Extension | null, id: string):
|
||||
try {
|
||||
const match = await ext.getMetadata(id);
|
||||
|
||||
if (match) {
|
||||
if (
|
||||
match &&
|
||||
match.title &&
|
||||
match.title !== "Unknown"
|
||||
) {
|
||||
const normalized: any = {
|
||||
title: match.title ?? "Unknown",
|
||||
summary: match.summary ?? "No summary available",
|
||||
@@ -524,8 +530,9 @@ export async function searchEpisodesInExtension(ext: Extension | null, name: str
|
||||
title: ep.title
|
||||
}));
|
||||
|
||||
// Cachear tanto el mediaId como los episodios
|
||||
await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS);
|
||||
if (result.length > 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 {
|
||||
|
||||
@@ -123,10 +123,10 @@ export async function getBookById(id: string | number): Promise<Book | { error:
|
||||
const insertSql = `
|
||||
INSERT INTO books (id, title, updatedAt, full_data)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
title = EXCLUDED.title,
|
||||
updatedAt = EXCLUDED.updatedAt,
|
||||
full_data = EXCLUDED.full_data;
|
||||
updatedAt = EXCLUDED.updatedAt,
|
||||
full_data = EXCLUDED.full_data;
|
||||
`;
|
||||
|
||||
await run(insertSql, [
|
||||
@@ -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) {
|
||||
|
||||
@@ -111,6 +111,7 @@ export interface ExtensionSettings {
|
||||
}
|
||||
|
||||
export interface StreamData {
|
||||
videoSources: any;
|
||||
url?: string;
|
||||
sources?: any[];
|
||||
subtitles?: any[];
|
||||
|
||||
@@ -181,7 +181,9 @@ export async function getAnimeById(id: string | number): Promise<Anime | { error
|
||||
`;
|
||||
|
||||
const data = await fetchAniList(query, { id: Number(id) });
|
||||
if (!data?.Media) return { error: "Anime not found" };
|
||||
if (!data?.Media || !data.Media.title) {
|
||||
return { error: "Anime not found" };
|
||||
}
|
||||
|
||||
await queryOne(
|
||||
"INSERT INTO anime (id, title, updatedAt, full_data) VALUES (?, ?, ?, ?)",
|
||||
@@ -354,7 +356,11 @@ export async function getAnimeInfoExtension(ext: Extension | null, id: string):
|
||||
try {
|
||||
const match = await ext.getMetadata(id);
|
||||
|
||||
if (match) {
|
||||
if (
|
||||
match &&
|
||||
match.title &&
|
||||
match.title !== "Unknown"
|
||||
) {
|
||||
const normalized: any = {
|
||||
title: match.title ?? "Unknown",
|
||||
summary: match.summary ?? "No summary available",
|
||||
@@ -524,8 +530,9 @@ export async function searchEpisodesInExtension(ext: Extension | null, name: str
|
||||
title: ep.title
|
||||
}));
|
||||
|
||||
// Cachear tanto el mediaId como los episodios
|
||||
await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS);
|
||||
if (result.length > 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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -111,6 +111,7 @@ export interface ExtensionSettings {
|
||||
}
|
||||
|
||||
export interface StreamData {
|
||||
videoSources: any;
|
||||
url?: string;
|
||||
sources?: any[];
|
||||
subtitles?: any[];
|
||||
|
||||
Reference in New Issue
Block a user