feat: reporting apis; better rate limiting

refactor: change certain apis to be more REST like (e.g. DELETE /api/paste/{pasteId}/delete -> DELETE /api/paste/{pasteId}
This commit is contained in:
2026-01-10 00:06:36 -05:00
parent 864a4ee91a
commit 14bbd9c762
15 changed files with 954 additions and 48 deletions
+13 -1
View File
@@ -10,6 +10,7 @@ namespace SharpbinV3.Server.Data
public DbSet<PasteView> PasteViews => Set<PasteView>();
public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
public DbSet<UserTotp> UserTotps => Set<UserTotp>();
public DbSet<Report> Reports => Set<Report>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -38,7 +39,18 @@ namespace SharpbinV3.Server.Data
.WithOne(u => u.Totp)
.HasForeignKey<UserTotp>(t => t.UserUUID)
.OnDelete(DeleteBehavior.Cascade);
}
modelBuilder.Entity<Report>()
.HasOne(r => r.Paste)
.WithMany(p => p.Reports)
.HasForeignKey(r => r.PastePID)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Report>()
.HasOne(r => r.User)
.WithMany(u => u.Reports)
.HasForeignKey(r => r.UserUUID)
.OnDelete(DeleteBehavior.Cascade);
}
}
}
+1
View File
@@ -34,5 +34,6 @@ namespace SharpbinV3.Server.Data.Entities
public long ExpiresAt { get; set; } // timestamp of when the paste expires, or 0 for never
public List<PasteView> PasteViews { get; set; } = [];
public List<Report> Reports { get; set; } = [];
}
}
+56
View File
@@ -0,0 +1,56 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
namespace SharpbinV3.Server.Data.Entities
{
[Index(nameof(ReportID), IsUnique = true)]
[Index(nameof(ReporterUUID))]
[Index(nameof(TargetType))]
[Index(nameof(PastePID))]
[Index(nameof(UserUUID))]
public class Report
{
public int? ReportID { get; set; }
public ReportType Type { get; set; }
public ReportStatus Status { get; set; } = ReportStatus.Open;
[MaxLength(1000)]
public string? Description { get; set; }
public long CreatedAt { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
public long? UpdatedAt { get; set; }
public Guid ReporterUUID { get; set; }
public ReportTargetType TargetType { get; set; }
public int? PastePID { get; set; }
public Guid? UserUUID { get; set; }
public Paste? Paste { get; set; }
public User? User { get; set; }
}
public enum ReportStatus
{
Open,
InProgress,
Resolved,
Closed
}
public enum ReportType
{
Spam,
Abuse,
InappropriateContent,
CopyrightViolation,
Fraud,
Other
}
public enum ReportTargetType
{
Paste,
User
}
}
+1
View File
@@ -21,6 +21,7 @@ namespace SharpbinV3.Server.Data.Entities
public int Visibility { get; set; } = 0; // 0 = public, 1 = unlisted, 2 = private
public List<Paste> Pastes { get; set; } = [];
public List<RefreshToken> RefreshTokens { get; set; } = [];
public List<Report> Reports { get; set; } = [];
public UserTotp? Totp { get; set; }
}
}