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,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Jellyfin.Plugin.Request.Api;
|
||||
|
||||
@@ -11,13 +10,11 @@ public sealed class CreateRequestDto
|
||||
/// <summary>
|
||||
/// Gets or sets the media type (<c>movie</c> or <c>tv</c>).
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string MediaType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the TMDB identifier.
|
||||
/// </summary>
|
||||
[Range(1, int.MaxValue)]
|
||||
public int TmdbId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -218,19 +218,24 @@ public sealed class RequestController : ControllerBase
|
||||
/// <returns>Created request.</returns>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<MediaRequest>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user