mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
feat: add form-urlencoded body parsing for Feishin compatibility
This commit is contained in:
@@ -51,8 +51,40 @@ public class SubsonicController : ControllerBase
|
|||||||
parameters[query.Key] = query.Value.ToString();
|
parameters[query.Key] = query.Value.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get body parameters (JSON)
|
// Get body parameters
|
||||||
if (Request.ContentLength > 0 && Request.ContentType?.Contains("application/json") == true)
|
if (Request.ContentLength > 0 || Request.ContentType != null)
|
||||||
|
{
|
||||||
|
// Handle application/x-www-form-urlencoded (OpenSubsonic formPost extension)
|
||||||
|
if (Request.HasFormContentType)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var form = await Request.ReadFormAsync();
|
||||||
|
foreach (var field in form)
|
||||||
|
{
|
||||||
|
parameters[field.Key] = field.Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Fall back to manual parsing if ReadFormAsync fails
|
||||||
|
Request.EnableBuffering();
|
||||||
|
using var reader = new StreamReader(Request.Body, leaveOpen: true);
|
||||||
|
var body = await reader.ReadToEndAsync();
|
||||||
|
Request.Body.Position = 0;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(body))
|
||||||
|
{
|
||||||
|
var formParams = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(body);
|
||||||
|
foreach (var param in formParams)
|
||||||
|
{
|
||||||
|
parameters[param.Key] = param.Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handle application/json
|
||||||
|
else if (Request.ContentType?.Contains("application/json") == true)
|
||||||
{
|
{
|
||||||
using var reader = new StreamReader(Request.Body);
|
using var reader = new StreamReader(Request.Body);
|
||||||
var body = await reader.ReadToEndAsync();
|
var body = await reader.ReadToEndAsync();
|
||||||
@@ -76,6 +108,7 @@ public class SubsonicController : ControllerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user