fix(ui): normalize request list fields for jellyfin json
Accept PascalCase or camelCase properties so My requests and Admin queue show title, requester, date, and status correctly. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
97619f1eb5
commit
3957c6ac1d
7 files changed
+78
-28
No files matched your search
@@ -131,17 +131,62 @@
|
||||
}
|
||||
|
||||
function statusName(value) {
|
||||
if (typeof value === "string") {
|
||||
if (typeof value === "string" && value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return ["Pending", "Approved", "Rejected", "Fulfilled"][value] || "Unknown";
|
||||
if (typeof value === "number" && value >= 0 && value <= 3) {
|
||||
return ["Pending", "Approved", "Rejected", "Fulfilled"][value];
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
function statusClass(value) {
|
||||
return statusName(value).toLowerCase();
|
||||
}
|
||||
|
||||
function normalizeRequest(item) {
|
||||
if (!item || typeof item !== "object") {
|
||||
return {
|
||||
id: "",
|
||||
mediaType: "",
|
||||
title: "Untitled",
|
||||
year: null,
|
||||
posterPath: null,
|
||||
seasons: [],
|
||||
allSeasons: false,
|
||||
requestedByName: "Unknown",
|
||||
createdAtUtc: null,
|
||||
status: "Unknown",
|
||||
adminNote: null
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
id: item.id ?? item.Id ?? "",
|
||||
mediaType: item.mediaType || item.MediaType || "",
|
||||
title: item.title || item.Title || "Untitled",
|
||||
year: item.year ?? item.Year ?? null,
|
||||
posterPath: item.posterPath || item.PosterPath || null,
|
||||
seasons: item.seasons || item.Seasons || [],
|
||||
allSeasons: !!(item.allSeasons ?? item.AllSeasons),
|
||||
requestedByName: item.requestedByName || item.RequestedByName || "Unknown",
|
||||
createdAtUtc: item.createdAtUtc || item.CreatedAtUtc || null,
|
||||
status: item.status ?? item.Status,
|
||||
adminNote: item.adminNote || item.AdminNote || null
|
||||
};
|
||||
}
|
||||
|
||||
function formatRequestDate(value) {
|
||||
if (!value) {
|
||||
return "Unknown date";
|
||||
}
|
||||
|
||||
const date = new Date(value);
|
||||
return Number.isNaN(date.getTime()) ? "Unknown date" : date.toLocaleString();
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value ?? "")
|
||||
.replaceAll("&", "&")
|
||||
@@ -420,13 +465,16 @@
|
||||
|
||||
async function loadRequests() {
|
||||
try {
|
||||
state.requests = await api("");
|
||||
const raw = await api("");
|
||||
state.requests = (Array.isArray(raw) ? raw : []).map(normalizeRequest);
|
||||
renderRequestList(els.mineList, state.requests, false);
|
||||
if (state.isAdmin) {
|
||||
const pendingFirst = [...state.requests].sort((a, b) => {
|
||||
const aPending = statusName(a.status) === "Pending" ? 0 : 1;
|
||||
const bPending = statusName(b.status) === "Pending" ? 0 : 1;
|
||||
return aPending - bPending || new Date(b.createdAtUtc) - new Date(a.createdAtUtc);
|
||||
const aTime = a.createdAtUtc ? new Date(a.createdAtUtc).getTime() : 0;
|
||||
const bTime = b.createdAtUtc ? new Date(b.createdAtUtc).getTime() : 0;
|
||||
return aPending - bPending || bTime - aTime;
|
||||
});
|
||||
renderRequestList(els.adminList, pendingFirst, true);
|
||||
}
|
||||
@@ -441,21 +489,23 @@
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = items.map((item) => {
|
||||
container.innerHTML = items.map((raw) => {
|
||||
const item = normalizeRequest(raw);
|
||||
const img = posterUrl(item.posterPath, 185);
|
||||
const seasons = item.allSeasons
|
||||
? "All seasons"
|
||||
: (item.seasons || []).length
|
||||
? `Seasons ${(item.seasons || []).join(", ")}`
|
||||
: item.seasons.length
|
||||
? `Seasons ${item.seasons.join(", ")}`
|
||||
: "";
|
||||
const status = statusName(item.status);
|
||||
const actions = adminMode
|
||||
? `
|
||||
<button type="button" class="req-btn" data-action="approve" data-id="${item.id}">Approve</button>
|
||||
<button type="button" class="req-btn" data-action="reject" data-id="${item.id}">Reject</button>
|
||||
<button type="button" class="req-btn" data-action="fulfill" data-id="${item.id}">Fulfilled</button>
|
||||
<button type="button" class="req-btn danger" data-action="delete" data-id="${item.id}">Delete</button>`
|
||||
: (statusName(item.status) === "Pending"
|
||||
? `<button type="button" class="req-btn danger" data-action="delete" data-id="${item.id}">Cancel</button>`
|
||||
<button type="button" class="req-btn" data-action="approve" data-id="${escapeHtml(item.id)}">Approve</button>
|
||||
<button type="button" class="req-btn" data-action="reject" data-id="${escapeHtml(item.id)}">Reject</button>
|
||||
<button type="button" class="req-btn" data-action="fulfill" data-id="${escapeHtml(item.id)}">Fulfilled</button>
|
||||
<button type="button" class="req-btn danger" data-action="delete" data-id="${escapeHtml(item.id)}">Delete</button>`
|
||||
: (status === "Pending"
|
||||
? `<button type="button" class="req-btn danger" data-action="delete" data-id="${escapeHtml(item.id)}">Cancel</button>`
|
||||
: "");
|
||||
|
||||
return `
|
||||
@@ -463,9 +513,9 @@
|
||||
${img ? `<img src="${escapeHtml(img)}" alt="" />` : "<div></div>"}
|
||||
<div>
|
||||
<p class="req-card-title">${escapeHtml(item.title)}</p>
|
||||
<p class="req-muted">${escapeHtml(item.mediaType)}${item.year ? ` · ${item.year}` : ""}${seasons ? ` · ${escapeHtml(seasons)}` : ""}</p>
|
||||
<p class="req-muted">Requested by ${escapeHtml(item.requestedByName)} · ${new Date(item.createdAtUtc).toLocaleString()}</p>
|
||||
<span class="req-badge ${statusClass(item.status)}">${escapeHtml(statusName(item.status))}</span>
|
||||
<p class="req-muted">${escapeHtml(item.mediaType)}${item.year ? ` · ${escapeHtml(item.year)}` : ""}${seasons ? ` · ${escapeHtml(seasons)}` : ""}</p>
|
||||
<p class="req-muted">Requested by ${escapeHtml(item.requestedByName)} · ${escapeHtml(formatRequestDate(item.createdAtUtc))}</p>
|
||||
<span class="req-badge ${statusClass(item.status)}">${escapeHtml(status)}</span>
|
||||
${item.adminNote ? `<p class="req-muted">${escapeHtml(item.adminNote)}</p>` : ""}
|
||||
</div>
|
||||
<div class="req-list-actions">${actions}</div>
|
||||
|
||||
Reference in new issue
Block a user