fix: anime api
This commit is contained in:
@@ -567,14 +567,24 @@ class AniWorldApp {
|
||||
|
||||
// Check if response has the expected format
|
||||
if (Array.isArray(data)) {
|
||||
// API returns array of AnimeSummary objects directly
|
||||
this.seriesData = data.map(anime => ({
|
||||
id: anime.id,
|
||||
name: anime.title,
|
||||
title: anime.title,
|
||||
missing_episodes: anime.missing_episodes || 0,
|
||||
episodeDict: {} // Will be populated when needed
|
||||
}));
|
||||
// API returns array of AnimeSummary objects with full serie data
|
||||
this.seriesData = data.map(anime => {
|
||||
// Count total missing episodes from the episode dictionary
|
||||
const episodeDict = anime.missing_episodes || {};
|
||||
const totalMissing = Object.values(episodeDict).reduce(
|
||||
(sum, episodes) => sum + (Array.isArray(episodes) ? episodes.length : 0),
|
||||
0
|
||||
);
|
||||
|
||||
return {
|
||||
key: anime.key,
|
||||
name: anime.name,
|
||||
site: anime.site,
|
||||
folder: anime.folder,
|
||||
episodeDict: episodeDict,
|
||||
missing_episodes: totalMissing
|
||||
};
|
||||
});
|
||||
} else if (data.status === 'success') {
|
||||
// Legacy format support
|
||||
this.seriesData = data.series;
|
||||
@@ -633,7 +643,7 @@ class AniWorldApp {
|
||||
filtered.sort((a, b) => {
|
||||
if (this.sortAlphabetical) {
|
||||
// Pure alphabetical sorting when A-Z is enabled
|
||||
return (a.name || a.folder).localeCompare(b.name || b.folder);
|
||||
return this.getDisplayName(a).localeCompare(this.getDisplayName(b));
|
||||
} else {
|
||||
// Default sorting: missing episodes first (descending), then by name
|
||||
// Always show series with missing episodes first
|
||||
@@ -705,7 +715,7 @@ class AniWorldApp {
|
||||
${isSelected ? 'checked' : ''}
|
||||
${!canBeSelected ? 'disabled' : ''}>
|
||||
<div class="series-info">
|
||||
<h3>${this.escapeHtml(serie.name)}</h3>
|
||||
<h3>${this.escapeHtml(this.getDisplayName(serie))}</h3>
|
||||
<div class="series-folder">${this.escapeHtml(serie.folder)}</div>
|
||||
</div>
|
||||
<div class="series-status">
|
||||
@@ -849,8 +859,8 @@ class AniWorldApp {
|
||||
|
||||
resultsList.innerHTML = results.map(result => `
|
||||
<div class="search-result-item">
|
||||
<span class="search-result-name">${this.escapeHtml(result.name)}</span>
|
||||
<button class="btn btn-small btn-primary" onclick="app.addSeries('${this.escapeHtml(result.link)}', '${this.escapeHtml(result.name)}')">
|
||||
<span class="search-result-name">${this.escapeHtml(this.getDisplayName(result))}</span>
|
||||
<button class="btn btn-small btn-primary" onclick="app.addSeries('${this.escapeHtml(result.link)}', '${this.escapeHtml(this.getDisplayName(result))}')">
|
||||
<i class="fas fa-plus"></i>
|
||||
Add
|
||||
</button>
|
||||
@@ -1026,6 +1036,24 @@ class AniWorldApp {
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get display name for anime/series object.
|
||||
* Returns name if available and not empty, otherwise returns key.
|
||||
* @param {Object} anime - Anime/series object with name and key properties
|
||||
* @returns {string} Display name
|
||||
*/
|
||||
getDisplayName(anime) {
|
||||
if (!anime) return '';
|
||||
// Use name if it exists and is not empty (after trimming whitespace)
|
||||
const name = anime.name || '';
|
||||
const trimmedName = name.trim();
|
||||
if (trimmedName) {
|
||||
return trimmedName;
|
||||
}
|
||||
// Fallback to key
|
||||
return anime.key || anime.folder || '';
|
||||
}
|
||||
|
||||
updateConnectionStatus() {
|
||||
const indicator = document.getElementById('connection-status-display');
|
||||
if (indicator) {
|
||||
@@ -2017,7 +2045,7 @@ class AniWorldApp {
|
||||
// Update current downloading
|
||||
if (data.current_downloading) {
|
||||
currentDownload.classList.remove('hidden');
|
||||
document.getElementById('current-serie-name').textContent = data.current_downloading.name;
|
||||
document.getElementById('current-serie-name').textContent = this.getDisplayName(data.current_downloading);
|
||||
document.getElementById('current-episode').textContent = `${data.current_downloading.missing_episodes} episodes remaining`;
|
||||
} else {
|
||||
currentDownload.classList.add('hidden');
|
||||
@@ -2028,7 +2056,7 @@ class AniWorldApp {
|
||||
queueList.innerHTML = data.queue.map((serie, index) => `
|
||||
<div class="queue-item">
|
||||
<div class="queue-item-index">${index + 1}</div>
|
||||
<div class="queue-item-name">${this.escapeHtml(serie.name)}</div>
|
||||
<div class="queue-item-name">${this.escapeHtml(this.getDisplayName(serie))}</div>
|
||||
<div class="queue-item-status">Waiting</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
Reference in New Issue
Block a user