mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Using services to get updates now
This commit is contained in:
parent
ae590828da
commit
11c49c9260
@ -93,6 +93,7 @@
|
||||
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
|
||||
<Compile Include="Instrumentation\ExceptronTarget.cs" />
|
||||
<Compile Include="PathEqualityComparer.cs" />
|
||||
<Compile Include="Services.cs" />
|
||||
<Compile Include="TPL\LimitedConcurrencyLevelTaskScheduler.cs" />
|
||||
<Compile Include="Security\IgnoreCertErrorPolicy.cs" />
|
||||
<Compile Include="StringExtensions.cs" />
|
||||
|
@ -40,7 +40,6 @@ public static string ToJson(this object obj)
|
||||
return JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
|
||||
|
||||
public static void Serialize<TModel>(TModel model, TextWriter outputStream)
|
||||
{
|
||||
var jsonTextWriter = new JsonTextWriter(outputStream);
|
||||
@ -52,7 +51,5 @@ public static void Serialize<TModel>(TModel model, Stream outputStream)
|
||||
{
|
||||
Serialize(model, new StreamWriter(outputStream));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
18
NzbDrone.Common/Services.cs
Normal file
18
NzbDrone.Common/Services.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
public class Services
|
||||
{
|
||||
public static String RootUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return "http://services.nzbdrone.com";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -15,14 +15,6 @@ public class SceneMappingProxyFixture : CoreTest<SceneMappingProxy>
|
||||
{
|
||||
private const string SCENE_MAPPING_URL = "http://services.nzbdrone.com/SceneMapping/Active";
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(s => s.ServiceRootUrl)
|
||||
.Returns("http://services.nzbdrone.com");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void fetch_should_return_list_of_mappings()
|
||||
{
|
||||
|
@ -16,13 +16,7 @@ public void should_get_list_of_available_updates()
|
||||
|
||||
Mocker.GetMock<IConfigFileProvider>().SetupGet(c => c.Branch).Returns("master");
|
||||
|
||||
var updates = Subject.GetAvailablePackages().ToList();
|
||||
|
||||
updates.Should().NotBeEmpty();
|
||||
updates.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.FileName));
|
||||
updates.Should().OnlyContain(c => !string.IsNullOrWhiteSpace(c.Url));
|
||||
updates.Should().OnlyContain(c => c.Version != null);
|
||||
updates.Should().OnlyContain(c => c.Version.Major == 2);
|
||||
Subject.GetLatestUpdate().Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,11 +172,6 @@ public string BlackholeFolder
|
||||
set { SetValue("BlackholeFolder", value); }
|
||||
}
|
||||
|
||||
public string ServiceRootUrl
|
||||
{
|
||||
get { return "http://services.nzbdrone.com"; }
|
||||
}
|
||||
|
||||
public string PneumaticFolder
|
||||
{
|
||||
get { return GetValue("PneumaticFolder", String.Empty); }
|
||||
|
@ -25,7 +25,6 @@ public interface IConfigService
|
||||
int Retention { get; set; }
|
||||
DownloadClientType DownloadClient { get; set; }
|
||||
string BlackholeFolder { get; set; }
|
||||
string ServiceRootUrl { get; }
|
||||
string PneumaticFolder { get; set; }
|
||||
string RecycleBin { get; set; }
|
||||
String NzbgetUsername { get; set; }
|
||||
|
@ -17,13 +17,11 @@ public interface IDailySeriesDataProxy
|
||||
public class DailySeriesDataProxy : IDailySeriesDataProxy
|
||||
{
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, Logger logger)
|
||||
public DailySeriesDataProxy(IHttpProvider httpProvider, Logger logger)
|
||||
{
|
||||
_httpProvider = httpProvider;
|
||||
_configService = configService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -31,7 +29,7 @@ public IEnumerable<int> GetDailySeriesIds()
|
||||
{
|
||||
try
|
||||
{
|
||||
var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds");
|
||||
var dailySeriesIds = _httpProvider.DownloadString(Services.RootUrl + "/DailySeries/AllIds");
|
||||
|
||||
var seriesIds = Json.Deserialize<List<int>>(dailySeriesIds);
|
||||
|
||||
@ -49,7 +47,7 @@ public bool IsDailySeries(int tvdbid)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/Check?seriesId=" + tvdbid);
|
||||
var result = _httpProvider.DownloadString(Services.RootUrl + "/DailySeries/Check?seriesId=" + tvdbid);
|
||||
return Convert.ToBoolean(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -13,19 +13,15 @@ public interface ISceneMappingProxy
|
||||
public class SceneMappingProxy : ISceneMappingProxy
|
||||
{
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
|
||||
public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService)
|
||||
public SceneMappingProxy(IHttpProvider httpProvider)
|
||||
{
|
||||
_httpProvider = httpProvider;
|
||||
_configService = configService;
|
||||
|
||||
}
|
||||
|
||||
public List<SceneMapping> Fetch()
|
||||
{
|
||||
var mappingsJson = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/SceneMapping/Active");
|
||||
var mappingsJson = _httpProvider.DownloadString(Services.RootUrl + "/SceneMapping/Active");
|
||||
return Json.Deserialize<List<SceneMapping>>(mappingsJson);
|
||||
}
|
||||
}
|
||||
|
@ -492,6 +492,7 @@
|
||||
<Compile Include="Tv\RefreshSeriesService.cs" />
|
||||
<Compile Include="Update\Commands\ApplicationUpdateCommand.cs" />
|
||||
<Compile Include="Update\InstallUpdateService.cs" />
|
||||
<Compile Include="Update\UpdatePackageAvailable.cs" />
|
||||
<Compile Include="Update\UpdatePackageProvider.cs" />
|
||||
<Compile Include="Update\UpdatePackage.cs" />
|
||||
<Compile Include="Update\UpdateCheckService.cs" />
|
||||
|
@ -26,7 +26,7 @@ public UpdatePackage AvailableUpdate()
|
||||
{
|
||||
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
|
||||
|
||||
if (latestAvailable == null || latestAvailable.Version <= BuildInfo.Version)
|
||||
if (latestAvailable == null)
|
||||
{
|
||||
_logger.Debug("No update available.");
|
||||
return null;
|
||||
|
@ -1,11 +1,18 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NzbDrone.Core.Update
|
||||
{
|
||||
public class UpdatePackage
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public String Id { get; set; }
|
||||
|
||||
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
|
||||
public Version Version { get; set; }
|
||||
|
||||
public String Branch { get; set; }
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
public String FileName { get; set; }
|
||||
public String Url { get; set; }
|
||||
}
|
||||
}
|
||||
|
13
NzbDrone.Core/Update/UpdatePackageAvailable.cs
Normal file
13
NzbDrone.Core/Update/UpdatePackageAvailable.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Update
|
||||
{
|
||||
public class UpdatePackageAvailable
|
||||
{
|
||||
public Boolean Available { get; set; }
|
||||
public UpdatePackage UpdatePackage { get; set; }
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
@ -11,56 +12,30 @@ namespace NzbDrone.Core.Update
|
||||
{
|
||||
public interface IUpdatePackageProvider
|
||||
{
|
||||
IEnumerable<UpdatePackage> GetAvailablePackages();
|
||||
UpdatePackage GetLatestUpdate();
|
||||
}
|
||||
|
||||
public class UpdatePackageProvider : IUpdatePackageProvider
|
||||
{
|
||||
private readonly IConfigFileProvider _configService;
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IHttpProvider _httpProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>(?<=\.)\d+\.\d+\.\d+\.\d+).+?)(?:\<\/a\>)",
|
||||
RegexOptions.IgnoreCase);
|
||||
|
||||
public UpdatePackageProvider(IConfigFileProvider configService, IHttpProvider httpProvider, Logger logger)
|
||||
public UpdatePackageProvider(IConfigFileProvider configFileProvider, IHttpProvider httpProvider, Logger logger)
|
||||
{
|
||||
_configService = configService;
|
||||
_configFileProvider = configFileProvider;
|
||||
_httpProvider = httpProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IEnumerable<UpdatePackage> GetAvailablePackages()
|
||||
{
|
||||
var updateList = new List<UpdatePackage>();
|
||||
|
||||
var branch = _configService.Branch;
|
||||
var version = BuildInfo.Version;
|
||||
var updateUrl = String.Format("http://update.nzbdrone.com/v{0}/{1}/", version.Major, branch);
|
||||
|
||||
_logger.Debug("Getting a list of updates from {0}", updateUrl);
|
||||
|
||||
var rawUpdateList = _httpProvider.DownloadString(updateUrl);
|
||||
var matches = ParseRegex.Matches(rawUpdateList);
|
||||
|
||||
foreach (Match match in matches)
|
||||
{
|
||||
var updatePackage = new UpdatePackage();
|
||||
updatePackage.FileName = match.Groups["filename"].Value;
|
||||
updatePackage.Url = updateUrl + updatePackage.FileName;
|
||||
updatePackage.Version = new Version(match.Groups["version"].Value);
|
||||
updateList.Add(updatePackage);
|
||||
}
|
||||
|
||||
_logger.Debug("Found {0} update packages", updateUrl.Length);
|
||||
|
||||
return updateList;
|
||||
}
|
||||
|
||||
public UpdatePackage GetLatestUpdate()
|
||||
{
|
||||
return GetAvailablePackages().OrderByDescending(c => c.Version).FirstOrDefault();
|
||||
var url = String.Format("{0}/v1/update/{1}?{2}", Services.RootUrl, _configFileProvider.Branch, BuildInfo.Version);
|
||||
var update = JsonConvert.DeserializeObject<UpdatePackageAvailable>(_httpProvider.DownloadString(url));
|
||||
|
||||
if (!update.Available) return null;
|
||||
|
||||
return update.UpdatePackage;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user