@@ -69,14 +82,30 @@
async function errorMessage(response) {
const text = await response.text();
try {
- return JSON.parse(text).message || `${response.status} ${response.statusText}`;
+ const data = JSON.parse(text);
+ if (data.message) {
+ return data.message;
+ }
+
+ if (data.errors && typeof data.errors === "object") {
+ const details = Object.values(data.errors).flat().filter(Boolean);
+ if (details.length) {
+ return details.join(" ");
+ }
+ }
+
+ if (data.title) {
+ return data.status ? `${data.title} (${data.status})` : data.title;
+ }
} catch {
- return text || `${response.status} ${response.statusText}`;
+ // Fall through.
}
+
+ return text || `${response.status} ${response.statusText}`;
}
async function api(path, options = {}) {
- const response = await fetch(`${API}${path}`, {
+ const response = await fetch(`${apiRoot()}${path}`, {
cache: "no-store",
...options,
headers: {
@@ -285,18 +314,28 @@
}
function renderDetail(detail) {
- const img = detail.posterUrl || posterUrl(detail.posterPath, 500);
- const allowSeasons = state.status?.allowSeasonSelection !== false && detail.mediaType === "tv";
+ const mediaType = detail.mediaType || detail.MediaType || "";
+ const title = detail.title || detail.Title || "Untitled";
+ const year = detail.year ?? detail.Year;
+ const overview = detail.overview || detail.Overview || "No overview available.";
+ const seasons = detail.seasons || detail.Seasons || [];
+ const img = detail.posterUrl || detail.PosterUrl || posterUrl(detail.posterPath || detail.PosterPath, 500);
+ const allowSeasons = state.status?.allowSeasonSelection !== false && mediaType === "tv";
const seasonHtml = allowSeasons
? `
- ${detail.seasons.map((season) => `
+ ${seasons.map((season) => {
+ const seasonNumber = season.seasonNumber ?? season.SeasonNumber;
+ const seasonName = season.name || season.Name || `Season ${seasonNumber}`;
+ const episodeCount = season.episodeCount ?? season.EpisodeCount ?? 0;
+ return `
`).join("")}
+
+ ${escapeHtml(seasonName)} (${escapeHtml(episodeCount)})
+ `;
+ }).join("")}
`
- : detail.mediaType === "tv"
+ : mediaType === "tv"
? `
This request will cover all seasons.
`
: "";
@@ -305,9 +344,9 @@
${img ? `
})
` : "
"}
-
${escapeHtml(detail.title)}
-
${escapeHtml(detail.mediaType)}${detail.year ? ` · ${detail.year}` : ""}
-
${escapeHtml(detail.overview || "No overview available.")}
+
${escapeHtml(title)}
+
${escapeHtml(mediaType)}${year ? ` · ${escapeHtml(year)}` : ""}
+
${escapeHtml(overview)}
${seasonHtml}