From 72dcf5cbe030b762ee0d5ca452f5e7344a3d4db9 Mon Sep 17 00:00:00 2001 From: Marcos Cordeiro Date: Mon, 26 Jun 2023 00:02:29 -0300 Subject: [PATCH] Adds notification support for wasari daemon --- Wasari.Daemon/Handlers/DownloadRequestHandler.cs | 11 +++++++++-- Wasari.Daemon/Options/NotificationOptions.cs | 6 ++++++ Wasari.Daemon/Program.cs | 13 ++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 Wasari.Daemon/Options/NotificationOptions.cs diff --git a/Wasari.Daemon/Handlers/DownloadRequestHandler.cs b/Wasari.Daemon/Handlers/DownloadRequestHandler.cs index 4134800..463699b 100644 --- a/Wasari.Daemon/Handlers/DownloadRequestHandler.cs +++ b/Wasari.Daemon/Handlers/DownloadRequestHandler.cs @@ -1,12 +1,14 @@ -using Wasari.App; +using Microsoft.Extensions.Options; +using Wasari.App; using Wasari.App.Abstractions; using Wasari.Daemon.Models; +using Wasari.Daemon.Options; namespace Wasari.Daemon.Handlers; public class DownloadRequestHandler { - public async ValueTask Handle(DownloadRequest request, ILogger logger, DownloadServiceSolver downloadServiceSolver) + public async ValueTask Handle(DownloadRequest request, ILogger logger, DownloadServiceSolver downloadServiceSolver, IServiceProvider serviceProvider, IOptions notificationOptions) { logger.LogInformation("Starting download of {Url}", request.Url); @@ -24,5 +26,10 @@ public async ValueTask Handle(DownloadRequest request, ILogger() is {} notificationService) + { + await notificationService.SendNotifcationForDownloadedEpisodeAsync(episodes); + } } } \ No newline at end of file diff --git a/Wasari.Daemon/Options/NotificationOptions.cs b/Wasari.Daemon/Options/NotificationOptions.cs new file mode 100644 index 0000000..532773d --- /dev/null +++ b/Wasari.Daemon/Options/NotificationOptions.cs @@ -0,0 +1,6 @@ +namespace Wasari.Daemon.Options; + +public record NotificationOptions +{ + public bool Enabled { get; set; } +} \ No newline at end of file diff --git a/Wasari.Daemon/Program.cs b/Wasari.Daemon/Program.cs index 28cb766..782c8d9 100644 --- a/Wasari.Daemon/Program.cs +++ b/Wasari.Daemon/Program.cs @@ -8,6 +8,7 @@ using Wasari.Daemon.Handlers; using Wasari.Daemon.HostedServices; using Wasari.Daemon.Models; +using Wasari.Daemon.Options; using Wasari.FFmpeg; using Wasari.YoutubeDlp; using WasariEnvironment; @@ -20,6 +21,7 @@ var username = Environment.GetEnvironmentVariable("USERNAME") ?? throw new InvalidOperationException("USERNAME environment variable is not set"); var password = Environment.GetEnvironmentVariable("PASSWORD") ?? throw new InvalidOperationException("PASSWORD environment variable is not set"); var postgresCs = Environment.GetEnvironmentVariable("POSTGRESQL_CONNECTION_STRING") ?? throw new InvalidOperationException("POSTGRESQL_CONNECTION_STRING environment variable is not set"); +var webhookUrl = Environment.GetEnvironmentVariable("WEBHOOK_URL"); var builder = WebApplication.CreateBuilder(args); @@ -74,7 +76,7 @@ opts.Discovery.DisableConventionalDiscovery(); opts.Discovery.IncludeType(); - + opts.PersistMessagesWithPostgresql(postgresCs); opts.UseEntityFrameworkCoreTransactions(); opts.Policies.AutoApplyTransactions(); @@ -84,6 +86,15 @@ opts.UseFluentValidation(); }); +if (webhookUrl != null) +{ + builder.Services.AddHttpClient(c => { c.BaseAddress = new Uri(webhookUrl); }); + builder.Services.Configure(o => + { + o.Enabled = true; + }); +} + builder.Host.UseResourceSetupOnStartup(); var app = builder.Build();