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 <cursoragent@cursor.com>
This commit is contained in:
1 parent
bfa8115fd0
commit
97619f1eb5
9 files changed
+92
-37
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.0.0.6</Version>
|
<Version>1.0.0.7</Version>
|
||||||
<AssemblyVersion>1.0.0.6</AssemblyVersion>
|
<AssemblyVersion>1.0.0.7</AssemblyVersion>
|
||||||
<FileVersion>1.0.0.6</FileVersion>
|
<FileVersion>1.0.0.7</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace Jellyfin.Plugin.Request.Api;
|
namespace Jellyfin.Plugin.Request.Api;
|
||||||
|
|
||||||
@@ -11,13 +10,11 @@ public sealed class CreateRequestDto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the media type (<c>movie</c> or <c>tv</c>).
|
/// Gets or sets the media type (<c>movie</c> or <c>tv</c>).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required]
|
|
||||||
public string MediaType { get; set; } = string.Empty;
|
public string MediaType { get; set; } = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the TMDB identifier.
|
/// Gets or sets the TMDB identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Range(1, int.MaxValue)]
|
|
||||||
public int TmdbId { get; set; }
|
public int TmdbId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -218,19 +218,24 @@ public sealed class RequestController : ControllerBase
|
|||||||
/// <returns>Created request.</returns>
|
/// <returns>Created request.</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<ActionResult<MediaRequest>> Create(
|
public async Task<ActionResult<MediaRequest>> Create(
|
||||||
[FromBody] CreateRequestDto body,
|
[FromBody] CreateRequestDto? body,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var config = GetConfig();
|
var config = GetConfig();
|
||||||
if (!config.EnableRequestSubmission)
|
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();
|
var userId = GetUserId();
|
||||||
if (userId == Guid.Empty)
|
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);
|
var mediaType = NormalizeMediaType(body.MediaType);
|
||||||
@@ -294,7 +299,7 @@ public sealed class RequestController : ControllerBase
|
|||||||
};
|
};
|
||||||
|
|
||||||
await _store.AddAsync(request, cancellationToken).ConfigureAwait(false);
|
await _store.AddAsync(request, cancellationToken).ConfigureAwait(false);
|
||||||
return CreatedAtAction(nameof(List), new { id = request.Id }, request);
|
return StatusCode(StatusCodes.Status201Created, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public sealed class WebNavInjector : IHostedService
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Script URL injected into jellyfin-web index.html.
|
/// Script URL injected into jellyfin-web index.html.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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 = "<!-- jellyfin-plugin-request-nav-start -->";
|
private const string MarkerStart = "<!-- jellyfin-plugin-request-nav-start -->";
|
||||||
private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
|
private const string MarkerEnd = "<!-- jellyfin-plugin-request-nav-end -->";
|
||||||
|
|||||||
@@ -1,7 +1,20 @@
|
|||||||
(() => {
|
(() => {
|
||||||
"use strict";
|
"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 = `
|
const MARKUP = `
|
||||||
<div class="req-root">
|
<div class="req-root">
|
||||||
@@ -69,14 +82,30 @@
|
|||||||
async function errorMessage(response) {
|
async function errorMessage(response) {
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
try {
|
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 {
|
} catch {
|
||||||
return text || `${response.status} ${response.statusText}`;
|
// Fall through.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return text || `${response.status} ${response.statusText}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function api(path, options = {}) {
|
async function api(path, options = {}) {
|
||||||
const response = await fetch(`${API}${path}`, {
|
const response = await fetch(`${apiRoot()}${path}`, {
|
||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -285,18 +314,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderDetail(detail) {
|
function renderDetail(detail) {
|
||||||
const img = detail.posterUrl || posterUrl(detail.posterPath, 500);
|
const mediaType = detail.mediaType || detail.MediaType || "";
|
||||||
const allowSeasons = state.status?.allowSeasonSelection !== false && detail.mediaType === "tv";
|
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
|
const seasonHtml = allowSeasons
|
||||||
? `<div class="req-seasons">
|
? `<div class="req-seasons">
|
||||||
<label class="req-season"><input type="checkbox" data-role="all-seasons" checked /> All seasons</label>
|
<label class="req-season"><input type="checkbox" data-role="all-seasons" checked /> All seasons</label>
|
||||||
${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 `
|
||||||
<label class="req-season">
|
<label class="req-season">
|
||||||
<input type="checkbox" class="season-box" value="${season.seasonNumber}" disabled />
|
<input type="checkbox" class="season-box" value="${escapeHtml(seasonNumber)}" disabled />
|
||||||
${escapeHtml(season.name)} <span class="req-muted">(${season.episodeCount})</span>
|
${escapeHtml(seasonName)} <span class="req-muted">(${escapeHtml(episodeCount)})</span>
|
||||||
</label>`).join("")}
|
</label>`;
|
||||||
|
}).join("")}
|
||||||
</div>`
|
</div>`
|
||||||
: detail.mediaType === "tv"
|
: mediaType === "tv"
|
||||||
? `<p class="req-muted">This request will cover all seasons.</p>`
|
? `<p class="req-muted">This request will cover all seasons.</p>`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
@@ -305,9 +344,9 @@
|
|||||||
${img ? `<img class="req-detail-poster" src="${escapeHtml(img)}" alt="" />` : "<div></div>"}
|
${img ? `<img class="req-detail-poster" src="${escapeHtml(img)}" alt="" />` : "<div></div>"}
|
||||||
<div class="req-detail-meta">
|
<div class="req-detail-meta">
|
||||||
<button type="button" class="req-btn" data-role="back-results">Back to results</button>
|
<button type="button" class="req-btn" data-role="back-results">Back to results</button>
|
||||||
<h2 class="req-detail-title">${escapeHtml(detail.title)}</h2>
|
<h2 class="req-detail-title">${escapeHtml(title)}</h2>
|
||||||
<p class="req-muted">${escapeHtml(detail.mediaType)}${detail.year ? ` · ${detail.year}` : ""}</p>
|
<p class="req-muted">${escapeHtml(mediaType)}${year ? ` · ${escapeHtml(year)}` : ""}</p>
|
||||||
<p>${escapeHtml(detail.overview || "No overview available.")}</p>
|
<p>${escapeHtml(overview)}</p>
|
||||||
${seasonHtml}
|
${seasonHtml}
|
||||||
<div class="req-detail-actions">
|
<div class="req-detail-actions">
|
||||||
<button type="button" class="req-btn primary" data-role="submit-request" ${state.status?.requestSubmissionEnabled ? "" : "disabled"}>
|
<button type="button" class="req-btn primary" data-role="submit-request" ${state.status?.requestSubmissionEnabled ? "" : "disabled"}>
|
||||||
@@ -338,15 +377,29 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function submitRequest(detail) {
|
async function submitRequest(detail) {
|
||||||
|
const mediaType = detail.mediaType || detail.MediaType || "";
|
||||||
|
const tmdbId = Number(detail.tmdbId ?? detail.TmdbId);
|
||||||
|
const title = detail.title || detail.Title || "Untitled";
|
||||||
|
|
||||||
|
if ((mediaType !== "movie" && mediaType !== "tv") || !Number.isFinite(tmdbId) || tmdbId < 1) {
|
||||||
|
showMessage("Could not read this title’s TMDB id. Go back and open it again.", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.status && !state.status.requestSubmissionEnabled) {
|
||||||
|
showMessage("Request submission is disabled. Enable it in Dashboard → Plugins → Request.", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
mediaType: detail.mediaType,
|
mediaType,
|
||||||
tmdbId: detail.tmdbId,
|
tmdbId,
|
||||||
allSeasons: true,
|
allSeasons: true,
|
||||||
seasons: null
|
seasons: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const allSeasons = els.detail.querySelector('[data-role="all-seasons"]');
|
const allSeasons = els.detail.querySelector('[data-role="all-seasons"]');
|
||||||
if (detail.mediaType === "tv" && allSeasons && !allSeasons.checked) {
|
if (mediaType === "tv" && allSeasons && !allSeasons.checked) {
|
||||||
const selected = Array.from(els.detail.querySelectorAll(".season-box:checked")).map((box) => Number(box.value));
|
const selected = Array.from(els.detail.querySelectorAll(".season-box:checked")).map((box) => Number(box.value));
|
||||||
if (!selected.length) {
|
if (!selected.length) {
|
||||||
showMessage("Select at least one season, or choose all seasons.", true);
|
showMessage("Select at least one season, or choose all seasons.", true);
|
||||||
@@ -359,7 +412,7 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await api("", { method: "POST", body: JSON.stringify(payload) });
|
await api("", { method: "POST", body: JSON.stringify(payload) });
|
||||||
showMessage(`Requested “${detail.title}”.`);
|
showMessage(`Requested “${title}”.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showMessage(error.message, true);
|
showMessage(error.message, true);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
name: "Request"
|
name: "Request"
|
||||||
guid: "11c08950-c4bb-484d-89ff-205b3724416b"
|
guid: "11c08950-c4bb-484d-89ff-205b3724416b"
|
||||||
version: "1.0.0.6"
|
version: "1.0.0.7"
|
||||||
targetAbi: "10.11.11.0"
|
targetAbi: "10.11.11.0"
|
||||||
framework: "net9.0"
|
framework: "net9.0"
|
||||||
overview: "Request movies and TV shows from a local admin review queue"
|
overview: "Request movies and TV shows from a local admin review queue"
|
||||||
|
|||||||
+5
-5
@@ -9,12 +9,12 @@
|
|||||||
"repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies",
|
"repositoryUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies",
|
||||||
"versions": [
|
"versions": [
|
||||||
{
|
{
|
||||||
"version": "1.0.0.6",
|
"version": "1.0.0.7",
|
||||||
"changelog": "Fix Request tab injection via File Transformation HTTP endpoint fallback",
|
"changelog": "Fix request submit errors with clearer validation and ApiClient base URL",
|
||||||
"targetAbi": "10.11.11.0",
|
"targetAbi": "10.11.11.0",
|
||||||
"sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.6.zip",
|
"sourceUrl": "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main/release/Jellyfin.Plugin.Request_1.0.0.7.zip",
|
||||||
"checksum": "F8F96C31230088255BA06409A5343897",
|
"checksum": "55DBF64784413920B09287802EE25732",
|
||||||
"timestamp": "2026-08-02T21:25:31.5610895Z",
|
"timestamp": "2026-08-02T21:32:22.2192886Z",
|
||||||
"dependencies": []
|
"dependencies": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
param(
|
param(
|
||||||
[string]$Version = "1.0.0.6",
|
[string]$Version = "1.0.0.7",
|
||||||
[string]$TargetAbi = "10.11.11.0",
|
[string]$TargetAbi = "10.11.11.0",
|
||||||
[string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main"
|
[string]$RepoRawBase = "https://git.masengr.com/Michael-A-Sloan/Jellyfin_Request_tvandmovies/raw/branch/main"
|
||||||
)
|
)
|
||||||
@@ -17,7 +17,7 @@ $dllPath = Join-Path $root "Jellyfin.Plugin.Request\bin\Release\net9.0\Jellyfin.
|
|||||||
$zipPath = Join-Path $releaseDir $zipFileName
|
$zipPath = Join-Path $releaseDir $zipFileName
|
||||||
$manifestPath = Join-Path $root "manifest.json"
|
$manifestPath = Join-Path $root "manifest.json"
|
||||||
$timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")
|
$timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")
|
||||||
$changelog = "Fix Request tab injection via File Transformation HTTP endpoint fallback"
|
$changelog = "Fix request submit errors with clearer validation and ApiClient base URL"
|
||||||
|
|
||||||
Write-Host "Building plugin..."
|
Write-Host "Building plugin..."
|
||||||
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release
|
dotnet build (Join-Path $root "Jellyfin.Plugin.Request.sln") -c Release
|
||||||
|
|||||||
Reference in new issue
Block a user