The Free Software Media System - Server Backend & API
Update documentation; use information from authorization; return generated filename
Cody Robibero0e584f68409e
diff --git a/Jellyfin.Api/Controllers/ClientLogController.cs b/Jellyfin.Api/Controllers/ClientLogController.csindex aac3f6a735..f50d560979 100644--- a/Jellyfin.Api/Controllers/ClientLogController.cs+++ b/Jellyfin.Api/Controllers/ClientLogController.cs@@ -45,17 +45,22 @@ namespace Jellyfin.Api.Controllers/// </summary>/// <param name="clientLogEventDto">The client log dto.</param>/// <response code="204">Event logged.</response>+ /// <response code="403">Event logging disabled.</response>/// <returns>Submission status.</returns>[HttpPost][ProducesResponseType(StatusCodes.Status204NoContent)]- public ActionResult LogEvent([FromBody] ClientLogEventDto clientLogEventDto)+ [ProducesResponseType(StatusCodes.Status403Forbidden)]+ public async Task<ActionResult> LogEvent([FromBody] ClientLogEventDto clientLogEventDto){if (!_serverConfigurationManager.Configuration.AllowClientLogUpload){return Forbid();}- Log(clientLogEventDto);+ var authorizationInfo = await _authorizationContext.GetAuthorizationInfo(Request)+ .ConfigureAwait(false);++ Log(clientLogEventDto, authorizationInfo);return NoContent();}@@ -64,19 +69,24 @@ namespace Jellyfin.Api.Controllers/// </summary>/// <param name="clientLogEventDtos">The list of client log dtos.</param>/// <response code="204">All events logged.</response>+ /// <response code="403">Event logging disabled.</response>/// <returns>Submission status.</returns>[HttpPost("Bulk")][ProducesResponseType(StatusCodes.Status204NoContent)]- public ActionResult LogEvents([FromBody] ClientLogEventDto[] clientLogEventDtos)+ [ProducesResponseType(StatusCodes.Status403Forbidden)]+ public async Task<ActionResult> LogEvents([FromBody] ClientLogEventDto[] clientLogEventDtos){if (!_serverConfigurationManager.Configuration.AllowClientLogUpload){return Forbid();}+ var authorizationInfo = await _authorizationContext.GetAuthorizationInfo(Request)+ .ConfigureAwait(false);+foreach (var dto in clientLogEventDtos){- Log(dto);+ Log(dto, authorizationInfo);}return NoContent();@@ -85,12 +95,17 @@ namespace Jellyfin.Api.Controllers/// <summary>/// Upload a document./// </summary>- /// <returns>Submission status.</returns>+ /// <response code="200">Document saved.</response>+ /// <response code="403">Event logging disabled.</response>+ /// <response code="413">Upload size too large.</response>+ /// <returns>Created file name.</returns>[HttpPost("Document")]- [ProducesResponseType(StatusCodes.Status204NoContent)]+ [ProducesResponseType(typeof(string), StatusCodes.Status200OK)]+ [ProducesResponseType(StatusCodes.Status403Forbidden)]+ [ProducesResponseType(StatusCodes.Status413PayloadTooLarge)][AcceptsFile(MediaTypeNames.Text.Plain)][RequestSizeLimit(MaxDocumentSize)]- public async Task<ActionResult> LogFile()+ public async Task<ActionResult<string>> LogFile(){if (!_serverConfigurationManager.Configuration.AllowClientLogUpload){@@ -106,20 +121,20 @@ namespace Jellyfin.Api.Controllersvar authorizationInfo = await _authorizationContext.GetAuthorizationInfo(Request).ConfigureAwait(false);- await _clientEventLogger.WriteDocumentAsync(authorizationInfo, Request.Body)+ var fileName = await _clientEventLogger.WriteDocumentAsync(authorizationInfo, Request.Body).ConfigureAwait(false);- return NoContent();+ return Ok(fileName);}- private void Log(ClientLogEventDto dto)+ private void Log(ClientLogEventDto dto, AuthorizationInfo authorizationInfo){_clientEventLogger.Log(new ClientLogEvent(dto.Timestamp,dto.Level,- dto.UserId,- dto.ClientName,- dto.ClientVersion,- dto.DeviceId,+ authorizationInfo.UserId,+ authorizationInfo.Client,+ authorizationInfo.Version,+ authorizationInfo.DeviceId,dto.Message));}}diff --git a/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs b/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.csindex 04d97047a1..9bf9be0a46 100644--- a/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs+++ b/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs@@ -21,30 +21,6 @@ namespace Jellyfin.Api.Models.ClientLogDtos[Required]public LogLevel Level { get; set; }- /// <summary>- /// Gets or sets the user id.- /// </summary>- public Guid? UserId { get; set; }-- /// <summary>- /// Gets or sets the client name.- /// </summary>- [Required]- public string ClientName { get; set; } = string.Empty;-- /// <summary>- /// Gets or sets the client version.- /// </summary>- [Required]- public string ClientVersion { get; set; } = string.Empty;-- ///- /// <summary>- /// Gets or sets the device id.- /// </summary>- [Required]- public string DeviceId { get; set; } = string.Empty;-/// <summary>/// Gets or sets the log message./// </summary>diff --git a/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs b/MediaBrowser.Controller/ClientEvent/ClientEventLogger.csindex 04d0a3c434..870070d354 100644--- a/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs+++ b/MediaBrowser.Controller/ClientEvent/ClientEventLogger.cs@@ -44,13 +44,14 @@ namespace MediaBrowser.Controller.ClientEvent}/// <inheritdoc />- public async Task WriteDocumentAsync(AuthorizationInfo authorizationInfo, Stream fileContents)+ public async Task<string> WriteDocumentAsync(AuthorizationInfo authorizationInfo, Stream fileContents){var fileName = $"upload_{authorizationInfo.Client}_{(authorizationInfo.IsApiKey ? "apikey" : authorizationInfo.Version)}_{DateTime.UtcNow:yyyyMMddHHmmss}.log";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);+ return fileName;}}}diff --git a/MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs b/MediaBrowser.Controller/ClientEvent/IClientEventLogger.csindex ee8e5806b7..6fc54faf2f 100644--- a/MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs+++ b/MediaBrowser.Controller/ClientEvent/IClientEventLogger.cs@@ -21,7 +21,7 @@ namespace MediaBrowser.Controller.ClientEvent/// </summary>/// <param name="authorizationInfo">The current authorization info.</param>/// <param name="fileContents">The file contents to write.</param>- /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>- Task WriteDocumentAsync(AuthorizationInfo authorizationInfo, Stream fileContents);+ /// <returns>The created file name.</returns>+ Task<string> WriteDocumentAsync(AuthorizationInfo authorizationInfo, Stream fileContents);}}