Remove snort/api

This commit is contained in:
2024-02-15 18:12:12 +00:00
parent 0cd0d5e425
commit 9f4daa9def
6 changed files with 26 additions and 68 deletions

View File

@ -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"

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
@ -49,6 +49,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nostr.Client" Version="2.0.0" />
<PackageReference Include="NostrServices.Client" Version="1.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.0.1" />
<PackageReference Include="StackExchange.Redis" Version="2.7.10" />

View File

@ -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<Config>();
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<PushSender>();
services.AddHostedService<PushSenderService>();
services.AddHostedService<EventStream>();
// webhooks
services.AddTransient<DiscordWebhook>();
// snort api
services.AddTransient<SnortApi>();
services.AddTransient<NostrServicesClient>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
@ -166,4 +172,4 @@ internal static class Program
return dummyHost;
}
}
}

View File

@ -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<PushSenderService> _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<PushSenderService> logger, SnortApi snort, IDatabase redis)
ILogger<PushSenderService> 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,

View File

@ -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<SnortProfile?> Profile(string pubkey)
{
var json = await _client.GetStringAsync($"/api/v1/raw/p/{pubkey}");
if (!string.IsNullOrEmpty(json))
{
return JsonConvert.DeserializeObject<SnortProfile>(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; }
}

View File

@ -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<NostrStreamManager> logger, StreamManagerContext context, IServiceProvider serviceProvider)
@ -29,7 +30,7 @@ public class NostrStreamManager : IStreamManager
_config = serviceProvider.GetRequiredService<Config>();
_dataProtectionProvider = serviceProvider.GetRequiredService<IDataProtectionProvider>();
_webhook = serviceProvider.GetRequiredService<DiscordWebhook>();
_snortApi = serviceProvider.GetRequiredService<SnortApi>();
_nostrApi = serviceProvider.GetRequiredService<NostrServicesClient>();
}
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()}");