From 9f4daa9def54fa8cde3ccc7edd6ab1eee8ae24c7 Mon Sep 17 00:00:00 2001 From: Kieran Date: Thu, 15 Feb 2024 18:12:12 +0000 Subject: [PATCH] Remove snort/api --- NostrStreamer/Dockerfile | 7 ++- NostrStreamer/NostrStreamer.csproj | 3 +- NostrStreamer/Program.cs | 18 ++++--- NostrStreamer/Services/PushSender.cs | 9 ++-- NostrStreamer/Services/SnortApi.cs | 50 ------------------- .../StreamManager/NostrStreamManager.cs | 7 +-- 6 files changed, 26 insertions(+), 68 deletions(-) delete mode 100644 NostrStreamer/Services/SnortApi.cs diff --git a/NostrStreamer/Dockerfile b/NostrStreamer/Dockerfile index d2a1f90..baa5534 100644 --- a/NostrStreamer/Dockerfile +++ b/NostrStreamer/Dockerfile @@ -1,9 +1,8 @@ -FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app -EXPOSE 80 -EXPOSE 443 +EXPOSE 8080 -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY ["NostrStreamer/NostrStreamer.csproj", "NostrStreamer/"] RUN dotnet restore "NostrStreamer/NostrStreamer.csproj" diff --git a/NostrStreamer/NostrStreamer.csproj b/NostrStreamer/NostrStreamer.csproj index a89d174..1f96bd4 100644 --- a/NostrStreamer/NostrStreamer.csproj +++ b/NostrStreamer/NostrStreamer.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable Linux @@ -49,6 +49,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/NostrStreamer/Program.cs b/NostrStreamer/Program.cs index 2dd5255..7d65847 100644 --- a/NostrStreamer/Program.cs +++ b/NostrStreamer/Program.cs @@ -8,6 +8,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; using Nostr.Client.Client; +using NostrServices.Client; using NostrStreamer.Database; using NostrStreamer.Services; using NostrStreamer.Services.Background; @@ -43,6 +44,11 @@ internal static class Program var services = builder.Services; var config = builder.Configuration.GetSection("Config").Get(); + if (config == default) + { + throw new Exception("Config is missing!"); + } + ConfigureDb(services, builder.Configuration); services.AddCors(); services.AddMemoryCache(); @@ -75,7 +81,7 @@ internal static class Program o.DefaultPolicy = new AuthorizationPolicy(new[] { new ClaimsAuthorizationRequirement(ClaimTypes.Name, null) - }, new[] {NostrAuth.Scheme}); + }, new[] { NostrAuth.Scheme }); }); services.AddDataProtection() @@ -119,13 +125,13 @@ internal static class Program services.AddSingleton(); services.AddHostedService(); services.AddHostedService(); - + // webhooks services.AddTransient(); - + // snort api - services.AddTransient(); - + services.AddTransient(); + var app = builder.Build(); using (var scope = app.Services.CreateScope()) @@ -166,4 +172,4 @@ internal static class Program return dummyHost; } -} +} \ No newline at end of file diff --git a/NostrStreamer/Services/PushSender.cs b/NostrStreamer/Services/PushSender.cs index 6e4ee4c..a64627d 100644 --- a/NostrStreamer/Services/PushSender.cs +++ b/NostrStreamer/Services/PushSender.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using Nostr.Client.Json; using Nostr.Client.Messages; +using NostrServices.Client; using NostrStreamer.ApiModel; using NostrStreamer.Database; using StackExchange.Redis; @@ -37,17 +38,17 @@ public class PushSenderService : BackgroundService private readonly ILogger _logger; private readonly IServiceScopeFactory _scopeFactory; private readonly IDatabase _redis; - private readonly SnortApi _snort; + private readonly NostrServicesClient _nostrApi; public PushSenderService(PushSender sender, HttpClient client, Config config, IServiceScopeFactory scopeFactory, - ILogger logger, SnortApi snort, IDatabase redis) + ILogger logger, NostrServicesClient snort, IDatabase redis) { _sender = sender; _client = client; _config = config; _scopeFactory = scopeFactory; _logger = logger; - _snort = snort; + _nostrApi = snort; _redis = redis; } @@ -121,7 +122,7 @@ public class PushSenderService : BackgroundService await _redis.StringSetAsync(key, ev.Id!, TimeSpan.FromDays(7)); var host = ev.GetHost(); - var profile = await _snort.Profile(host); + var profile = await _nostrApi.Profile(host); return new PushMessage { Type = PushMessageType.StreamStarted, diff --git a/NostrStreamer/Services/SnortApi.cs b/NostrStreamer/Services/SnortApi.cs deleted file mode 100644 index b1fc325..0000000 --- a/NostrStreamer/Services/SnortApi.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Newtonsoft.Json; - -namespace NostrStreamer.Services; - -public class SnortApi -{ - private readonly HttpClient _client; - - public SnortApi(HttpClient client, Config config) - { - _client = client; - _client.BaseAddress = config.SnortApi; - _client.Timeout = TimeSpan.FromSeconds(30); - } - - public async Task Profile(string pubkey) - { - var json = await _client.GetStringAsync($"/api/v1/raw/p/{pubkey}"); - if (!string.IsNullOrEmpty(json)) - { - return JsonConvert.DeserializeObject(json); - } - - return default; - } -} - -public class SnortProfile -{ - [JsonProperty("pubKey")] - public string PubKey { get; init; } = null!; - - [JsonProperty("name")] - public string? Name { get; init; } - - [JsonProperty("about")] - public string? About { get; init; } - - [JsonProperty("picture")] - public string? Picture { get; init; } - - [JsonProperty("nip05")] - public string? Nip05 { get; init; } - - [JsonProperty("lud16")] - public string? Lud16 { get; init; } - - [JsonProperty("banner")] - public string? Banner { get; init; } -} diff --git a/NostrStreamer/Services/StreamManager/NostrStreamManager.cs b/NostrStreamer/Services/StreamManager/NostrStreamManager.cs index 88c978e..d4e7ea3 100644 --- a/NostrStreamer/Services/StreamManager/NostrStreamManager.cs +++ b/NostrStreamer/Services/StreamManager/NostrStreamManager.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using Nostr.Client.Json; using Nostr.Client.Messages; using Nostr.Client.Utils; +using NostrServices.Client; using NostrStreamer.Database; using NostrStreamer.Services.Dvr; @@ -17,7 +18,7 @@ public class NostrStreamManager : IStreamManager private readonly IDvrStore _dvrStore; private readonly Config _config; private readonly DiscordWebhook _webhook; - private readonly SnortApi _snortApi; + private readonly NostrServicesClient _nostrApi; private readonly IDataProtectionProvider _dataProtectionProvider; public NostrStreamManager(ILogger logger, StreamManagerContext context, IServiceProvider serviceProvider) @@ -29,7 +30,7 @@ public class NostrStreamManager : IStreamManager _config = serviceProvider.GetRequiredService(); _dataProtectionProvider = serviceProvider.GetRequiredService(); _webhook = serviceProvider.GetRequiredService(); - _snortApi = serviceProvider.GetRequiredService(); + _nostrApi = serviceProvider.GetRequiredService(); } public UserStream GetStream() @@ -86,7 +87,7 @@ public class NostrStreamManager : IStreamManager { try { - var profile = await _snortApi.Profile(_context.User.PubKey); + var profile = await _nostrApi.Profile(_context.User.PubKey); var name = profile?.Name ?? NostrConverter.ToBech32(_context.User.PubKey, "npub"); var id = ev.ToIdentifier(); await _webhook.SendMessage(_config.DiscordLiveWebhook, $"{name} went live!\nhttps://zap.stream/{id.ToBech32()}");