mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-13 02:07:12 -07:00
Fix some Build Issues, Renaming
This commit is contained in:
parent
95051cbd63
commit
a747c5f135
191 changed files with 16 additions and 16 deletions
55
src/Lidarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs
Normal file
55
src/Lidarr.Http/Frontend/Mappers/StaticResourceMapperBase.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Nancy;
|
||||
using Nancy.Responses;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace Lidarr.Http.Frontend.Mappers
|
||||
{
|
||||
public abstract class StaticResourceMapperBase : IMapHttpRequestsToDisk
|
||||
{
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
private readonly StringComparison _caseSensitive;
|
||||
|
||||
private static readonly NotFoundResponse NotFoundResponse = new NotFoundResponse();
|
||||
|
||||
protected StaticResourceMapperBase(IDiskProvider diskProvider, Logger logger)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
|
||||
if (!RuntimeInfo.IsProduction)
|
||||
{
|
||||
_caseSensitive = StringComparison.OrdinalIgnoreCase;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract string Map(string resourceUrl);
|
||||
|
||||
public abstract bool CanHandle(string resourceUrl);
|
||||
|
||||
public virtual Response GetResponse(string resourceUrl)
|
||||
{
|
||||
var filePath = Map(resourceUrl);
|
||||
|
||||
if (_diskProvider.FileExists(filePath, _caseSensitive))
|
||||
{
|
||||
var response = new StreamResponse(() => GetContentStream(filePath), MimeTypes.GetMimeType(filePath));
|
||||
return new MaterialisingResponse(response);
|
||||
}
|
||||
|
||||
_logger.Warn("File {0} not found", filePath);
|
||||
|
||||
return NotFoundResponse;
|
||||
}
|
||||
|
||||
protected virtual Stream GetContentStream(string filePath)
|
||||
{
|
||||
return File.OpenRead(filePath);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue