Move ActivityLogService to Jellyfin.Api
This commit is contained in:
parent
b3f8928fbb
commit
dc190e5683
54
Jellyfin.Api/Controllers/System/ActivityLogController.cs
Normal file
54
Jellyfin.Api/Controllers/System/ActivityLogController.cs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Jellyfin.Api.Constants;
|
||||||
|
using MediaBrowser.Model.Activity;
|
||||||
|
using MediaBrowser.Model.Querying;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Controllers.System
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Activity log controller.
|
||||||
|
/// </summary>
|
||||||
|
[Route("/System/ActivityLog/Entries")]
|
||||||
|
[Authorize(Policy = Policies.RequiresElevation)]
|
||||||
|
public class ActivityLogController : BaseJellyfinApiController
|
||||||
|
{
|
||||||
|
private readonly IActivityManager _activityManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ActivityLogController"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="activityManager">Instance of <see cref="IActivityManager"/> interface.</param>
|
||||||
|
public ActivityLogController(IActivityManager activityManager)
|
||||||
|
{
|
||||||
|
_activityManager = activityManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets activity log entries.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startIndex">Optional. The record index to start at. All items with a lower index will be dropped from the results.</param>
|
||||||
|
/// <param name="limit">Optional. The maximum number of records to return.</param>
|
||||||
|
/// <param name="minDate">Optional. The minimum date. Format = ISO.</param>
|
||||||
|
/// <param name="hasUserId">Optional. Only returns activities that have a user associated.</param>
|
||||||
|
/// <response code="200">Activity log returned.</response>
|
||||||
|
/// <returns>A <see cref="QueryResult{ActivityLogEntry}"/> containing the log entries.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public ActionResult<QueryResult<ActivityLogEntry>> GetLogEntries(
|
||||||
|
[FromQuery] int? startIndex,
|
||||||
|
[FromQuery] int? limit,
|
||||||
|
[FromQuery] string minDate,
|
||||||
|
bool? hasUserId)
|
||||||
|
{
|
||||||
|
DateTime? startDate = string.IsNullOrWhiteSpace(minDate) ?
|
||||||
|
(DateTime?)null :
|
||||||
|
DateTime.Parse(minDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
||||||
|
|
||||||
|
return _activityManager.GetActivityLogEntries(startDate, hasUserId, startIndex, limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,61 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
using MediaBrowser.Controller.Configuration;
|
|
||||||
using MediaBrowser.Controller.Net;
|
|
||||||
using MediaBrowser.Model.Activity;
|
|
||||||
using MediaBrowser.Model.Querying;
|
|
||||||
using MediaBrowser.Model.Services;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Api.System
|
|
||||||
{
|
|
||||||
[Route("/System/ActivityLog/Entries", "GET", Summary = "Gets activity log entries")]
|
|
||||||
public class GetActivityLogs : IReturn<QueryResult<ActivityLogEntry>>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Skips over a given number of items within the results. Use for paging.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The start index.</value>
|
|
||||||
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
|
||||||
public int? StartIndex { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The maximum number of items to return
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The limit.</value>
|
|
||||||
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
|
|
||||||
public int? Limit { get; set; }
|
|
||||||
|
|
||||||
[ApiMember(Name = "MinDate", Description = "Optional. The minimum date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
|
||||||
public string MinDate { get; set; }
|
|
||||||
|
|
||||||
public bool? HasUserId { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Authenticated(Roles = "Admin")]
|
|
||||||
public class ActivityLogService : BaseApiService
|
|
||||||
{
|
|
||||||
private readonly IActivityManager _activityManager;
|
|
||||||
|
|
||||||
public ActivityLogService(
|
|
||||||
ILogger<ActivityLogService> logger,
|
|
||||||
IServerConfigurationManager serverConfigurationManager,
|
|
||||||
IHttpResultFactory httpResultFactory,
|
|
||||||
IActivityManager activityManager)
|
|
||||||
: base(logger, serverConfigurationManager, httpResultFactory)
|
|
||||||
{
|
|
||||||
_activityManager = activityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Get(GetActivityLogs request)
|
|
||||||
{
|
|
||||||
DateTime? minDate = string.IsNullOrWhiteSpace(request.MinDate) ?
|
|
||||||
(DateTime?)null :
|
|
||||||
DateTime.Parse(request.MinDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
||||||
|
|
||||||
var result = _activityManager.GetActivityLogEntries(minDate, request.HasUserId, request.StartIndex, request.Limit);
|
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user