mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-24 22:35:49 -04:00
Regular → Executable
+79
-8
@@ -1,35 +1,64 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation.Results;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Webhook
|
||||
{
|
||||
public class Webhook : NotificationBase<WebhookSettings>
|
||||
{
|
||||
private readonly IWebhookService _service;
|
||||
private readonly IWebhookProxy _proxy;
|
||||
|
||||
public Webhook(IWebhookService service)
|
||||
public Webhook(IWebhookProxy proxy)
|
||||
{
|
||||
_service = service;
|
||||
_proxy = proxy;
|
||||
}
|
||||
|
||||
public override string Link => "https://github.com/Radarr/Radarr/wiki/Webhook";
|
||||
|
||||
public override void OnGrab(GrabMessage message)
|
||||
{
|
||||
_service.OnGrab(message.Movie, message.RemoteMovie, message.Quality, Settings);
|
||||
var remoteMovie = message.RemoteMovie;
|
||||
var quality = message.Quality;
|
||||
|
||||
var payload = new WebhookGrabPayload
|
||||
{
|
||||
EventType = "Grab",
|
||||
Movie = new WebhookMovie(message.Movie),
|
||||
RemoteMovie = new WebhookRemoteMovie(remoteMovie),
|
||||
Release = new WebhookRelease(quality, remoteMovie)
|
||||
};
|
||||
|
||||
_proxy.SendWebhook(payload, Settings);
|
||||
}
|
||||
|
||||
public override void OnDownload(DownloadMessage message)
|
||||
{
|
||||
_service.OnDownload(message.Movie, message.MovieFile, Settings);
|
||||
var movieFile = message.MovieFile;
|
||||
|
||||
var payload = new WebhookImportPayload
|
||||
{
|
||||
EventType = "Download",
|
||||
Movie = new WebhookMovie(message.Movie),
|
||||
RemoteMovie = new WebhookRemoteMovie(message.Movie),
|
||||
MovieFile = new WebhookMovieFile(movieFile),
|
||||
IsUpgrade = message.OldMovieFiles.Any()
|
||||
};
|
||||
|
||||
_proxy.SendWebhook(payload, Settings);
|
||||
}
|
||||
|
||||
public override void OnMovieRename(Movie movie)
|
||||
{
|
||||
_service.OnRename(movie, Settings);
|
||||
var payload = new WebhookPayload
|
||||
{
|
||||
EventType = "Rename",
|
||||
Movie = new WebhookMovie(movie)
|
||||
};
|
||||
|
||||
_proxy.SendWebhook(payload, Settings);
|
||||
}
|
||||
|
||||
public override void OnRename(Series series)
|
||||
@@ -42,9 +71,51 @@ namespace NzbDrone.Core.Notifications.Webhook
|
||||
{
|
||||
var failures = new List<ValidationFailure>();
|
||||
|
||||
failures.AddIfNotNull(_service.Test(Settings));
|
||||
failures.AddIfNotNull(SendWebhookTest());
|
||||
|
||||
return new ValidationResult(failures);
|
||||
}
|
||||
|
||||
private ValidationFailure SendWebhookTest()
|
||||
{
|
||||
try
|
||||
{
|
||||
var payload = new WebhookGrabPayload
|
||||
{
|
||||
EventType = "Test",
|
||||
Movie = new WebhookMovie
|
||||
{
|
||||
Id = 1,
|
||||
Title = "Test Title",
|
||||
FilePath = "C:\\testpath",
|
||||
ReleaseDate = "1970-01-01"
|
||||
},
|
||||
RemoteMovie = new WebhookRemoteMovie
|
||||
{
|
||||
TmdbId = 1234,
|
||||
ImdbId = "5678",
|
||||
Title = "Test title",
|
||||
Year = 1970
|
||||
},
|
||||
Release = new WebhookRelease
|
||||
{
|
||||
Indexer = "Test Indexer",
|
||||
Quality = "Test Quality",
|
||||
QualityVersion = 1,
|
||||
ReleaseGroup = "Test Group",
|
||||
ReleaseTitle = "Test Title",
|
||||
Size = 9999999
|
||||
}
|
||||
};
|
||||
|
||||
_proxy.SendWebhook(payload, Settings);
|
||||
}
|
||||
catch (WebhookException ex)
|
||||
{
|
||||
return new NzbDroneValidationFailure("Url", ex.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user