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
|
// Ensure MediaSources is included in Fields parameter for bitrate info
|
||||||
var queryString = Request.QueryString.Value ?? "";
|
var queryString = Request.QueryString.Value ?? "";
|
||||||
if (!queryString.Contains("Fields=", StringComparison.OrdinalIgnoreCase))
|
|
||||||
|
if (!string.IsNullOrEmpty(queryString))
|
||||||
{
|
{
|
||||||
// No Fields parameter, add MediaSources
|
// Parse query string to modify Fields parameter
|
||||||
queryString = string.IsNullOrEmpty(queryString)
|
var queryParams = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(queryString);
|
||||||
? "?Fields=MediaSources"
|
|
||||||
: $"{queryString}&Fields=MediaSources";
|
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
|
||||||
|
{
|
||||||
|
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 if (!queryString.Contains("MediaSources", StringComparison.OrdinalIgnoreCase))
|
else
|
||||||
{
|
{
|
||||||
// Fields parameter exists but doesn't include MediaSources, append it
|
// No query string at all
|
||||||
queryString = $"{queryString},MediaSources";
|
queryString = "?Fields=MediaSources";
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint = $"{endpoint}{queryString}";
|
endpoint = $"{endpoint}{queryString}";
|
||||||
|
|||||||
Reference in New Issue
Block a user