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:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user