1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-22 22:16:13 -04:00

Improve HTTP file mappers

This commit is contained in:
Mark McDowall
2026-02-24 20:13:55 -08:00
parent 028d2414e7
commit f30207c3d1
16 changed files with 94 additions and 33 deletions
@@ -27,14 +27,28 @@ namespace Sonarr.Http.Frontend.Mappers
_caseSensitive = RuntimeInfo.IsProduction ? DiskProviderBase.PathStringComparison : StringComparison.OrdinalIgnoreCase;
}
public abstract string Map(string resourceUrl);
protected abstract string FolderPath { get; }
protected abstract string MapPath(string resourceUrl);
public abstract bool CanHandle(string resourceUrl);
public string Map(string resourceUrl)
{
var filePath = Path.GetFullPath(MapPath(resourceUrl));
var parentPath = Path.GetFullPath(FolderPath) + Path.DirectorySeparatorChar;
return filePath.StartsWith(parentPath) ? filePath : null;
}
public Task<IActionResult> GetResponse(string resourceUrl)
{
var filePath = Map(resourceUrl);
if (filePath == null)
{
return Task.FromResult<IActionResult>(null);
}
if (_diskProvider.FileExists(filePath, _caseSensitive))
{
if (!_mimeTypeProvider.TryGetContentType(filePath, out var contentType))