From 4a50fa24169909f44776b470947a4d58b9e7e5cc Mon Sep 17 00:00:00 2001 From: chiragkrishna Date: Mon, 9 Sep 2024 19:26:01 +0530 Subject: [PATCH] Add Enable/Disable options for webhooks (#283) --- Jellyfin.Plugin.Webhook/Configuration/Web/config.html | 7 +++++++ Jellyfin.Plugin.Webhook/Configuration/Web/config.js | 2 ++ Jellyfin.Plugin.Webhook/Destinations/BaseOption.cs | 5 +++++ Jellyfin.Plugin.Webhook/WebhookSender.cs | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Jellyfin.Plugin.Webhook/Configuration/Web/config.html b/Jellyfin.Plugin.Webhook/Configuration/Web/config.html index 2b318c1..d099740 100644 --- a/Jellyfin.Plugin.Webhook/Configuration/Web/config.html +++ b/Jellyfin.Plugin.Webhook/Configuration/Web/config.html @@ -76,6 +76,13 @@

Webhook

The webhook destination url +
+ + +
diff --git a/Jellyfin.Plugin.Webhook/Configuration/Web/config.js b/Jellyfin.Plugin.Webhook/Configuration/Web/config.js index b50b6ee..f42bd07 100644 --- a/Jellyfin.Plugin.Webhook/Configuration/Web/config.js +++ b/Jellyfin.Plugin.Webhook/Configuration/Web/config.js @@ -164,6 +164,7 @@ export default function (view) { element.querySelector("[data-name=chkSendAllProperties]").checked = config.SendAllProperties || false; element.querySelector("[data-name=chkTrimWhitespace]").checked = config.TrimWhitespace || false; element.querySelector("[data-name=chkSkipEmptyMessageBody]").checked = config.SkipEmptyMessageBody || false; + element.querySelector("[data-name=chkEnableWebhook]").checked = config.EnableWebhook !== undefined ? config.EnableWebhook : true; element.querySelector("[data-name=txtTemplate]").value = Webhook.atou(config.Template || ""); const notificationTypeContainer = element.querySelector("[data-name=notificationTypeContainer]"); @@ -187,6 +188,7 @@ export default function (view) { config.SendAllProperties = element.querySelector("[data-name=chkSendAllProperties]").checked || false; config.TrimWhitespace = element.querySelector("[data-name=chkTrimWhitespace]").checked || false; config.SkipEmptyMessageBody = element.querySelector("[data-name=chkSkipEmptyMessageBody]").checked || false; + config.EnableWebhook = element.querySelector("[data-name=chkEnableWebhook]").checked; config.Template = Webhook.utoa(element.querySelector("[data-name=txtTemplate]").value || ""); config.NotificationTypes = []; diff --git a/Jellyfin.Plugin.Webhook/Destinations/BaseOption.cs b/Jellyfin.Plugin.Webhook/Destinations/BaseOption.cs index 34bb5b6..9e6510d 100644 --- a/Jellyfin.Plugin.Webhook/Destinations/BaseOption.cs +++ b/Jellyfin.Plugin.Webhook/Destinations/BaseOption.cs @@ -82,6 +82,11 @@ public abstract class BaseOption /// public bool SkipEmptyMessageBody { get; set; } + /// + /// Gets or sets a value indicating whether to Enable or Disable Webhook. + /// + public bool EnableWebhook { get; set; } = true; + /// /// Gets or sets the handlebars template. /// diff --git a/Jellyfin.Plugin.Webhook/WebhookSender.cs b/Jellyfin.Plugin.Webhook/WebhookSender.cs index 2e989b8..13dd1cc 100644 --- a/Jellyfin.Plugin.Webhook/WebhookSender.cs +++ b/Jellyfin.Plugin.Webhook/WebhookSender.cs @@ -182,7 +182,7 @@ private static bool NotifyOnItem(T baseOptions, Type? itemType) private async Task SendNotification(IWebhookClient webhookClient, T option, Dictionary itemData, Type? itemType) where T : BaseOption { - if (NotifyOnItem(option, itemType)) + if (option.EnableWebhook && NotifyOnItem(option, itemType)) { try {