mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-10-08 14:05:02 -04:00
fix(controllers): prevent ObjectDisposedException by returning raw ContentResult in AppleMusicController
This commit is contained in:
1 file changed
+13
-13
@@ -1,7 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text.Json;
|
|
||||||
using allstarr.Models.Settings;
|
using allstarr.Models.Settings;
|
||||||
using allstarr.Filters;
|
using allstarr.Filters;
|
||||||
|
|
||||||
@@ -35,14 +34,13 @@ public class AppleMusicController : ControllerBase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var res = await _httpClient.GetAsync("api/health");
|
var res = await _httpClient.GetAsync("api/health");
|
||||||
|
var json = await res.Content.ReadAsStringAsync();
|
||||||
if (!res.IsSuccessStatusCode)
|
if (!res.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
return StatusCode((int)res.StatusCode, await res.Content.ReadAsStringAsync());
|
return StatusCode((int)res.StatusCode, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
var json = await res.Content.ReadAsStringAsync();
|
return Content(json, "application/json");
|
||||||
using var doc = JsonDocument.Parse(json);
|
|
||||||
return Ok(doc.RootElement);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -77,8 +75,7 @@ public class AppleMusicController : ControllerBase
|
|||||||
return StatusCode((int)res.StatusCode, json);
|
return StatusCode((int)res.StatusCode, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
using var doc = JsonDocument.Parse(json);
|
return Content(json, "application/json");
|
||||||
return Ok(doc.RootElement);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -88,7 +85,7 @@ public class AppleMusicController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("login")]
|
[HttpPost("login")]
|
||||||
public async Task<IActionResult> Login([FromBody] JsonElement credentials)
|
public async Task<IActionResult> Login([FromBody] System.Text.Json.JsonElement credentials)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -97,8 +94,12 @@ public class AppleMusicController : ControllerBase
|
|||||||
|
|
||||||
if (res.StatusCode == System.Net.HttpStatusCode.Accepted || res.StatusCode == System.Net.HttpStatusCode.OK)
|
if (res.StatusCode == System.Net.HttpStatusCode.Accepted || res.StatusCode == System.Net.HttpStatusCode.OK)
|
||||||
{
|
{
|
||||||
using var doc = JsonDocument.Parse(json);
|
return new ContentResult
|
||||||
return StatusCode((int)res.StatusCode, doc.RootElement);
|
{
|
||||||
|
Content = json,
|
||||||
|
ContentType = "application/json",
|
||||||
|
StatusCode = (int)res.StatusCode
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return StatusCode((int)res.StatusCode, json);
|
return StatusCode((int)res.StatusCode, json);
|
||||||
@@ -111,7 +112,7 @@ public class AppleMusicController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("login/2fa")]
|
[HttpPost("login/2fa")]
|
||||||
public async Task<IActionResult> Login2fa([FromBody] JsonElement code)
|
public async Task<IActionResult> Login2fa([FromBody] System.Text.Json.JsonElement code)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -120,8 +121,7 @@ public class AppleMusicController : ControllerBase
|
|||||||
|
|
||||||
if (res.IsSuccessStatusCode)
|
if (res.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
using var doc = JsonDocument.Parse(json);
|
return Content(json, "application/json");
|
||||||
return Ok(doc.RootElement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return StatusCode((int)res.StatusCode, json);
|
return StatusCode((int)res.StatusCode, json);
|
||||||
|
|||||||
Reference in new issue
Block a user