feat: stream-keys

This commit is contained in:
2024-08-28 10:02:49 +01:00
parent 015b75f894
commit 97e43c8cbd
27 changed files with 1723 additions and 87 deletions

View File

@ -8,8 +8,6 @@ public class UserStreamConfiguration : IEntityTypeConfiguration<UserStream>
public void Configure(EntityTypeBuilder<UserStream> builder)
{
builder.HasKey(a => a.Id);
builder.Property(a => a.StreamId)
.IsRequired();
builder.Property(a => a.Starts)
.IsRequired();
@ -35,6 +33,13 @@ public class UserStreamConfiguration : IEntityTypeConfiguration<UserStream>
builder.Property(a => a.AdmissionCost);
builder.Property(a => a.Title);
builder.Property(a => a.Image);
builder.Property(a => a.Summary);
builder.Property(a => a.ContentWarning);
builder.Property(a => a.Tags);
builder.Property(a => a.Goal);
builder.HasOne(a => a.Endpoint)
.WithMany()
.HasForeignKey(a => a.EndpointId);

View File

@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace NostrStreamer.Database.Configuration;
public class UserStreamKeyConfiguration : IEntityTypeConfiguration<UserStreamKey>
{
public void Configure(EntityTypeBuilder<UserStreamKey> builder)
{
builder.HasKey(a => a.Id);
builder.Property(a => a.Key)
.IsRequired();
builder.Property(a => a.Created)
.IsRequired();
builder.Property(a => a.Expires)
.IsRequired(false);
builder.HasOne(a => a.UserStream)
.WithOne(a => a.StreamKey)
.HasPrincipalKey<UserStream>(a => a.Id)
.HasForeignKey<UserStreamKey>(a => a.StreamId);
builder.HasOne(a => a.User)
.WithMany(a => a.StreamKeys)
.HasForeignKey(a => a.UserPubkey)
.HasPrincipalKey(a => a.PubKey);
}
}

View File

@ -37,4 +37,6 @@ public class StreamerContext : DbContext
public DbSet<PushSubscription> PushSubscriptions => Set<PushSubscription>();
public DbSet<PushSubscriptionTarget> PushSubscriptionTargets => Set<PushSubscriptionTarget>();
public DbSet<UserStreamKey> StreamKeys => Set<UserStreamKey>();
}

View File

@ -67,4 +67,5 @@ public class User
public List<Payment> Payments { get; init; } = new();
public List<UserStream> Streams { get; init; } = new();
public List<UserStreamForwards> Forwards { get; init; } = new();
}
public List<UserStreamKey> StreamKeys { get; init; } = new();
}

View File

@ -7,14 +7,42 @@ public class UserStream
public string PubKey { get; init; } = null!;
public User User { get; init; } = null!;
public string StreamId { get; init; } = null!;
public DateTime Starts { get; init; } = DateTime.UtcNow;
public DateTime? Ends { get; set; }
public UserStreamState State { get; set; }
/// <summary>
/// Stream title
/// </summary>
public string? Title { get; set; }
/// <summary>
/// Stream summary
/// </summary>
public string? Summary { get; set; }
/// <summary>
/// Stream cover image
/// </summary>
public string? Image { get; set; }
/// <summary>
/// Comma seperated tags
/// </summary>
public string? Tags { get; set; }
/// <summary>
/// Any content warning tag (NIP-36)
/// </summary>
public string? ContentWarning { get; set; }
/// <summary>
/// Stream goal
/// </summary>
public string? Goal { get; set; }
/// <summary>
/// Nostr Event for this stream
/// </summary>
@ -25,7 +53,7 @@ public class UserStream
/// </summary>
public string? Thumbnail { get; set; }
public Guid EndpointId { get; init; }
public Guid EndpointId { get; set; }
public IngestEndpoint Endpoint { get; init; } = null!;
/// <summary>
@ -58,10 +86,15 @@ public class UserStream
public List<UserStreamGuest> Guests { get; init; } = new();
public List<UserStreamRecording> Recordings { get; init; } = new();
public UserStreamKey? StreamKey { get; init; }
public string Key => StreamKey?.Key ?? User.StreamKey;
}
public enum UserStreamState
{
Unknown = 0,
Planned = 1,
Live = 2,
Ended = 3

View File

@ -0,0 +1,25 @@
namespace NostrStreamer.Database;
/// <summary>
/// Single use stream keys
/// </summary>
public class UserStreamKey
{
public Guid Id { get; init; } = Guid.NewGuid();
public string UserPubkey { get; init; } = null!;
public User User { get; init; } = null!;
public string Key { get; init; } = null!;
public DateTime Created { get; init; } = DateTime.UtcNow;
/// <summary>
/// Expiry of the key when it can no longer be used
/// </summary>
public DateTime? Expires { get; init; }
public Guid StreamId { get; init; }
public UserStream UserStream { get; init; } = null!;
}