2019-06-11 02:59:39 +00:00
|
|
|
using System.Collections.Generic;
|
2013-06-25 07:21:10 +00:00
|
|
|
using System.Linq;
|
2018-11-23 07:03:32 +00:00
|
|
|
using NzbDrone.Core.CustomFormats;
|
2019-06-14 03:54:25 +00:00
|
|
|
using NzbDrone.Core.Languages;
|
2014-06-08 08:22:55 +00:00
|
|
|
using NzbDrone.Core.Profiles;
|
|
|
|
using NzbDrone.Core.Qualities;
|
2018-11-23 07:03:32 +00:00
|
|
|
using Radarr.Http;
|
2013-06-25 07:21:10 +00:00
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
namespace NzbDrone.Api.Profiles
|
2013-06-25 07:21:10 +00:00
|
|
|
{
|
2018-11-23 07:03:32 +00:00
|
|
|
public class ProfileSchemaModule : RadarrRestModule<ProfileResource>
|
2013-06-25 07:21:10 +00:00
|
|
|
{
|
2014-01-18 11:44:36 +00:00
|
|
|
private readonly IQualityDefinitionService _qualityDefinitionService;
|
2018-08-05 14:28:05 +00:00
|
|
|
private readonly ICustomFormatService _formatService;
|
2014-01-18 11:44:36 +00:00
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
public ProfileSchemaModule(IQualityDefinitionService qualityDefinitionService, ICustomFormatService formatService)
|
2014-06-08 08:22:55 +00:00
|
|
|
: base("/profile/schema")
|
2013-06-25 07:21:10 +00:00
|
|
|
{
|
2014-01-18 11:44:36 +00:00
|
|
|
_qualityDefinitionService = qualityDefinitionService;
|
2018-08-05 14:28:05 +00:00
|
|
|
_formatService = formatService;
|
2014-01-18 11:44:36 +00:00
|
|
|
|
2013-06-25 07:21:10 +00:00
|
|
|
GetResourceAll = GetAll;
|
|
|
|
}
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
private List<ProfileResource> GetAll()
|
2013-06-25 07:21:10 +00:00
|
|
|
{
|
2014-01-29 00:53:59 +00:00
|
|
|
var items = _qualityDefinitionService.All()
|
|
|
|
.OrderBy(v => v.Weight)
|
2014-06-08 08:22:55 +00:00
|
|
|
.Select(v => new ProfileQualityItem { Quality = v.Quality, Allowed = false })
|
2014-01-29 00:53:59 +00:00
|
|
|
.ToList();
|
|
|
|
|
2018-08-05 14:28:05 +00:00
|
|
|
var formatItems = _formatService.All().Select(v => new ProfileFormatItem
|
|
|
|
{
|
2019-12-22 22:08:53 +00:00
|
|
|
Format = v,
|
|
|
|
Allowed = true
|
2018-08-05 14:28:05 +00:00
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
formatItems.Insert(0, new ProfileFormatItem
|
|
|
|
{
|
|
|
|
Format = CustomFormat.None,
|
|
|
|
Allowed = true
|
|
|
|
});
|
|
|
|
|
2014-06-08 08:22:55 +00:00
|
|
|
var profile = new Profile();
|
2019-06-11 02:59:39 +00:00
|
|
|
profile.Cutoff = Quality.Unknown.Id;
|
2014-01-29 00:53:59 +00:00
|
|
|
profile.Items = items;
|
2019-08-31 06:45:22 +00:00
|
|
|
profile.FormatCutoff = CustomFormat.None.Id;
|
2018-08-05 14:28:05 +00:00
|
|
|
profile.FormatItems = formatItems;
|
2014-06-08 08:22:55 +00:00
|
|
|
profile.Language = Language.English;
|
2014-01-18 11:44:36 +00:00
|
|
|
|
2016-03-25 00:56:29 +00:00
|
|
|
return new List<ProfileResource> { profile.ToResource() };
|
2013-06-25 07:21:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-05 14:28:05 +00:00
|
|
|
}
|