improvement on my lists

This commit is contained in:
2025-12-07 02:48:56 +01:00
parent 1973069949
commit 220bbed16a
2 changed files with 109 additions and 64 deletions

View File

@@ -117,14 +117,12 @@ export async function getUserList(userId: number): Promise<any> {
try {
const dbList = await queryAll(sql, [userId], USER_DB) as ListEntryData[];
const connected = await isConnected(userId);
let finalList: ListEntryData[] = [...dbList];
let finalList: any[] = [...dbList];
if (connected) {
const anilistEntries = await aniListService.getUserAniList(userId);
const localWithoutAnilist = dbList.filter(
entry => entry.source !== 'anilist'
);
@@ -133,42 +131,46 @@ export async function getUserList(userId: number): Promise<any> {
}
const enrichedListPromises = finalList.map(async (entry) => {
// ✅ Si viene de AniList, ya está completo → NO fetch
if (entry.source === 'anilist') {
let finalTitle = entry.title;
if (typeof finalTitle === 'object' && finalTitle !== null) {
finalTitle =
finalTitle.userPreferred ||
finalTitle.english ||
finalTitle.romaji ||
'Unknown Title';
}
return {
...entry,
title: finalTitle,
poster: entry.poster || 'https://placehold.co/400x600?text=No+Cover',
};
}
// ✅ Solo se hace fetch para fuentes NO AniList
let contentDetails: any | null = null;
const id = entry.entry_id;
const source = entry.source;
const type = entry.entry_type;
const ext = getExtension(entry.source);
try {
if (type === 'ANIME') {
let anime: any;
if (source === 'anilist') {
anime = await animeService.getAnimeById(id);
} else {
const ext = getExtension(source);
anime = await animeService.getAnimeInfoExtension(ext, id.toString());
}
const anime: any = await animeService.getAnimeInfoExtension(ext, id.toString());
contentDetails = {
title: anime?.title || 'Unknown Anime Title',
poster: anime?.coverImage?.extraLarge || anime?.image || '',
total_episodes: anime?.episodes || anime?.nextAiringEpisode?.episode - 1 || 0,
poster: anime?.image || '',
total_episodes: anime?.episodes || 0,
};
} else if (type === 'MANGA' || type === 'NOVEL') {
let book: any;
if (source === 'anilist') {
book = await booksService.getBookById(id);
} else {
const ext = getExtension(source);
const result = await booksService.getBookInfoExtension(ext, id.toString());
book = result || null;
}
const book:any = await booksService.getBookInfoExtension(ext, id.toString());
contentDetails = {
title: book?.title || 'Unknown Book Title',
poster: book?.coverImage?.extraLarge || book?.image || '',
poster: book?.image || '',
total_chapters: book?.chapters || book?.volumes * 10 || 0,
};
}
@@ -184,7 +186,11 @@ export async function getUserList(userId: number): Promise<any> {
let finalPoster = contentDetails?.poster || 'https://placehold.co/400x600?text=No+Cover';
if (typeof finalTitle === 'object' && finalTitle !== null) {
finalTitle = finalTitle.userPreferred || finalTitle.english || finalTitle.romaji || 'Unknown Title';
finalTitle =
finalTitle.userPreferred ||
finalTitle.english ||
finalTitle.romaji ||
'Unknown Title';
}
return {