feat(repo): add request plugin with jellyfin catalog manifest
Ship the plugin sources, release zip, and SeerrFin-style manifest.json so Jellyfin can install from the Gitea raw repository URL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a1960d860
commit
bf6cd4540f
30 files changed
+3096
No files matched your search
@@ -0,0 +1,380 @@
|
||||
(() => {
|
||||
"use strict";
|
||||
|
||||
const API = "/Requests";
|
||||
const state = {
|
||||
mediaType: "multi",
|
||||
status: null,
|
||||
isAdmin: false,
|
||||
detail: null,
|
||||
requests: []
|
||||
};
|
||||
|
||||
const els = {
|
||||
statusBanner: document.getElementById("statusBanner"),
|
||||
globalMessage: document.getElementById("globalMessage"),
|
||||
searchInput: document.getElementById("searchInput"),
|
||||
searchBtn: document.getElementById("searchBtn"),
|
||||
results: document.getElementById("results"),
|
||||
detail: document.getElementById("detail"),
|
||||
mineList: document.getElementById("mineList"),
|
||||
adminList: document.getElementById("adminList"),
|
||||
adminTab: document.getElementById("adminTab"),
|
||||
searchView: document.getElementById("searchView"),
|
||||
mineView: document.getElementById("mineView"),
|
||||
adminView: document.getElementById("adminView")
|
||||
};
|
||||
|
||||
function authHeader() {
|
||||
try {
|
||||
const raw = localStorage.getItem("jellyfin_credentials");
|
||||
const credentials = raw ? JSON.parse(raw) : null;
|
||||
const server = credentials?.Servers?.find((item) => item.AccessToken) || credentials?.Servers?.[0];
|
||||
const token = server?.AccessToken;
|
||||
if (!token) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
Authorization: `MediaBrowser Client="Request Plugin", Device="Browser", DeviceId="jellyfin-plugin-request", Version="1.0.0", Token="${token}"`,
|
||||
"X-Emby-Token": token
|
||||
};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function errorMessage(response) {
|
||||
const text = await response.text();
|
||||
try {
|
||||
return JSON.parse(text).message || `${response.status} ${response.statusText}`;
|
||||
} catch {
|
||||
return text || `${response.status} ${response.statusText}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function api(path, options = {}) {
|
||||
const response = await fetch(`${API}${path}`, {
|
||||
cache: "no-store",
|
||||
...options,
|
||||
headers: {
|
||||
...authHeader(),
|
||||
...(options.body ? { "Content-Type": "application/json" } : {}),
|
||||
...(options.headers || {})
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(await errorMessage(response));
|
||||
}
|
||||
|
||||
if (response.status === 204) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
return text ? JSON.parse(text) : null;
|
||||
}
|
||||
|
||||
function showMessage(text, isError) {
|
||||
els.globalMessage.textContent = text;
|
||||
els.globalMessage.classList.toggle("req-hidden", !text);
|
||||
els.globalMessage.classList.toggle("req-error", !!isError);
|
||||
}
|
||||
|
||||
function posterUrl(path, width) {
|
||||
return path ? `https://image.tmdb.org/t/p/w${width || 342}${path}` : "";
|
||||
}
|
||||
|
||||
function statusName(value) {
|
||||
if (typeof value === "string") {
|
||||
return value;
|
||||
}
|
||||
|
||||
return ["Pending", "Approved", "Rejected", "Fulfilled"][value] || "Unknown";
|
||||
}
|
||||
|
||||
function statusClass(value) {
|
||||
return statusName(value).toLowerCase();
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value ?? "")
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """);
|
||||
}
|
||||
|
||||
function setView(view) {
|
||||
document.querySelectorAll(".req-tab").forEach((tab) => {
|
||||
tab.classList.toggle("active", tab.dataset.view === view);
|
||||
});
|
||||
els.searchView.classList.toggle("req-hidden", view !== "search");
|
||||
els.mineView.classList.toggle("req-hidden", view !== "mine");
|
||||
els.adminView.classList.toggle("req-hidden", view !== "admin");
|
||||
if (view === "mine" || view === "admin") {
|
||||
loadRequests();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStatus() {
|
||||
try {
|
||||
state.status = await api("/Status");
|
||||
if (!state.status.isConfigured) {
|
||||
els.statusBanner.textContent = "TMDB is not configured. An administrator must set a TMDB API key in Dashboard → Plugins → Request.";
|
||||
els.statusBanner.classList.remove("req-hidden");
|
||||
} else if (!state.status.requestSubmissionEnabled) {
|
||||
els.statusBanner.textContent = "Search is available. Request submission is disabled by the administrator.";
|
||||
els.statusBanner.classList.remove("req-hidden");
|
||||
} else {
|
||||
els.statusBanner.classList.add("req-hidden");
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage(error.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCurrentUser() {
|
||||
try {
|
||||
const response = await fetch("/Users/Me", {
|
||||
cache: "no-store",
|
||||
headers: authHeader()
|
||||
});
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
const me = await response.json();
|
||||
state.isAdmin = !!me?.Policy?.IsAdministrator;
|
||||
els.adminTab.classList.toggle("req-hidden", !state.isAdmin);
|
||||
} catch {
|
||||
// Non-fatal: admin tab stays hidden.
|
||||
}
|
||||
}
|
||||
|
||||
async function runSearch() {
|
||||
const query = els.searchInput.value.trim();
|
||||
if (!query) {
|
||||
showMessage("Enter a search query.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage("Searching…");
|
||||
els.detail.classList.add("req-hidden");
|
||||
try {
|
||||
const results = await api(`/Search?query=${encodeURIComponent(query)}&type=${encodeURIComponent(state.mediaType)}`);
|
||||
showMessage(results.length ? "" : "No results found.");
|
||||
renderResults(results);
|
||||
} catch (error) {
|
||||
showMessage(error.message, true);
|
||||
els.results.innerHTML = "";
|
||||
}
|
||||
}
|
||||
|
||||
function renderResults(results) {
|
||||
els.results.innerHTML = results.map((item) => {
|
||||
const img = item.posterUrl || posterUrl(item.posterPath);
|
||||
return `
|
||||
<article class="req-card" data-type="${escapeHtml(item.mediaType)}" data-id="${item.tmdbId}">
|
||||
${img ? `<img src="${escapeHtml(img)}" alt="" loading="lazy" />` : `<div class="req-card-body"><p class="req-muted">No poster</p></div>`}
|
||||
<div class="req-card-body">
|
||||
<p class="req-card-title">${escapeHtml(item.title)}</p>
|
||||
<p class="req-muted">${escapeHtml(item.mediaType)}${item.year ? ` · ${item.year}` : ""}</p>
|
||||
</div>
|
||||
</article>`;
|
||||
}).join("");
|
||||
|
||||
els.results.querySelectorAll(".req-card").forEach((card) => {
|
||||
card.addEventListener("click", () => openDetail(card.dataset.type, Number(card.dataset.id)));
|
||||
});
|
||||
}
|
||||
|
||||
async function openDetail(type, tmdbId) {
|
||||
showMessage("Loading details…");
|
||||
try {
|
||||
const detail = await api(`/Media/${encodeURIComponent(type)}/${tmdbId}`);
|
||||
state.detail = detail;
|
||||
showMessage("");
|
||||
renderDetail(detail);
|
||||
} catch (error) {
|
||||
showMessage(error.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
function renderDetail(detail) {
|
||||
const img = detail.posterUrl || posterUrl(detail.posterPath, 500);
|
||||
const allowSeasons = state.status?.allowSeasonSelection !== false && detail.mediaType === "tv";
|
||||
const seasonHtml = allowSeasons
|
||||
? `<div class="req-seasons">
|
||||
<label class="req-season"><input type="checkbox" id="allSeasons" checked /> All seasons</label>
|
||||
${detail.seasons.map((season) => `
|
||||
<label class="req-season">
|
||||
<input type="checkbox" class="season-box" value="${season.seasonNumber}" disabled />
|
||||
${escapeHtml(season.name)} <span class="req-muted">(${season.episodeCount})</span>
|
||||
</label>`).join("")}
|
||||
</div>`
|
||||
: detail.mediaType === "tv"
|
||||
? `<p class="req-muted">This request will cover all seasons.</p>`
|
||||
: "";
|
||||
|
||||
els.detail.classList.remove("req-hidden");
|
||||
els.detail.innerHTML = `
|
||||
${img ? `<img class="req-detail-poster" src="${escapeHtml(img)}" alt="" />` : "<div></div>"}
|
||||
<div class="req-detail-meta">
|
||||
<button type="button" class="req-btn" id="backToResults">Back to results</button>
|
||||
<h2 class="req-detail-title">${escapeHtml(detail.title)}</h2>
|
||||
<p class="req-muted">${escapeHtml(detail.mediaType)}${detail.year ? ` · ${detail.year}` : ""}</p>
|
||||
<p>${escapeHtml(detail.overview || "No overview available.")}</p>
|
||||
${seasonHtml}
|
||||
<div class="req-detail-actions">
|
||||
<button type="button" class="req-btn primary" id="submitRequest" ${state.status?.requestSubmissionEnabled ? "" : "disabled"}>
|
||||
Request
|
||||
</button>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
els.results.classList.add("req-hidden");
|
||||
document.getElementById("backToResults").addEventListener("click", () => {
|
||||
els.detail.classList.add("req-hidden");
|
||||
els.results.classList.remove("req-hidden");
|
||||
});
|
||||
|
||||
const allSeasons = document.getElementById("allSeasons");
|
||||
if (allSeasons) {
|
||||
allSeasons.addEventListener("change", () => {
|
||||
document.querySelectorAll(".season-box").forEach((box) => {
|
||||
box.disabled = allSeasons.checked;
|
||||
if (allSeasons.checked) {
|
||||
box.checked = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById("submitRequest").addEventListener("click", () => submitRequest(detail));
|
||||
}
|
||||
|
||||
async function submitRequest(detail) {
|
||||
const payload = {
|
||||
mediaType: detail.mediaType,
|
||||
tmdbId: detail.tmdbId,
|
||||
allSeasons: true,
|
||||
seasons: null
|
||||
};
|
||||
|
||||
const allSeasons = document.getElementById("allSeasons");
|
||||
if (detail.mediaType === "tv" && allSeasons && !allSeasons.checked) {
|
||||
const selected = Array.from(document.querySelectorAll(".season-box:checked")).map((box) => Number(box.value));
|
||||
if (!selected.length) {
|
||||
showMessage("Select at least one season, or choose all seasons.", true);
|
||||
return;
|
||||
}
|
||||
|
||||
payload.allSeasons = false;
|
||||
payload.seasons = selected;
|
||||
}
|
||||
|
||||
try {
|
||||
await api("", { method: "POST", body: JSON.stringify(payload) });
|
||||
showMessage(`Requested “${detail.title}”.`);
|
||||
} catch (error) {
|
||||
showMessage(error.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadRequests() {
|
||||
try {
|
||||
state.requests = await api("");
|
||||
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);
|
||||
});
|
||||
renderRequestList(els.adminList, pendingFirst, true);
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage(error.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
function renderRequestList(container, items, adminMode) {
|
||||
if (!items.length) {
|
||||
container.innerHTML = `<p class="req-message">No requests yet.</p>`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = items.map((item) => {
|
||||
const img = posterUrl(item.posterPath, 185);
|
||||
const seasons = item.allSeasons
|
||||
? "All seasons"
|
||||
: (item.seasons || []).length
|
||||
? `Seasons ${(item.seasons || []).join(", ")}`
|
||||
: "";
|
||||
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>`
|
||||
: "");
|
||||
|
||||
return `
|
||||
<article class="req-list-item">
|
||||
${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>
|
||||
${item.adminNote ? `<p class="req-muted">${escapeHtml(item.adminNote)}</p>` : ""}
|
||||
</div>
|
||||
<div class="req-list-actions">${actions}</div>
|
||||
</article>`;
|
||||
}).join("");
|
||||
|
||||
container.querySelectorAll("[data-action]").forEach((button) => {
|
||||
button.addEventListener("click", () => handleRequestAction(button.dataset.action, button.dataset.id));
|
||||
});
|
||||
}
|
||||
|
||||
async function handleRequestAction(action, id) {
|
||||
try {
|
||||
if (action === "delete") {
|
||||
await api(`/${id}`, { method: "DELETE" });
|
||||
} else {
|
||||
await api(`/${id}/${action}`, { method: "POST", body: "{}" });
|
||||
}
|
||||
|
||||
await loadRequests();
|
||||
showMessage("Updated.");
|
||||
} catch (error) {
|
||||
showMessage(error.message, true);
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelectorAll(".req-tab").forEach((tab) => {
|
||||
tab.addEventListener("click", () => setView(tab.dataset.view));
|
||||
});
|
||||
|
||||
document.querySelectorAll(".req-type-btn").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
document.querySelectorAll(".req-type-btn").forEach((item) => item.classList.remove("active"));
|
||||
button.classList.add("active");
|
||||
state.mediaType = button.dataset.type;
|
||||
});
|
||||
});
|
||||
|
||||
els.searchBtn.addEventListener("click", runSearch);
|
||||
els.searchInput.addEventListener("keydown", (event) => {
|
||||
if (event.key === "Enter") {
|
||||
runSearch();
|
||||
}
|
||||
});
|
||||
|
||||
loadStatus();
|
||||
loadCurrentUser();
|
||||
})();
|
||||
Reference in new issue
Block a user