Remove snort/api
This commit is contained in:
@ -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,
|
||||
|
@ -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; }
|
||||
}
|
@ -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()}");
|
||||
|
Reference in New Issue
Block a user