You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.9 KiB
81 lines
2.9 KiB
using System;
|
|
using Nancy;
|
|
using NzbDrone.Api.Episodes;
|
|
using NzbDrone.Api.Albums;
|
|
using Lidarr.Http.Extensions;
|
|
using NzbDrone.Api.Series;
|
|
using NzbDrone.Api.Music;
|
|
using NzbDrone.Core.Datastore;
|
|
using NzbDrone.Core.DecisionEngine;
|
|
using NzbDrone.Core.Download;
|
|
using NzbDrone.Core.History;
|
|
using Lidarr.Http;
|
|
|
|
namespace NzbDrone.Api.History
|
|
{
|
|
public class HistoryModule : LidarrRestModule<HistoryResource>
|
|
{
|
|
private readonly IHistoryService _historyService;
|
|
private readonly IUpgradableSpecification _upgradableSpecification;
|
|
private readonly IFailedDownloadService _failedDownloadService;
|
|
|
|
public HistoryModule(IHistoryService historyService,
|
|
IUpgradableSpecification qualityUpgradableSpecification,
|
|
IFailedDownloadService failedDownloadService)
|
|
{
|
|
_historyService = historyService;
|
|
_upgradableSpecification = qualityUpgradableSpecification;
|
|
_failedDownloadService = failedDownloadService;
|
|
GetResourcePaged = GetHistory;
|
|
|
|
Post["/failed"] = x => MarkAsFailed();
|
|
}
|
|
|
|
protected HistoryResource MapToResource(Core.History.History model)
|
|
{
|
|
var resource = model.ToResource();
|
|
|
|
resource.Artist = model.Artist.ToResource();
|
|
resource.Album = model.Album.ToResource();
|
|
|
|
if (model.Artist != null)
|
|
{
|
|
resource.QualityCutoffNotMet = _upgradableSpecification.CutoffNotMet(model.Artist.Profile.Value,
|
|
model.Artist.LanguageProfile,
|
|
model.Quality,
|
|
model.Language);
|
|
}
|
|
|
|
return resource;
|
|
}
|
|
|
|
private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
|
|
{
|
|
var albumId = Request.Query.AlbumId;
|
|
|
|
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, Core.History.History>("date", SortDirection.Descending);
|
|
|
|
if (pagingResource.FilterKey == "eventType")
|
|
{
|
|
var filterValue = (HistoryEventType)Convert.ToInt32(pagingResource.FilterValue);
|
|
pagingSpec.FilterExpression = v => v.EventType == filterValue;
|
|
}
|
|
|
|
if (albumId.HasValue)
|
|
{
|
|
int i = (int)albumId;
|
|
pagingSpec.FilterExpression = h => h.AlbumId == i;
|
|
}
|
|
|
|
return ApplyToPage(_historyService.Paged, pagingSpec, MapToResource);
|
|
}
|
|
|
|
private Response MarkAsFailed()
|
|
{
|
|
var id = (int)Request.Form.Id;
|
|
_failedDownloadService.MarkAsFailed(id);
|
|
return new object().AsResponse();
|
|
}
|
|
}
|
|
}
|