mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
Fix MediaSources field appending to query string
- Properly parse and modify Fields parameter instead of appending to end - Fixes 400 BadRequest errors from malformed URLs - Now correctly adds MediaSources to Fields parameter value
This commit is contained in:
@@ -126,17 +126,50 @@ public class JellyfinController : ControllerBase
|
||||
|
||||
// Ensure MediaSources is included in Fields parameter for bitrate info
|
||||
var queryString = Request.QueryString.Value ?? "";
|
||||
if (!queryString.Contains("Fields=", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
if (!string.IsNullOrEmpty(queryString))
|
||||
{
|
||||
// No Fields parameter, add MediaSources
|
||||
queryString = string.IsNullOrEmpty(queryString)
|
||||
? "?Fields=MediaSources"
|
||||
: $"{queryString}&Fields=MediaSources";
|
||||
// Parse query string to modify Fields parameter
|
||||
var queryParams = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(queryString);
|
||||
|
||||
if (queryParams.ContainsKey("Fields"))
|
||||
{
|
||||
var fieldsValue = queryParams["Fields"].ToString();
|
||||
if (!fieldsValue.Contains("MediaSources", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Append MediaSources to existing Fields
|
||||
var newFields = string.IsNullOrEmpty(fieldsValue)
|
||||
? "MediaSources"
|
||||
: $"{fieldsValue},MediaSources";
|
||||
|
||||
// Rebuild query string with updated Fields
|
||||
var newQueryParams = new Dictionary<string, string>();
|
||||
foreach (var kvp in queryParams)
|
||||
{
|
||||
if (kvp.Key == "Fields")
|
||||
{
|
||||
newQueryParams[kvp.Key] = newFields;
|
||||
}
|
||||
else if (!queryString.Contains("MediaSources", StringComparison.OrdinalIgnoreCase))
|
||||
else
|
||||
{
|
||||
// Fields parameter exists but doesn't include MediaSources, append it
|
||||
queryString = $"{queryString},MediaSources";
|
||||
newQueryParams[kvp.Key] = kvp.Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
queryString = "?" + string.Join("&", newQueryParams.Select(kvp =>
|
||||
$"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No Fields parameter, add it
|
||||
queryString = $"{queryString}&Fields=MediaSources";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No query string at all
|
||||
queryString = "?Fields=MediaSources";
|
||||
}
|
||||
|
||||
endpoint = $"{endpoint}{queryString}";
|
||||
|
||||
Reference in New Issue
Block a user