bug fixes

This commit is contained in:
2025-11-28 13:12:42 +01:00
parent 2b29beeeb5
commit df1b9a5edd
4 changed files with 70 additions and 25 deletions

View File

@@ -23,8 +23,8 @@ fastify.register(require('@fastify/static'), {
}); });
fastify.register(require('@fastify/static'), { fastify.register(require('@fastify/static'), {
root: path.join(__dirname, 'src'), root: path.join(__dirname, 'src', 'scripts'),
prefix: '/src/', prefix: '/src/scripts/',
decorateReply: false decorateReply: false
}); });

View File

@@ -20,35 +20,70 @@ async function loadAnime() {
return; return;
} }
const title = data.title.english || data.title.romaji; const title = data.title?.english || data.title?.romaji || "Unknown Title";
document.title = `${title} | WaifuBoard`; document.title = `${title} | WaifuBoard`;
document.getElementById('title').innerText = title; document.getElementById('title').innerText = title;
document.getElementById('poster').src = data.coverImage.extraLarge; if (data.coverImage?.extraLarge) {
document.getElementById('poster').src = data.coverImage.extraLarge;
}
const rawDesc = data.description || "No description available."; const rawDesc = data.description || "No description available.";
handleDescription(rawDesc); handleDescription(rawDesc);
document.getElementById('score').innerText = (data.averageScore || '?') + '% Score'; document.getElementById('score').innerText = (data.averageScore || '?') + '% Score';
document.getElementById('year').innerText = data.seasonYear || '????'; document.getElementById('year').innerText = data.seasonYear || data.startDate?.year || '????';
document.getElementById('genres').innerText = data.genres ? data.genres.slice(0, 3).join(' • ') : ''; document.getElementById('genres').innerText = data.genres?.length > 0 ? data.genres.slice(0, 3).join(' • ') : '';
document.getElementById('format').innerText = data.format || 'TV'; document.getElementById('format').innerText = data.format || 'TV';
document.getElementById('episodes').innerText = data.episodes || '?';
document.getElementById('status').innerText = data.status || 'Unknown'; document.getElementById('status').innerText = data.status || 'Unknown';
document.getElementById('season').innerText = `${data.season || ''} ${data.seasonYear || ''}`;
if (data.studios && data.studios.nodes.length > 0) { let seasonText = '';
document.getElementById('studio').innerText = data.studios.nodes[0].name; if (data.season && data.seasonYear) {
seasonText = `${data.season} ${data.seasonYear}`;
} else if (data.startDate?.year) {
const months = ['', 'Winter', 'Winter', 'Spring', 'Spring', 'Spring', 'Summer', 'Summer', 'Summer', 'Fall', 'Fall', 'Fall', 'Winter'];
const month = data.startDate.month || 1;
const estimatedSeason = months[month] || '';
seasonText = `${estimatedSeason} ${data.startDate.year}`.trim();
}
document.getElementById('season').innerText = seasonText || 'Unknown';
let studioName = 'Unknown Studio';
if (data.studios?.nodes?.length > 0) {
studioName = data.studios.nodes[0].name;
} else if (data.studios?.edges?.length > 0) {
studioName = data.studios.edges[0]?.node?.name || 'Unknown Studio';
}
document.getElementById('studio').innerText = studioName;
const charContainer = document.getElementById('char-list');
charContainer.innerHTML = '';
let characters = [];
if (data.characters?.nodes?.length > 0) {
characters = data.characters.nodes.slice(0, 5);
}
else if (data.characters?.edges?.length > 0) {
characters = data.characters.edges
.filter(edge => edge?.node?.name?.full)
.slice(0, 5)
.map(edge => edge.node);
} }
if (data.characters && data.characters.nodes) { if (characters.length > 0) {
const charContainer = document.getElementById('char-list'); characters.forEach(char => {
data.characters.nodes.slice(0, 5).forEach(char => { if (char?.name?.full) {
charContainer.innerHTML += ` charContainer.innerHTML += `
<div class="character-item"> <div class="character-item">
<div class="char-dot"></div> ${char.name.full} <div class="char-dot"></div> ${char.name.full}
</div>`; </div>`;
}
}); });
} else {
charContainer.innerHTML = `
<div class="character-item" style="color: #666;">
No character data available
</div>`;
} }
document.getElementById('watch-btn').onclick = () => { document.getElementById('watch-btn').onclick = () => {
@@ -70,23 +105,28 @@ async function loadAnime() {
}); });
}; };
} else { } else {
const banner = data.bannerImage || data.coverImage.extraLarge; const banner = data.bannerImage || data.coverImage?.extraLarge || '';
document.querySelector('.video-background').innerHTML = `<img src="${banner}" style="width:100%; height:100%; object-fit:cover;">`; if (banner) {
document.querySelector('.video-background').innerHTML = `<img src="${banner}" style="width:100%; height:100%; object-fit:cover;">`;
}
} }
if (data.episodes) {
if (data.nextAiringEpisode) { totalEpisodes = data.episodes;
} else if (data.nextAiringEpisode?.episode) {
totalEpisodes = data.nextAiringEpisode.episode - 1; totalEpisodes = data.nextAiringEpisode.episode - 1;
} else { } else {
totalEpisodes = data.episodes || 12; totalEpisodes = 12;
} }
totalEpisodes = Math.min(Math.max(totalEpisodes, 1), 5000); totalEpisodes = Math.min(Math.max(totalEpisodes, 1), 5000);
document.getElementById('episodes').innerText = totalEpisodes;
renderEpisodes(); renderEpisodes();
} catch (err) { } catch (err) {
console.error(err); console.error('Error loading anime:', err);
document.getElementById('title').innerText = "Error loading anime";
} }
} }

View File

@@ -8,6 +8,7 @@ async function init() {
try { try {
const res = await fetch(`/api/book/${bookId}`); const res = await fetch(`/api/book/${bookId}`);
const data = await res.json(); const data = await res.json();
console.log(data)
if (data.error) { if (data.error) {
const titleEl = document.getElementById('title'); const titleEl = document.getElementById('title');

View File

@@ -448,12 +448,16 @@ document.querySelectorAll('[data-direction]').forEach(btn => {
}); });
prevBtn.addEventListener('click', () => { prevBtn.addEventListener('click', () => {
const newChapter = String(parseInt(chapter) - 1); const current = parseInt(chapter);
if (current <= 0) return;
const newChapter = String(current - 1);
updateURL(newChapter); updateURL(newChapter);
window.scrollTo(0, 0); window.scrollTo(0, 0);
loadChapter(); loadChapter();
}); });
nextBtn.addEventListener('click', () => { nextBtn.addEventListener('click', () => {
const newChapter = String(parseInt(chapter) + 1); const newChapter = String(parseInt(chapter) + 1);
updateURL(newChapter); updateURL(newChapter);