From e4966edbb5c8f880f4bdb1c388b1039efb52305a Mon Sep 17 00:00:00 2001 From: whoswhip Date: Tue, 30 Dec 2025 17:48:28 -0500 Subject: [PATCH] i think this fixes it --- .gitignore | 3 +- SharpbinV3.Server/Data/AppDbContext.cs | 12 ++++++ SharpbinV3.Server/Data/Entities/Paste.cs | 37 +++++++++++++++++++ .../Data/Entities/RefreshToken.cs | 16 ++++++++ SharpbinV3.Server/Data/Entities/User.cs | 21 +++++++++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 SharpbinV3.Server/Data/AppDbContext.cs create mode 100644 SharpbinV3.Server/Data/Entities/Paste.cs create mode 100644 SharpbinV3.Server/Data/Entities/RefreshToken.cs create mode 100644 SharpbinV3.Server/Data/Entities/User.cs diff --git a/.gitignore b/.gitignore index 3fd9d56..4a06601 100644 --- a/.gitignore +++ b/.gitignore @@ -325,4 +325,5 @@ FodyWeavers.xsd **/*.db-shm **/*.sqlite -Data \ No newline at end of file +Data +!SharpbinV3.Server/Data \ No newline at end of file diff --git a/SharpbinV3.Server/Data/AppDbContext.cs b/SharpbinV3.Server/Data/AppDbContext.cs new file mode 100644 index 0000000..cb8e807 --- /dev/null +++ b/SharpbinV3.Server/Data/AppDbContext.cs @@ -0,0 +1,12 @@ +using Microsoft.EntityFrameworkCore; +using SharpbinV3.Server.Data.Entities; + +namespace SharpbinV3.Server.Data +{ + public sealed class AppDbContext(DbContextOptions options) : DbContext(options) + { + public DbSet Users => Set(); + public DbSet Pastes => Set(); + public DbSet RefreshTokens => Set(); + } +} diff --git a/SharpbinV3.Server/Data/Entities/Paste.cs b/SharpbinV3.Server/Data/Entities/Paste.cs new file mode 100644 index 0000000..d2fec33 --- /dev/null +++ b/SharpbinV3.Server/Data/Entities/Paste.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; + +namespace SharpbinV3.Server.Data.Entities +{ + [Index(nameof(PID), IsUnique = true)] + [Index(nameof(UUID), IsUnique = true)] + [Index(nameof(ID), IsUnique = true)] + [Index(nameof(AuthorUUID))] + [Index(nameof(ExpiresAt))] + [Index(nameof(Views))] + [Index(nameof(Visibility))] + public sealed class Paste + { + [Key] + public int PID { get; set; } + public required Guid UUID { get; set; } // uuid v7 includes timestamp, this counts as created at + public required string ID { get; set; } + public string? Title { get; set; } + + public required Guid AuthorUUID { get; set; } = Guid.Empty; // uuid of the user who created the paste, or Guid.Empty for anonymous pastes + public User? User { get; set; } + + public long? EditedAt { get; set; } + + public required byte[] Content { get; set; } + public long Size { get; set; } // stored size (may be compressed) + public long TrueSize { get; set; } // uncompressed size + public bool IsCompressed { get; set; } = false; + + public int Views { get; set; } + public string? Syntax { get; set; } + public int Visibility { get; set; } = 0; // 0 = public, 1 = unlisted, 2 = private (encrypted pastes handled on frontend) + + public long ExpiresAt { get; set; } // timestamp of when the paste expires, or 0 for never + } +} diff --git a/SharpbinV3.Server/Data/Entities/RefreshToken.cs b/SharpbinV3.Server/Data/Entities/RefreshToken.cs new file mode 100644 index 0000000..3190226 --- /dev/null +++ b/SharpbinV3.Server/Data/Entities/RefreshToken.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; + +namespace SharpbinV3.Server.Data.Entities +{ + public sealed class RefreshToken + { + [Key] + public Guid UserUUID { get; set; } + public required string Token { get; set; } + public required string JwtId { get; set; } + public required long CreatedAt { get; set; } + public required long ExpiresAt { get; set; } + public bool Used { get; set; } = false; + public User? User { get; set; } + } +} diff --git a/SharpbinV3.Server/Data/Entities/User.cs b/SharpbinV3.Server/Data/Entities/User.cs new file mode 100644 index 0000000..2c59d48 --- /dev/null +++ b/SharpbinV3.Server/Data/Entities/User.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; + +namespace SharpbinV3.Server.Data.Entities +{ + [Index(nameof(UUID), IsUnique = true)] + public sealed class User + { + [Key] + public int UID { get; set; } + public required Guid UUID { get; set; } = Guid.CreateVersion7(); // uuid v7 includes timestamp + public required string Username { get; set; } + public required string PasswordHash { get; set; } + public string? Email { get; set; } + public string? DisplayName { get; set; } + public long? LastLogin { get; set; } + public int[] Roles { get; set; } = [0]; // 0 = regular user, 1 = moderator, 255 = admin + public int Visibility { get; set; } = 0; // 0 = public, 1 = unlisted, 2 = private + public List Pastes { get; set; } = []; + } +}