feat(request): custom titles and remount blank request tab

Allow movie/TV requests without a TMDB match via a Custom form, and remount the embedded Request UI when the home tab opens empty.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Michael SloanandCursor committed 2026-08-02 17:46:53 -04:00
1 parent 2eed62390b
commit 7044023d98
12 files changed
+312 -33

No files matched your search

@@ -242,9 +242,62 @@ public sealed class RequestController : ControllerBase
}
var mediaType = NormalizeMediaType(body.MediaType);
if (mediaType is null || body.TmdbId <= 0)
if (mediaType is null)
{
return BadRequest(new { message = "mediaType must be movie or tv and tmdbId must be positive." });
return BadRequest(new { message = "mediaType must be movie or tv." });
}
if (body.IsCustom)
{
var customTitle = (body.Title ?? string.Empty).Trim();
if (customTitle.Length is < 1 or > 200)
{
return BadRequest(new { message = "Custom requests need a title (1–200 characters)." });
}
if (body.Year.HasValue && (body.Year.Value < 1870 || body.Year.Value > 2100))
{
return BadRequest(new { message = "Year must be between 1870 and 2100 when provided." });
}
var notes = string.IsNullOrWhiteSpace(body.Notes) ? null : body.Notes.Trim();
if (notes is { Length: > 1000 })
{
return BadRequest(new { message = "Notes must be 1000 characters or fewer." });
}
var existingCustom = await _store.GetAllAsync(cancellationToken).ConfigureAwait(false);
if (HasCustomDuplicate(existingCustom, userId, mediaType, customTitle, body.Year))
{
return Conflict(new { message = "You already have an open request for this custom title." });
}
var customUser = _userManager.GetUserById(userId);
var customRequest = new MediaRequest
{
Id = Guid.NewGuid(),
MediaType = mediaType,
TmdbId = 0,
IsCustom = true,
Title = customTitle,
Year = body.Year,
Notes = notes,
PosterPath = null,
Seasons = null,
AllSeasons = mediaType == "tv",
RequestedByUserId = userId,
RequestedByName = customUser?.Username ?? "Unknown",
CreatedAtUtc = DateTime.UtcNow,
Status = RequestStatus.Pending
};
await _store.AddAsync(customRequest, cancellationToken).ConfigureAwait(false);
return StatusCode(StatusCodes.Status201Created, customRequest);
}
if (body.TmdbId <= 0)
{
return BadRequest(new { message = "tmdbId must be positive for TMDB requests." });
}
var allSeasons = body.AllSeasons;
@@ -290,8 +343,10 @@ public sealed class RequestController : ControllerBase
Id = Guid.NewGuid(),
MediaType = mediaType,
TmdbId = detail.TmdbId,
IsCustom = false,
Title = detail.Title,
Year = detail.Year,
Notes = string.IsNullOrWhiteSpace(body.Notes) ? null : body.Notes.Trim(),
PosterPath = detail.PosterPath,
Seasons = seasons,
AllSeasons = mediaType == "tv" && allSeasons,
@@ -428,6 +483,7 @@ public sealed class RequestController : ControllerBase
foreach (var item in existing)
{
if (item.RequestedByUserId != userId
|| item.IsCustom
|| !item.MediaType.Equals(mediaType, StringComparison.OrdinalIgnoreCase)
|| item.TmdbId != tmdbId
|| item.Status is not (RequestStatus.Pending or RequestStatus.Approved))
@@ -459,6 +515,35 @@ public sealed class RequestController : ControllerBase
return false;
}
private static bool HasCustomDuplicate(
IReadOnlyList<MediaRequest> existing,
Guid userId,
string mediaType,
string title,
int? year)
{
foreach (var item in existing)
{
if (item.RequestedByUserId != userId
|| !item.IsCustom
|| !item.MediaType.Equals(mediaType, StringComparison.OrdinalIgnoreCase)
|| item.Status is not (RequestStatus.Pending or RequestStatus.Approved)
|| !item.Title.Equals(title, StringComparison.OrdinalIgnoreCase))
{
continue;
}
if (year.HasValue && item.Year.HasValue && year.Value != item.Year.Value)
{
continue;
}
return true;
}
return false;
}
private static PluginConfiguration GetConfig()
{
return Plugin.Instance?.Configuration ?? new PluginConfiguration();