From 840f2ae3e60b76bd0905c75e1f847b5f44307f44 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 16 Sep 2023 15:07:39 +0300 Subject: [PATCH] Sync static resource controller with upstream (cherry picked from commit ad1f185330a30a2a9d27c9d3f18d384e66727c2a) --- .../Frontend/Mappers/IMapHttpRequestsToDisk.cs | 3 ++- .../Mappers/StaticResourceMapperBase.cs | 7 ++++--- .../Frontend/StaticResourceController.cs | 17 +++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Prowlarr.Http/Frontend/Mappers/IMapHttpRequestsToDisk.cs b/src/Prowlarr.Http/Frontend/Mappers/IMapHttpRequestsToDisk.cs index abd563606..54206b844 100644 --- a/src/Prowlarr.Http/Frontend/Mappers/IMapHttpRequestsToDisk.cs +++ b/src/Prowlarr.Http/Frontend/Mappers/IMapHttpRequestsToDisk.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; namespace Prowlarr.Http.Frontend.Mappers @@ -6,6 +7,6 @@ namespace Prowlarr.Http.Frontend.Mappers { string Map(string resourceUrl); bool CanHandle(string resourceUrl); - FileStreamResult GetResponse(string resourceUrl); + Task GetResponse(string resourceUrl); } } diff --git a/src/Prowlarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs b/src/Prowlarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs index fe47442b4..3a9b02da0 100644 --- a/src/Prowlarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs +++ b/src/Prowlarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Text; +using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Net.Http.Headers; @@ -30,7 +31,7 @@ namespace Prowlarr.Http.Frontend.Mappers public abstract bool CanHandle(string resourceUrl); - public FileStreamResult GetResponse(string resourceUrl) + public Task GetResponse(string resourceUrl) { var filePath = Map(resourceUrl); @@ -41,10 +42,10 @@ namespace Prowlarr.Http.Frontend.Mappers contentType = "application/octet-stream"; } - return new FileStreamResult(GetContentStream(filePath), new MediaTypeHeaderValue(contentType) + return Task.FromResult(new FileStreamResult(GetContentStream(filePath), new MediaTypeHeaderValue(contentType) { Encoding = contentType == "text/plain" ? Encoding.UTF8 : null - }); + })); } _logger.Warn("File {0} not found", filePath); diff --git a/src/Prowlarr.Http/Frontend/StaticResourceController.cs b/src/Prowlarr.Http/Frontend/StaticResourceController.cs index 11cfa2e02..55a472da9 100644 --- a/src/Prowlarr.Http/Frontend/StaticResourceController.cs +++ b/src/Prowlarr.Http/Frontend/StaticResourceController.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; @@ -25,27 +26,27 @@ namespace Prowlarr.Http.Frontend [AllowAnonymous] [HttpGet("login")] - public IActionResult LoginPage() + public async Task LoginPage() { - return MapResource("login"); + return await MapResource("login"); } [EnableCors("AllowGet")] [AllowAnonymous] [HttpGet("/content/{**path:regex(^(?!api/).*)}")] - public IActionResult IndexContent([FromRoute] string path) + public async Task IndexContent([FromRoute] string path) { - return MapResource("Content/" + path); + return await MapResource("Content/" + path); } [HttpGet("")] [HttpGet("/{**path:regex(^(?!api/).*)}")] - public IActionResult Index([FromRoute] string path) + public async Task Index([FromRoute] string path) { - return MapResource(path); + return await MapResource(path); } - private IActionResult MapResource(string path) + private async Task MapResource(string path) { path = "/" + (path ?? ""); @@ -53,7 +54,7 @@ namespace Prowlarr.Http.Frontend if (mapper != null) { - var result = mapper.GetResponse(path); + var result = await mapper.GetResponse(path); if (result != null) {