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) });
|
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(
|
await queryOne(
|
||||||
"INSERT INTO anime (id, title, updatedAt, full_data) VALUES (?, ?, ?, ?)",
|
"INSERT INTO anime (id, title, updatedAt, full_data) VALUES (?, ?, ?, ?)",
|
||||||
@@ -354,7 +356,11 @@ export async function getAnimeInfoExtension(ext: Extension | null, id: string):
|
|||||||
try {
|
try {
|
||||||
const match = await ext.getMetadata(id);
|
const match = await ext.getMetadata(id);
|
||||||
|
|
||||||
if (match) {
|
if (
|
||||||
|
match &&
|
||||||
|
match.title &&
|
||||||
|
match.title !== "Unknown"
|
||||||
|
) {
|
||||||
const normalized: any = {
|
const normalized: any = {
|
||||||
title: match.title ?? "Unknown",
|
title: match.title ?? "Unknown",
|
||||||
summary: match.summary ?? "No summary available",
|
summary: match.summary ?? "No summary available",
|
||||||
@@ -524,8 +530,9 @@ export async function searchEpisodesInExtension(ext: Extension | null, name: str
|
|||||||
title: ep.title
|
title: ep.title
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Cachear tanto el mediaId como los episodios
|
if (result.length > 0) {
|
||||||
await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS);
|
await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -598,10 +605,26 @@ export async function getStreamData(extension: Extension, episode: string, id: s
|
|||||||
throw new Error("Episode not found");
|
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);
|
await setCache(cacheKey, streamData, CACHE_TTL_MS);
|
||||||
return streamData;
|
return streamData;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function similarity(s1: string, s2: string): number {
|
function similarity(s1: string, s2: string): number {
|
||||||
|
|||||||
@@ -123,10 +123,10 @@ export async function getBookById(id: string | number): Promise<Book | { error:
|
|||||||
const insertSql = `
|
const insertSql = `
|
||||||
INSERT INTO books (id, title, updatedAt, full_data)
|
INSERT INTO books (id, title, updatedAt, full_data)
|
||||||
VALUES (?, ?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
ON CONFLICT(id) DO UPDATE SET
|
ON CONFLICT(id) DO UPDATE SET
|
||||||
title = EXCLUDED.title,
|
title = EXCLUDED.title,
|
||||||
updatedAt = EXCLUDED.updatedAt,
|
updatedAt = EXCLUDED.updatedAt,
|
||||||
full_data = EXCLUDED.full_data;
|
full_data = EXCLUDED.full_data;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
await run(insertSql, [
|
await run(insertSql, [
|
||||||
@@ -275,7 +275,12 @@ export async function getBookInfoExtension(ext: Extension | null, id: string): P
|
|||||||
try {
|
try {
|
||||||
const info = await ext.getMetadata(id);
|
const info = await ext.getMetadata(id);
|
||||||
|
|
||||||
if (info) {
|
if (
|
||||||
|
info &&
|
||||||
|
info.title &&
|
||||||
|
info.title !== "" &&
|
||||||
|
info.title !== "Unknown"
|
||||||
|
) {
|
||||||
const normalized = {
|
const normalized = {
|
||||||
id: info.id ?? id,
|
id: info.id ?? id,
|
||||||
title: info.title ?? "",
|
title: info.title ?? "",
|
||||||
@@ -320,6 +325,8 @@ export async function searchBooksInExtension(ext: Extension | null, name: string
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (matches?.length) {
|
if (matches?.length) {
|
||||||
|
const clean = matches.filter(m => m.id && m.title);
|
||||||
|
if (!clean.length) return [];
|
||||||
return matches.map(m => ({
|
return matches.map(m => ({
|
||||||
id: m.id,
|
id: m.id,
|
||||||
extensionName: name,
|
extensionName: name,
|
||||||
@@ -459,10 +466,13 @@ async function searchChaptersInExtension(ext: Extension, name: string, lookupId:
|
|||||||
language: ch.language ?? null,
|
language: ch.language ?? null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await setCache(cacheKey, {
|
if (result.length > 0) {
|
||||||
mediaId,
|
await setCache(cacheKey, {
|
||||||
chapters: result
|
mediaId,
|
||||||
}, CACHE_TTL_MS);
|
chapters: result
|
||||||
|
}, CACHE_TTL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -599,7 +609,15 @@ export async function getChapterContent(bookId: string, chapterId: string, provi
|
|||||||
throw new Error("Unknown mediaType");
|
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;
|
return contentResult;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ export interface ExtensionSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface StreamData {
|
export interface StreamData {
|
||||||
|
videoSources: any;
|
||||||
url?: string;
|
url?: string;
|
||||||
sources?: any[];
|
sources?: any[];
|
||||||
subtitles?: 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) });
|
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(
|
await queryOne(
|
||||||
"INSERT INTO anime (id, title, updatedAt, full_data) VALUES (?, ?, ?, ?)",
|
"INSERT INTO anime (id, title, updatedAt, full_data) VALUES (?, ?, ?, ?)",
|
||||||
@@ -354,7 +356,11 @@ export async function getAnimeInfoExtension(ext: Extension | null, id: string):
|
|||||||
try {
|
try {
|
||||||
const match = await ext.getMetadata(id);
|
const match = await ext.getMetadata(id);
|
||||||
|
|
||||||
if (match) {
|
if (
|
||||||
|
match &&
|
||||||
|
match.title &&
|
||||||
|
match.title !== "Unknown"
|
||||||
|
) {
|
||||||
const normalized: any = {
|
const normalized: any = {
|
||||||
title: match.title ?? "Unknown",
|
title: match.title ?? "Unknown",
|
||||||
summary: match.summary ?? "No summary available",
|
summary: match.summary ?? "No summary available",
|
||||||
@@ -524,8 +530,9 @@ export async function searchEpisodesInExtension(ext: Extension | null, name: str
|
|||||||
title: ep.title
|
title: ep.title
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Cachear tanto el mediaId como los episodios
|
if (result.length > 0) {
|
||||||
await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS);
|
await setCache(cacheKey, { mediaId, episodes: result }, CACHE_TTL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -598,10 +605,26 @@ export async function getStreamData(extension: Extension, episode: string, id: s
|
|||||||
throw new Error("Episode not found");
|
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);
|
await setCache(cacheKey, streamData, CACHE_TTL_MS);
|
||||||
return streamData;
|
return streamData;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function similarity(s1: string, s2: string): number {
|
function similarity(s1: string, s2: string): number {
|
||||||
|
|||||||
@@ -275,7 +275,12 @@ export async function getBookInfoExtension(ext: Extension | null, id: string): P
|
|||||||
try {
|
try {
|
||||||
const info = await ext.getMetadata(id);
|
const info = await ext.getMetadata(id);
|
||||||
|
|
||||||
if (info) {
|
if (
|
||||||
|
info &&
|
||||||
|
info.title &&
|
||||||
|
info.title !== "" &&
|
||||||
|
info.title !== "Unknown"
|
||||||
|
) {
|
||||||
const normalized = {
|
const normalized = {
|
||||||
id: info.id ?? id,
|
id: info.id ?? id,
|
||||||
title: info.title ?? "",
|
title: info.title ?? "",
|
||||||
@@ -320,6 +325,8 @@ export async function searchBooksInExtension(ext: Extension | null, name: string
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (matches?.length) {
|
if (matches?.length) {
|
||||||
|
const clean = matches.filter(m => m.id && m.title);
|
||||||
|
if (!clean.length) return [];
|
||||||
return matches.map(m => ({
|
return matches.map(m => ({
|
||||||
id: m.id,
|
id: m.id,
|
||||||
extensionName: name,
|
extensionName: name,
|
||||||
@@ -459,10 +466,13 @@ async function searchChaptersInExtension(ext: Extension, name: string, lookupId:
|
|||||||
language: ch.language ?? null,
|
language: ch.language ?? null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await setCache(cacheKey, {
|
if (result.length > 0) {
|
||||||
mediaId,
|
await setCache(cacheKey, {
|
||||||
chapters: result
|
mediaId,
|
||||||
}, CACHE_TTL_MS);
|
chapters: result
|
||||||
|
}, CACHE_TTL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -599,7 +609,15 @@ export async function getChapterContent(bookId: string, chapterId: string, provi
|
|||||||
throw new Error("Unknown mediaType");
|
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;
|
return contentResult;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ export interface ExtensionSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface StreamData {
|
export interface StreamData {
|
||||||
|
videoSources: any;
|
||||||
url?: string;
|
url?: string;
|
||||||
sources?: any[];
|
sources?: any[];
|
||||||
subtitles?: any[];
|
subtitles?: any[];
|
||||||
|
|||||||
Reference in New Issue
Block a user