aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Api
diff options
context:
space:
mode:
Diffstat (limited to 'Jellyfin.Api')
-rw-r--r--Jellyfin.Api/Controllers/ClientLogController.cs72
-rw-r--r--Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs54
2 files changed, 126 insertions, 0 deletions
diff --git a/Jellyfin.Api/Controllers/ClientLogController.cs b/Jellyfin.Api/Controllers/ClientLogController.cs
new file mode 100644
index 000000000..b894deb84
--- /dev/null
+++ b/Jellyfin.Api/Controllers/ClientLogController.cs
@@ -0,0 +1,72 @@
+using Jellyfin.Api.Constants;
+using Jellyfin.Api.Models.ClientLogDtos;
+using MediaBrowser.Controller.ClientEvent;
+using MediaBrowser.Model.ClientLog;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Jellyfin.Api.Controllers
+{
+ /// <summary>
+ /// Client log controller.
+ /// </summary>
+ [Authorize(Policy = Policies.DefaultAuthorization)]
+ public class ClientLogController : BaseJellyfinApiController
+ {
+ private readonly IClientEventLogger _clientEventLogger;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ClientLogController"/> class.
+ /// </summary>
+ /// <param name="clientEventLogger">Instance of the <see cref="IClientEventLogger"/> interface.</param>
+ public ClientLogController(IClientEventLogger clientEventLogger)
+ {
+ _clientEventLogger = clientEventLogger;
+ }
+
+ /// <summary>
+ /// Post event from client.
+ /// </summary>
+ /// <param name="clientLogEventDto">The client log dto.</param>
+ /// <response code="204">Event logged.</response>
+ /// <returns>Submission status.</returns>
+ [HttpPost]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ public ActionResult LogEvent([FromBody] ClientLogEventDto clientLogEventDto)
+ {
+ Log(clientLogEventDto);
+ return NoContent();
+ }
+
+ /// <summary>
+ /// Bulk post events from client.
+ /// </summary>
+ /// <param name="clientLogEventDtos">The list of client log dtos.</param>
+ /// <response code="204">All events logged.</response>
+ /// <returns>Submission status.</returns>
+ [HttpPost("Bulk")]
+ [ProducesResponseType(StatusCodes.Status204NoContent)]
+ public ActionResult LogEvents([FromBody] ClientLogEventDto[] clientLogEventDtos)
+ {
+ foreach (var dto in clientLogEventDtos)
+ {
+ Log(dto);
+ }
+
+ return NoContent();
+ }
+
+ private void Log(ClientLogEventDto dto)
+ {
+ _clientEventLogger.Log(new ClientLogEvent(
+ dto.Timestamp,
+ dto.Level,
+ dto.UserId,
+ dto.ClientName,
+ dto.ClientVersion,
+ dto.DeviceId,
+ dto.Message));
+ }
+ }
+} \ No newline at end of file
diff --git a/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs b/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs
new file mode 100644
index 000000000..04d97047a
--- /dev/null
+++ b/Jellyfin.Api/Models/ClientLogDtos/ClientLogEventDto.cs
@@ -0,0 +1,54 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+using Microsoft.Extensions.Logging;
+
+namespace Jellyfin.Api.Models.ClientLogDtos
+{
+ /// <summary>
+ /// The client log dto.
+ /// </summary>
+ public class ClientLogEventDto
+ {
+ /// <summary>
+ /// Gets or sets the event timestamp.
+ /// </summary>
+ [Required]
+ public DateTime Timestamp { get; set; }
+
+ /// <summary>
+ /// Gets or sets the log level.
+ /// </summary>
+ [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>
+ [Required]
+ public string Message { get; set; } = string.Empty;
+ }
+}