Merge branch 'services-update' into develop
This commit is contained in:
commit
429460dd5e
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NzbDrone.Api.REST;
|
using NzbDrone.Api.REST;
|
||||||
using NzbDrone.Core.Update;
|
using NzbDrone.Core.Update;
|
||||||
using NzbDrone.Api.Mapping;
|
using NzbDrone.Api.Mapping;
|
||||||
|
@ -32,7 +33,13 @@ namespace NzbDrone.Api.Update
|
||||||
|
|
||||||
public class UpdateResource : RestResource
|
public class UpdateResource : RestResource
|
||||||
{
|
{
|
||||||
|
public String Id { get; set; }
|
||||||
|
|
||||||
|
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
|
||||||
public Version Version { get; set; }
|
public Version Version { get; set; }
|
||||||
|
|
||||||
|
public String Branch { get; set; }
|
||||||
|
public DateTime ReleaseDate { get; set; }
|
||||||
public String FileName { get; set; }
|
public String FileName { get; set; }
|
||||||
public String Url { get; set; }
|
public String Url { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@
|
||||||
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
|
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
|
||||||
<Compile Include="Instrumentation\ExceptronTarget.cs" />
|
<Compile Include="Instrumentation\ExceptronTarget.cs" />
|
||||||
<Compile Include="PathEqualityComparer.cs" />
|
<Compile Include="PathEqualityComparer.cs" />
|
||||||
|
<Compile Include="Services.cs" />
|
||||||
<Compile Include="TPL\LimitedConcurrencyLevelTaskScheduler.cs" />
|
<Compile Include="TPL\LimitedConcurrencyLevelTaskScheduler.cs" />
|
||||||
<Compile Include="Security\IgnoreCertErrorPolicy.cs" />
|
<Compile Include="Security\IgnoreCertErrorPolicy.cs" />
|
||||||
<Compile Include="StringExtensions.cs" />
|
<Compile Include="StringExtensions.cs" />
|
||||||
|
|
|
@ -40,7 +40,6 @@ namespace NzbDrone.Common.Serializer
|
||||||
return JsonConvert.SerializeObject(obj);
|
return JsonConvert.SerializeObject(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void Serialize<TModel>(TModel model, TextWriter outputStream)
|
public static void Serialize<TModel>(TModel model, TextWriter outputStream)
|
||||||
{
|
{
|
||||||
var jsonTextWriter = new JsonTextWriter(outputStream);
|
var jsonTextWriter = new JsonTextWriter(outputStream);
|
||||||
|
@ -52,7 +51,5 @@ namespace NzbDrone.Common.Serializer
|
||||||
{
|
{
|
||||||
Serialize(model, new StreamWriter(outputStream));
|
Serialize(model, new StreamWriter(outputStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 @@ namespace NzbDrone.Core.Test.DataAugmentationFixture.Scene
|
||||||
{
|
{
|
||||||
private const string SCENE_MAPPING_URL = "http://services.nzbdrone.com/SceneMapping/Active";
|
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]
|
[Test]
|
||||||
public void fetch_should_return_list_of_mappings()
|
public void fetch_should_return_list_of_mappings()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,13 +16,7 @@ namespace NzbDrone.Core.Test.UpdateTests
|
||||||
|
|
||||||
Mocker.GetMock<IConfigFileProvider>().SetupGet(c => c.Branch).Returns("master");
|
Mocker.GetMock<IConfigFileProvider>().SetupGet(c => c.Branch).Returns("master");
|
||||||
|
|
||||||
var updates = Subject.GetAvailablePackages().ToList();
|
Subject.GetLatestUpdate().Should().BeNull();
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,11 +172,6 @@ namespace NzbDrone.Core.Configuration
|
||||||
set { SetValue("BlackholeFolder", value); }
|
set { SetValue("BlackholeFolder", value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ServiceRootUrl
|
|
||||||
{
|
|
||||||
get { return "http://services.nzbdrone.com"; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string PneumaticFolder
|
public string PneumaticFolder
|
||||||
{
|
{
|
||||||
get { return GetValue("PneumaticFolder", String.Empty); }
|
get { return GetValue("PneumaticFolder", String.Empty); }
|
||||||
|
|
|
@ -25,7 +25,6 @@ namespace NzbDrone.Core.Configuration
|
||||||
int Retention { get; set; }
|
int Retention { get; set; }
|
||||||
DownloadClientType DownloadClient { get; set; }
|
DownloadClientType DownloadClient { get; set; }
|
||||||
string BlackholeFolder { get; set; }
|
string BlackholeFolder { get; set; }
|
||||||
string ServiceRootUrl { get; }
|
|
||||||
string PneumaticFolder { get; set; }
|
string PneumaticFolder { get; set; }
|
||||||
string RecycleBin { get; set; }
|
string RecycleBin { get; set; }
|
||||||
String NzbgetUsername { get; set; }
|
String NzbgetUsername { get; set; }
|
||||||
|
|
|
@ -17,13 +17,11 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries
|
||||||
public class DailySeriesDataProxy : IDailySeriesDataProxy
|
public class DailySeriesDataProxy : IDailySeriesDataProxy
|
||||||
{
|
{
|
||||||
private readonly IHttpProvider _httpProvider;
|
private readonly IHttpProvider _httpProvider;
|
||||||
private readonly IConfigService _configService;
|
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, Logger logger)
|
public DailySeriesDataProxy(IHttpProvider httpProvider, Logger logger)
|
||||||
{
|
{
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_configService = configService;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +29,7 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds");
|
var dailySeriesIds = _httpProvider.DownloadString(Services.RootUrl + "/DailySeries/AllIds");
|
||||||
|
|
||||||
var seriesIds = Json.Deserialize<List<int>>(dailySeriesIds);
|
var seriesIds = Json.Deserialize<List<int>>(dailySeriesIds);
|
||||||
|
|
||||||
|
@ -49,7 +47,7 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries
|
||||||
{
|
{
|
||||||
try
|
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);
|
return Convert.ToBoolean(result);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -13,19 +13,15 @@ namespace NzbDrone.Core.DataAugmentation.Scene
|
||||||
public class SceneMappingProxy : ISceneMappingProxy
|
public class SceneMappingProxy : ISceneMappingProxy
|
||||||
{
|
{
|
||||||
private readonly IHttpProvider _httpProvider;
|
private readonly IHttpProvider _httpProvider;
|
||||||
private readonly IConfigService _configService;
|
|
||||||
|
|
||||||
|
public SceneMappingProxy(IHttpProvider httpProvider)
|
||||||
public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService)
|
|
||||||
{
|
{
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_configService = configService;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SceneMapping> Fetch()
|
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);
|
return Json.Deserialize<List<SceneMapping>>(mappingsJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -493,6 +493,7 @@
|
||||||
<Compile Include="Tv\RefreshSeriesService.cs" />
|
<Compile Include="Tv\RefreshSeriesService.cs" />
|
||||||
<Compile Include="Update\Commands\ApplicationUpdateCommand.cs" />
|
<Compile Include="Update\Commands\ApplicationUpdateCommand.cs" />
|
||||||
<Compile Include="Update\InstallUpdateService.cs" />
|
<Compile Include="Update\InstallUpdateService.cs" />
|
||||||
|
<Compile Include="Update\UpdatePackageAvailable.cs" />
|
||||||
<Compile Include="Update\UpdatePackageProvider.cs" />
|
<Compile Include="Update\UpdatePackageProvider.cs" />
|
||||||
<Compile Include="Update\UpdatePackage.cs" />
|
<Compile Include="Update\UpdatePackage.cs" />
|
||||||
<Compile Include="Update\UpdateCheckService.cs" />
|
<Compile Include="Update\UpdateCheckService.cs" />
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace NzbDrone.Core.Update
|
||||||
{
|
{
|
||||||
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
|
var latestAvailable = _updatePackageProvider.GetLatestUpdate();
|
||||||
|
|
||||||
if (latestAvailable == null || latestAvailable.Version <= BuildInfo.Version)
|
if (latestAvailable == null)
|
||||||
{
|
{
|
||||||
_logger.Debug("No update available.");
|
_logger.Debug("No update available.");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
using System;
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Update
|
namespace NzbDrone.Core.Update
|
||||||
{
|
{
|
||||||
public class UpdatePackage
|
public class UpdatePackage
|
||||||
{
|
{
|
||||||
public string Url { get; set; }
|
public String Id { get; set; }
|
||||||
public string FileName { get; set; }
|
|
||||||
|
[JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))]
|
||||||
public Version Version { get; set; }
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
@ -11,56 +12,30 @@ namespace NzbDrone.Core.Update
|
||||||
{
|
{
|
||||||
public interface IUpdatePackageProvider
|
public interface IUpdatePackageProvider
|
||||||
{
|
{
|
||||||
IEnumerable<UpdatePackage> GetAvailablePackages();
|
|
||||||
UpdatePackage GetLatestUpdate();
|
UpdatePackage GetLatestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UpdatePackageProvider : IUpdatePackageProvider
|
public class UpdatePackageProvider : IUpdatePackageProvider
|
||||||
{
|
{
|
||||||
private readonly IConfigFileProvider _configService;
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
private readonly IHttpProvider _httpProvider;
|
private readonly IHttpProvider _httpProvider;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
private static readonly Regex ParseRegex = new Regex(@"(?:\>)(?<filename>NzbDrone.+?(?<version>(?<=\.)\d+\.\d+\.\d+\.\d+).+?)(?:\<\/a\>)",
|
public UpdatePackageProvider(IConfigFileProvider configFileProvider, IHttpProvider httpProvider, Logger logger)
|
||||||
RegexOptions.IgnoreCase);
|
|
||||||
|
|
||||||
public UpdatePackageProvider(IConfigFileProvider configService, IHttpProvider httpProvider, Logger logger)
|
|
||||||
{
|
{
|
||||||
_configService = configService;
|
_configFileProvider = configFileProvider;
|
||||||
_httpProvider = httpProvider;
|
_httpProvider = httpProvider;
|
||||||
_logger = logger;
|
_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()
|
public UpdatePackage GetLatestUpdate()
|
||||||
{
|
{
|
||||||
return GetAvailablePackages().OrderByDescending(c => c.Version).FirstOrDefault();
|
var url = String.Format("{0}/v1/update/{1}?version={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