2018-02-19 07:18:14 +00:00
|
|
|
using System;
|
2018-11-23 07:03:32 +00:00
|
|
|
using System.Linq;
|
2013-10-30 23:49:53 +00:00
|
|
|
using Nancy;
|
2018-02-19 07:18:14 +00:00
|
|
|
using NzbDrone.Api.Movies;
|
2013-10-06 18:06:39 +00:00
|
|
|
using NzbDrone.Core.Datastore;
|
2019-12-22 22:08:53 +00:00
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications;
|
2013-10-30 23:49:53 +00:00
|
|
|
using NzbDrone.Core.Download;
|
2013-05-03 06:53:32 +00:00
|
|
|
using NzbDrone.Core.History;
|
2018-11-23 07:03:32 +00:00
|
|
|
using Radarr.Http;
|
2013-05-03 06:53:32 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Api.History
|
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
public class HistoryModule : RadarrRestModule<HistoryResource>
|
2013-05-03 06:53:32 +00:00
|
|
|
{
|
|
|
|
private readonly IHistoryService _historyService;
|
2019-06-19 02:50:17 +00:00
|
|
|
private readonly IUpgradableSpecification _qualityUpgradableSpecification;
|
2014-12-19 00:26:42 +00:00
|
|
|
private readonly IFailedDownloadService _failedDownloadService;
|
2013-05-03 06:53:32 +00:00
|
|
|
|
2014-08-27 00:25:35 +00:00
|
|
|
public HistoryModule(IHistoryService historyService,
|
2019-06-19 02:50:17 +00:00
|
|
|
IUpgradableSpecification qualityUpgradableSpecification,
|
2014-12-19 00:26:42 +00:00
|
|
|
IFailedDownloadService failedDownloadService)
|
2013-05-03 06:53:32 +00:00
|
|
|
{
|
|
|
|
_historyService = historyService;
|
2014-08-27 00:25:35 +00:00
|
|
|
_qualityUpgradableSpecification = qualityUpgradableSpecification;
|
2014-12-19 00:26:42 +00:00
|
|
|
_failedDownloadService = failedDownloadService;
|
2013-05-13 06:12:19 +00:00
|
|
|
GetResourcePaged = GetHistory;
|
2013-10-30 23:49:53 +00:00
|
|
|
|
2019-12-22 22:08:53 +00:00
|
|
|
Post("/failed", x => MarkAsFailed());
|
2013-05-03 06:53:32 +00:00
|
|
|
}
|
|
|
|
|
2016-03-25 00:56:29 +00:00
|
|
|
protected HistoryResource MapToResource(Core.History.History model)
|
2014-08-27 00:25:35 +00:00
|
|
|
{
|
2016-03-25 00:56:29 +00:00
|
|
|
var resource = model.ToResource();
|
2017-01-02 19:15:13 +00:00
|
|
|
resource.Movie = model.Movie.ToResource();
|
2014-08-27 00:25:35 +00:00
|
|
|
|
2017-01-02 19:15:13 +00:00
|
|
|
if (model.Movie != null)
|
|
|
|
{
|
2020-01-22 21:47:33 +00:00
|
|
|
resource.QualityCutoffNotMet = _qualityUpgradableSpecification.QualityCutoffNotMet(model.Movie.Profile, model.Quality);
|
2017-01-02 19:15:13 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 00:25:35 +00:00
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
2013-05-13 06:12:19 +00:00
|
|
|
private PagingResource<HistoryResource> GetHistory(PagingResource<HistoryResource> pagingResource)
|
2013-05-03 06:53:32 +00:00
|
|
|
{
|
2017-01-02 19:15:13 +00:00
|
|
|
var movieId = Request.Query.MovieId;
|
2016-09-10 21:05:34 +00:00
|
|
|
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, Core.History.History>("date", SortDirection.Descending);
|
2018-11-23 07:03:32 +00:00
|
|
|
var filter = pagingResource.Filters.FirstOrDefault();
|
2013-05-03 06:53:32 +00:00
|
|
|
|
2018-11-23 07:03:32 +00:00
|
|
|
if (filter != null && filter.Key == "eventType")
|
2014-02-25 02:50:09 +00:00
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
var filterValue = (HistoryEventType)Convert.ToInt32(filter.Value);
|
|
|
|
pagingSpec.FilterExpressions.Add(v => v.EventType == filterValue);
|
2014-02-25 02:50:09 +00:00
|
|
|
}
|
2013-12-27 09:47:51 +00:00
|
|
|
|
2017-01-02 19:15:13 +00:00
|
|
|
if (movieId.HasValue)
|
|
|
|
{
|
|
|
|
int i = (int)movieId;
|
2018-11-23 07:03:32 +00:00
|
|
|
pagingSpec.FilterExpressions.Add(h => h.MovieId == i);
|
2017-01-02 19:15:13 +00:00
|
|
|
}
|
|
|
|
|
2016-03-25 00:56:29 +00:00
|
|
|
return ApplyToPage(_historyService.Paged, pagingSpec, MapToResource);
|
2013-05-03 06:53:32 +00:00
|
|
|
}
|
2013-10-30 23:49:53 +00:00
|
|
|
|
2019-08-28 21:43:55 +00:00
|
|
|
private object MarkAsFailed()
|
2013-10-30 23:49:53 +00:00
|
|
|
{
|
|
|
|
var id = (int)Request.Form.Id;
|
2014-12-19 00:26:42 +00:00
|
|
|
_failedDownloadService.MarkAsFailed(id);
|
2019-08-28 21:43:55 +00:00
|
|
|
return new object();
|
2013-10-30 23:49:53 +00:00
|
|
|
}
|
2013-05-03 06:53:32 +00:00
|
|
|
}
|
2016-09-10 21:05:34 +00:00
|
|
|
}
|