Add ability to upload entire file
This commit is contained in:
parent
f78f1e834c
commit
a6357f89ab
|
@ -1,4 +1,5 @@
|
||||||
using Jellyfin.Api.Constants;
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Api.Constants;
|
||||||
using Jellyfin.Api.Models.ClientLogDtos;
|
using Jellyfin.Api.Models.ClientLogDtos;
|
||||||
using MediaBrowser.Controller.ClientEvent;
|
using MediaBrowser.Controller.ClientEvent;
|
||||||
using MediaBrowser.Model.ClientLog;
|
using MediaBrowser.Model.ClientLog;
|
||||||
|
@ -57,6 +58,20 @@ namespace Jellyfin.Api.Controllers
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Upload a log file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="file">The file.</param>
|
||||||
|
/// <returns>Submission status.</returns>
|
||||||
|
[HttpPost("File")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
public async Task<ActionResult> LogFile(IFormFile file)
|
||||||
|
{
|
||||||
|
await _clientEventLogger.WriteFileAsync(file.FileName, file.OpenReadStream())
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
private void Log(ClientLogEventDto dto)
|
private void Log(ClientLogEventDto dto)
|
||||||
{
|
{
|
||||||
_clientEventLogger.Log(new ClientLogEvent(
|
_clientEventLogger.Log(new ClientLogEvent(
|
||||||
|
@ -69,4 +84,4 @@ namespace Jellyfin.Api.Controllers
|
||||||
dto.Message));
|
dto.Message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -607,7 +607,7 @@ namespace Jellyfin.Server
|
||||||
"ClientName",
|
"ClientName",
|
||||||
(clientName, wt)
|
(clientName, wt)
|
||||||
=> wt.File(
|
=> wt.File(
|
||||||
Path.Combine(appPaths.LogDirectoryPath, clientName + "_.log"),
|
Path.Combine(appPaths.LogDirectoryPath, "log_" + clientName + "_.log"),
|
||||||
rollingInterval: RollingInterval.Day,
|
rollingInterval: RollingInterval.Day,
|
||||||
outputTemplate: "{Message:l}{NewLine}{Exception}",
|
outputTemplate: "{Message:l}{NewLine}{Exception}",
|
||||||
encoding: Encoding.UTF8))
|
encoding: Encoding.UTF8))
|
||||||
|
@ -632,7 +632,7 @@ namespace Jellyfin.Server
|
||||||
"ClientName",
|
"ClientName",
|
||||||
(clientName, wt)
|
(clientName, wt)
|
||||||
=> wt.File(
|
=> wt.File(
|
||||||
Path.Combine(appPaths.LogDirectoryPath, clientName + "_.log"),
|
Path.Combine(appPaths.LogDirectoryPath, "log_" + clientName + "_.log"),
|
||||||
rollingInterval: RollingInterval.Day,
|
rollingInterval: RollingInterval.Day,
|
||||||
outputTemplate: "{Message:l}{NewLine}{Exception}",
|
outputTemplate: "{Message:l}{NewLine}{Exception}",
|
||||||
encoding: Encoding.UTF8))
|
encoding: Encoding.UTF8))
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Model.ClientLog;
|
using MediaBrowser.Model.ClientLog;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
@ -9,14 +11,19 @@ namespace MediaBrowser.Controller.ClientEvent
|
||||||
{
|
{
|
||||||
private const string LogString = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level}] [{ClientName}:{ClientVersion}]: UserId: {UserId} DeviceId: {DeviceId}{NewLine}{Message}";
|
private const string LogString = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level}] [{ClientName}:{ClientVersion}]: UserId: {UserId} DeviceId: {DeviceId}{NewLine}{Message}";
|
||||||
private readonly ILogger<ClientEventLogger> _logger;
|
private readonly ILogger<ClientEventLogger> _logger;
|
||||||
|
private readonly IServerApplicationPaths _applicationPaths;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
|
/// Initializes a new instance of the <see cref="ClientEventLogger"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Instance of the <see cref="ILogger{ClientEventLogger}"/> interface.</param>
|
/// <param name="logger">Instance of the <see cref="ILogger{ClientEventLogger}"/> interface.</param>
|
||||||
public ClientEventLogger(ILogger<ClientEventLogger> logger)
|
/// <param name="applicationPaths">Instance of the <see cref="IServerApplicationPaths"/> interface.</param>
|
||||||
|
public ClientEventLogger(
|
||||||
|
ILogger<ClientEventLogger> logger,
|
||||||
|
IServerApplicationPaths applicationPaths)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_applicationPaths = applicationPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -34,5 +41,16 @@ namespace MediaBrowser.Controller.ClientEvent
|
||||||
Environment.NewLine,
|
Environment.NewLine,
|
||||||
clientLogEvent.Message);
|
clientLogEvent.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public async Task WriteFileAsync(string fileName, Stream fileContents)
|
||||||
|
{
|
||||||
|
// Force naming convention: upload_YYYYMMDD_$name
|
||||||
|
fileName = $"upload_{DateTime.UtcNow:yyyyMMdd}_{fileName}";
|
||||||
|
var logFilePath = Path.Combine(_applicationPaths.LogDirectoryPath, fileName);
|
||||||
|
await using var fileStream = new FileStream(logFilePath, FileMode.CreateNew, FileAccess.Write, FileShare.None);
|
||||||
|
await fileContents.CopyToAsync(fileStream).ConfigureAwait(false);
|
||||||
|
await fileStream.FlushAsync().ConfigureAwait(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using MediaBrowser.Model.ClientLog;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MediaBrowser.Model.ClientLog;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.ClientEvent
|
namespace MediaBrowser.Controller.ClientEvent
|
||||||
{
|
{
|
||||||
|
@ -12,5 +14,13 @@ namespace MediaBrowser.Controller.ClientEvent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="clientLogEvent">The client log event.</param>
|
/// <param name="clientLogEvent">The client log event.</param>
|
||||||
void Log(ClientLogEvent clientLogEvent);
|
void Log(ClientLogEvent clientLogEvent);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a file to the log directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">The file name.</param>
|
||||||
|
/// <param name="fileContents">The file contents.</param>
|
||||||
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||||
|
Task WriteFileAsync(string fileName, Stream fileContents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user