mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 02:18:54 -07:00
65cd3ed597
This makes resolving dependencies from the container much easier as you cannot resolve with primitives parameters in a way that is any more readable. The aim of this commit is to change as little as possible with the end result, loggers that were newed up for the parent object were given the same name. Objects that used the base or app loggers, were given a new logger with an appropriate name. Also removed some unused dependencies.
66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using MediaBrowser.Controller;
|
|
using MediaBrowser.Controller.Net;
|
|
using MediaBrowser.Model.IO;
|
|
using MediaBrowser.Model.Services;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Emby.Server.Implementations
|
|
{
|
|
public class ResourceFileManager : IResourceFileManager
|
|
{
|
|
private readonly IFileSystem _fileSystem;
|
|
private readonly ILogger _logger;
|
|
private readonly IHttpResultFactory _resultFactory;
|
|
|
|
public ResourceFileManager(
|
|
IHttpResultFactory resultFactory,
|
|
ILoggerFactory loggerFactory,
|
|
IFileSystem fileSystem)
|
|
{
|
|
_resultFactory = resultFactory;
|
|
_logger = loggerFactory.CreateLogger("ResourceManager");
|
|
_fileSystem = fileSystem;
|
|
}
|
|
|
|
public Stream GetResourceFileStream(string basePath, string virtualPath)
|
|
{
|
|
return _fileSystem.GetFileStream(GetResourcePath(basePath, virtualPath), FileOpenMode.Open, FileAccessMode.Read, FileShareMode.ReadWrite, true);
|
|
}
|
|
|
|
public Task<object> GetStaticFileResult(IRequest request, string basePath, string virtualPath, string contentType, TimeSpan? cacheDuration)
|
|
{
|
|
return _resultFactory.GetStaticFileResult(request, GetResourcePath(basePath, virtualPath));
|
|
}
|
|
|
|
public string ReadAllText(string basePath, string virtualPath)
|
|
{
|
|
return _fileSystem.ReadAllText(GetResourcePath(basePath, virtualPath));
|
|
}
|
|
|
|
private string GetResourcePath(string basePath, string virtualPath)
|
|
{
|
|
var fullPath = Path.Combine(basePath, virtualPath.Replace('/', _fileSystem.DirectorySeparatorChar));
|
|
|
|
try
|
|
{
|
|
fullPath = _fileSystem.GetFullPath(fullPath);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error in Path.GetFullPath");
|
|
}
|
|
|
|
// Don't allow file system access outside of the source folder
|
|
if (!_fileSystem.ContainsSubPath(basePath, fullPath))
|
|
{
|
|
throw new SecurityException("Access denied");
|
|
}
|
|
|
|
return fullPath;
|
|
}
|
|
}
|
|
}
|