Fix DI in FileWriter.TransmitFile

pull/1010/head
Claus Vium 5 years ago
parent df92df7bd6
commit 9a4a01fb0e

@ -741,7 +741,7 @@ namespace Emby.Server.Implementations
ZipClient = new ZipClient(); ZipClient = new ZipClient();
serviceCollection.AddSingleton(ZipClient); serviceCollection.AddSingleton(ZipClient);
HttpResultFactory = new HttpResultFactory(LoggerFactory, FileSystemManager, JsonSerializer); HttpResultFactory = new HttpResultFactory(LoggerFactory, FileSystemManager, JsonSerializer, StreamHelper);
serviceCollection.AddSingleton(HttpResultFactory); serviceCollection.AddSingleton(HttpResultFactory);
serviceCollection.AddSingleton<IServerApplicationHost>(this); serviceCollection.AddSingleton<IServerApplicationHost>(this);

@ -15,6 +15,7 @@ namespace Emby.Server.Implementations.HttpServer
{ {
public class FileWriter : IHttpResult public class FileWriter : IHttpResult
{ {
private readonly IStreamHelper _streamHelper;
private ILogger Logger { get; set; } private ILogger Logger { get; set; }
public IFileSystem FileSystem { get; } public IFileSystem FileSystem { get; }
@ -45,13 +46,15 @@ namespace Emby.Server.Implementations.HttpServer
public string Path { get; set; } public string Path { get; set; }
public FileWriter(string path, string contentType, string rangeHeader, ILogger logger, IFileSystem fileSystem) public FileWriter(string path, string contentType, string rangeHeader, ILogger logger, IFileSystem fileSystem, IStreamHelper streamHelper)
{ {
if (string.IsNullOrEmpty(contentType)) if (string.IsNullOrEmpty(contentType))
{ {
throw new ArgumentNullException(nameof(contentType)); throw new ArgumentNullException(nameof(contentType));
} }
_streamHelper = streamHelper;
Path = path; Path = path;
Logger = logger; Logger = logger;
FileSystem = fileSystem; FileSystem = fileSystem;
@ -147,8 +150,7 @@ namespace Emby.Server.Implementations.HttpServer
} }
} }
private string[] SkipLogExtensions = new string[] private readonly string[] SkipLogExtensions = {
{
".js", ".js",
".html", ".html",
".css" ".css"
@ -165,8 +167,10 @@ namespace Emby.Server.Implementations.HttpServer
} }
var path = Path; var path = Path;
var offset = RangeStart;
var count = RangeLength;
if (string.IsNullOrWhiteSpace(RangeHeader) || (RangeStart <= 0 && RangeEnd >= TotalContentLength - 1)) if (string.IsNullOrWhiteSpace(RangeHeader) || RangeStart <= 0 && RangeEnd >= TotalContentLength - 1)
{ {
var extension = System.IO.Path.GetExtension(path); var extension = System.IO.Path.GetExtension(path);
@ -175,20 +179,15 @@ namespace Emby.Server.Implementations.HttpServer
Logger.LogDebug("Transmit file {0}", path); Logger.LogDebug("Transmit file {0}", path);
} }
//var count = FileShare == FileShareMode.ReadWrite ? TotalContentLength : 0; offset = 0;
// TODO not DI friendly lol count = 0;
await response.TransmitFile(path, 0, 0, FileShare, FileSystem, new StreamHelper(), cancellationToken).ConfigureAwait(false);
return;
} }
// TODO not DI friendly lol
await response.TransmitFile(path, RangeStart, RangeLength, FileShare, FileSystem, new StreamHelper(), cancellationToken).ConfigureAwait(false); await response.TransmitFile(path, offset, count, FileShare, FileSystem, _streamHelper, cancellationToken).ConfigureAwait(false);
} }
finally finally
{ {
if (OnComplete != null) OnComplete?.Invoke();
{
OnComplete();
}
} }
} }
@ -205,8 +204,5 @@ namespace Emby.Server.Implementations.HttpServer
get => (HttpStatusCode)Status; get => (HttpStatusCode)Status;
set => Status = (int)value; set => Status = (int)value;
} }
public string StatusDescription { get; set; }
} }
} }

@ -34,14 +34,16 @@ namespace Emby.Server.Implementations.HttpServer
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IJsonSerializer _jsonSerializer; private readonly IJsonSerializer _jsonSerializer;
private readonly IStreamHelper _streamHelper;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HttpResultFactory" /> class. /// Initializes a new instance of the <see cref="HttpResultFactory" /> class.
/// </summary> /// </summary>
public HttpResultFactory(ILoggerFactory loggerfactory, IFileSystem fileSystem, IJsonSerializer jsonSerializer) public HttpResultFactory(ILoggerFactory loggerfactory, IFileSystem fileSystem, IJsonSerializer jsonSerializer, IStreamHelper streamHelper)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
_streamHelper = streamHelper;
_logger = loggerfactory.CreateLogger("HttpResultFactory"); _logger = loggerfactory.CreateLogger("HttpResultFactory");
} }
@ -541,7 +543,7 @@ namespace Emby.Server.Implementations.HttpServer
if (!isHeadRequest && !string.IsNullOrEmpty(options.Path)) if (!isHeadRequest && !string.IsNullOrEmpty(options.Path))
{ {
var hasHeaders = new FileWriter(options.Path, contentType, rangeHeader, _logger, _fileSystem) var hasHeaders = new FileWriter(options.Path, contentType, rangeHeader, _logger, _fileSystem, _streamHelper)
{ {
OnComplete = options.OnComplete, OnComplete = options.OnComplete,
OnError = options.OnError, OnError = options.OnError,

@ -78,8 +78,6 @@ namespace Emby.Server.Implementations.SocketSharp
const int StreamCopyToBufferSize = 81920; const int StreamCopyToBufferSize = 81920;
public async Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, IFileSystem fileSystem, IStreamHelper streamHelper, CancellationToken cancellationToken) public async Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, IFileSystem fileSystem, IStreamHelper streamHelper, CancellationToken cancellationToken)
{ {
// TODO
// return _response.TransmitFile(path, offset, count, fileShareMode, cancellationToken);
var allowAsync = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); var allowAsync = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
//if (count <= 0) //if (count <= 0)

Loading…
Cancel
Save