From 97619f1eb58e5d3bce743994dc47c5f2e68cd309 Mon Sep 17 00:00:00 2001 From: Michael Sloan <89812914+Michael-A-Sloan@users.noreply.github.com> Date: Sun, 2 Aug 2026 17:32:22 -0400 Subject: [PATCH] fix(api): harden request submit path and errors Use ApiClient server address for API calls, return 201 without CreatedAtAction route issues, and surface clearer validation messages when submit fails. Co-authored-by: Cursor --- Directory.Build.props | 6 +- .../Api/CreateRequestDto.cs | 3 - .../Api/RequestController.cs | 13 ++- .../Hosting/WebNavInjector.cs | 2 +- Jellyfin.Plugin.Request/Web/request.js | 89 ++++++++++++++---- build.yaml | 2 +- manifest.json | 10 +- release/Jellyfin.Plugin.Request_1.0.0.7.zip | Bin 0 -> 40783 bytes scripts/package-release.ps1 | 4 +- 9 files changed, 92 insertions(+), 37 deletions(-) create mode 100644 release/Jellyfin.Plugin.Request_1.0.0.7.zip diff --git a/Directory.Build.props b/Directory.Build.props index 1cc7d55..1b37413 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.0.0.6 - 1.0.0.6 - 1.0.0.6 + 1.0.0.7 + 1.0.0.7 + 1.0.0.7 diff --git a/Jellyfin.Plugin.Request/Api/CreateRequestDto.cs b/Jellyfin.Plugin.Request/Api/CreateRequestDto.cs index 05a5a76..2b9edb5 100644 --- a/Jellyfin.Plugin.Request/Api/CreateRequestDto.cs +++ b/Jellyfin.Plugin.Request/Api/CreateRequestDto.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; namespace Jellyfin.Plugin.Request.Api; @@ -11,13 +10,11 @@ public sealed class CreateRequestDto /// /// Gets or sets the media type (movie or tv). /// - [Required] public string MediaType { get; set; } = string.Empty; /// /// Gets or sets the TMDB identifier. /// - [Range(1, int.MaxValue)] public int TmdbId { get; set; } /// diff --git a/Jellyfin.Plugin.Request/Api/RequestController.cs b/Jellyfin.Plugin.Request/Api/RequestController.cs index cbeaafd..918c855 100644 --- a/Jellyfin.Plugin.Request/Api/RequestController.cs +++ b/Jellyfin.Plugin.Request/Api/RequestController.cs @@ -218,19 +218,24 @@ public sealed class RequestController : ControllerBase /// Created request. [HttpPost] public async Task> Create( - [FromBody] CreateRequestDto body, + [FromBody] CreateRequestDto? body, CancellationToken cancellationToken) { var config = GetConfig(); if (!config.EnableRequestSubmission) { - return StatusCode(StatusCodes.Status403Forbidden, new { message = "Request submission is disabled." }); + return StatusCode(StatusCodes.Status403Forbidden, new { message = "Request submission is disabled. Enable it in Dashboard → Plugins → Request." }); } var userId = GetUserId(); if (userId == Guid.Empty) { - return Unauthorized(); + return Unauthorized(new { message = "You must be signed in to submit a request." }); + } + + if (body is null) + { + return BadRequest(new { message = "Request body is required." }); } var mediaType = NormalizeMediaType(body.MediaType); @@ -294,7 +299,7 @@ public sealed class RequestController : ControllerBase }; await _store.AddAsync(request, cancellationToken).ConfigureAwait(false); - return CreatedAtAction(nameof(List), new { id = request.Id }, request); + return StatusCode(StatusCodes.Status201Created, request); } /// diff --git a/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs b/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs index 2810562..9f3c7ff 100644 --- a/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs +++ b/Jellyfin.Plugin.Request/Hosting/WebNavInjector.cs @@ -21,7 +21,7 @@ public sealed class WebNavInjector : IHostedService /// /// Script URL injected into jellyfin-web index.html. /// - public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.0.6"; + public const string LoaderSrc = "/Requests/Assets/nav-loader.js?v=1.0.0.7"; private const string MarkerStart = ""; private const string MarkerEnd = ""; diff --git a/Jellyfin.Plugin.Request/Web/request.js b/Jellyfin.Plugin.Request/Web/request.js index 159f627..8813443 100644 --- a/Jellyfin.Plugin.Request/Web/request.js +++ b/Jellyfin.Plugin.Request/Web/request.js @@ -1,7 +1,20 @@ (() => { "use strict"; - const API = "/Requests"; + function apiRoot() { + try { + if (typeof ApiClient !== "undefined" && typeof ApiClient.serverAddress === "function") { + const base = String(ApiClient.serverAddress() || "").replace(/\/+$/, ""); + if (base) { + return `${base}/Requests`; + } + } + } catch { + // Fall through. + } + + return "/Requests"; + } const MARKUP = `
@@ -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}