|
|
@ -1,6 +1,11 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using Microsoft.AspNet.SignalR.Hosting;
|
|
|
|
|
|
|
|
using Nancy;
|
|
|
|
|
|
|
|
using Nancy.ModelBinding;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
using NzbDrone.Api.Extensions;
|
|
|
|
using NzbDrone.Api.REST;
|
|
|
|
using NzbDrone.Api.REST;
|
|
|
|
using NzbDrone.Core.Update;
|
|
|
|
using NzbDrone.Core.Update;
|
|
|
|
using NzbDrone.Api.Mapping;
|
|
|
|
using NzbDrone.Api.Mapping;
|
|
|
@ -9,33 +14,40 @@ namespace NzbDrone.Api.Update
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class UpdateModule : NzbDroneRestModule<UpdateResource>
|
|
|
|
public class UpdateModule : NzbDroneRestModule<UpdateResource>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly ICheckUpdateService _checkUpdateService;
|
|
|
|
|
|
|
|
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
|
|
|
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
|
|
|
|
|
|
|
private readonly IInstallUpdates _installUpdateService;
|
|
|
|
|
|
|
|
|
|
|
|
public UpdateModule(ICheckUpdateService checkUpdateService,
|
|
|
|
public UpdateModule(IRecentUpdateProvider recentUpdateProvider,
|
|
|
|
IRecentUpdateProvider recentUpdateProvider)
|
|
|
|
IInstallUpdates installUpdateService)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_checkUpdateService = checkUpdateService;
|
|
|
|
|
|
|
|
_recentUpdateProvider = recentUpdateProvider;
|
|
|
|
_recentUpdateProvider = recentUpdateProvider;
|
|
|
|
|
|
|
|
_installUpdateService = installUpdateService;
|
|
|
|
GetResourceAll = GetRecentUpdates;
|
|
|
|
GetResourceAll = GetRecentUpdates;
|
|
|
|
|
|
|
|
Post["/"] = x=> InstallUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private UpdateResource GetAvailableUpdate()
|
|
|
|
private List<UpdateResource> GetRecentUpdates()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var update = _checkUpdateService.AvailableUpdate();
|
|
|
|
var resources = _recentUpdateProvider.GetRecentUpdatePackages()
|
|
|
|
var response = new UpdateResource();
|
|
|
|
.OrderByDescending(u => u.Version)
|
|
|
|
|
|
|
|
.InjectTo<List<UpdateResource>>();
|
|
|
|
|
|
|
|
|
|
|
|
if (update != null)
|
|
|
|
if (resources.Any())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return update.InjectTo<UpdateResource>();
|
|
|
|
resources.First().Latest = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
return resources;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<UpdateResource> GetRecentUpdates()
|
|
|
|
private Response InstallUpdate()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ToListResource(_recentUpdateProvider.GetRecentUpdatePackages);
|
|
|
|
var updateResource = Request.Body.FromJson<UpdateResource>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var updatePackage = updateResource.InjectTo<UpdatePackage>();
|
|
|
|
|
|
|
|
_installUpdateService.InstallUpdate(updatePackage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updateResource.AsResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -48,7 +60,7 @@ namespace NzbDrone.Api.Update
|
|
|
|
public DateTime ReleaseDate { 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; }
|
|
|
|
|
|
|
|
public Boolean Latest { get; set; }
|
|
|
|
public UpdateChanges Changes { get; set; }
|
|
|
|
public UpdateChanges Changes { get; set; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|