From 02da841c350cecc985b6b161fb175e7e5882e1d5 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Tue, 5 Sep 2023 14:02:11 +1000 Subject: MediaService now records whether the checksum was verified at upload time --- Media.cs | 1 + .../20230905034704_ChecksumVerified.Designer.cs | 313 +++++++++++++++++++++ Migrations/20230905034704_ChecksumVerified.cs | 29 ++ Migrations/HBContextModelSnapshot.cs | 3 + Pages/ViewMedia.razor | 15 +- Pages/ViewMedia.razor.css | 4 + Services/MediaService.cs | 1 + Todo.md | 1 - wwwroot/styles/global.css | 1 + 9 files changed, 364 insertions(+), 4 deletions(-) create mode 100644 Migrations/20230905034704_ChecksumVerified.Designer.cs create mode 100644 Migrations/20230905034704_ChecksumVerified.cs diff --git a/Media.cs b/Media.cs index 2a4dab6..db38e9f 100644 --- a/Media.cs +++ b/Media.cs @@ -34,6 +34,7 @@ public class Media : HBObject { public class UploadedFile : HBObject { public string OriginalChecksum { get; set; } + public bool ChecksumVerified { get; set; } = false; public string? Filename { get; set; } public long Length { get; set; } public DateTime UploadTime { get; set; } = DateTime.UtcNow; diff --git a/Migrations/20230905034704_ChecksumVerified.Designer.cs b/Migrations/20230905034704_ChecksumVerified.Designer.cs new file mode 100644 index 0000000..076816f --- /dev/null +++ b/Migrations/20230905034704_ChecksumVerified.Designer.cs @@ -0,0 +1,313 @@ +// +using System; +using HyperBooru; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HyperBooru.Migrations +{ + [DbContext(typeof(HBContext))] + [Migration("20230905034704_ChecksumVerified")] + partial class ChecksumVerified + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HyperBooru.HBObject", b => + { + b.Property("ObjectId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("ObjectId")); + + b.Property("Guid") + .HasColumnType("uuid"); + + b.HasKey("ObjectId"); + + b.HasIndex("Guid"); + + b.ToTable("Objects", (string)null); + + b.UseTptMappingStrategy(); + }); + + modelBuilder.Entity("HyperBooru.OcrData", b => + { + b.Property("OcrDataId") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("OcrDataId")); + + b.Property("MediaId") + .HasColumnType("integer"); + + b.Property("SearchableText") + .IsRequired() + .HasColumnType("text"); + + b.Property("Text") + .IsRequired() + .HasColumnType("text"); + + b.Property("Timestamp") + .HasColumnType("timestamp with time zone"); + + b.HasKey("OcrDataId"); + + b.HasIndex("MediaId") + .IsUnique(); + + b.ToTable("OcrData"); + }); + + modelBuilder.Entity("TagDefinitionTagDefinition", b => + { + b.Property("ImplicitTagsObjectId") + .HasColumnType("integer"); + + b.Property("TagDefinitionObjectId") + .HasColumnType("integer"); + + b.HasKey("ImplicitTagsObjectId", "TagDefinitionObjectId"); + + b.HasIndex("TagDefinitionObjectId"); + + b.ToTable("TagDefinitionTagDefinition"); + }); + + modelBuilder.Entity("HyperBooru.Media", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("Checksum") + .IsRequired() + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("LongDescription") + .HasColumnType("text"); + + b.Property("MimeType") + .IsRequired() + .HasColumnType("text"); + + b.Property("ShortDescription") + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.ToTable("Media", (string)null); + }); + + modelBuilder.Entity("HyperBooru.Tag", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("CreateTime") + .HasColumnType("timestamp with time zone"); + + b.Property("TagDefinitionId") + .HasColumnType("integer"); + + b.Property("TargetObjectId") + .HasColumnType("integer"); + + b.HasIndex("TagDefinitionId"); + + b.HasIndex("TargetObjectId"); + + b.ToTable("Tags", (string)null); + }); + + modelBuilder.Entity("HyperBooru.TagDefinition", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("Alias") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Namespace") + .HasColumnType("text"); + + b.Property("Source") + .HasColumnType("integer"); + + b.ToTable("TagDefinitions", (string)null); + + b.HasData( + new + { + ObjectId = -1, + Guid = new Guid("ebdad4f8-455a-4351-8017-1d4854d6fa38"), + Name = "nsfw", + Source = 0 + }, + new + { + ObjectId = -2, + Guid = new Guid("ea212801-5bcc-4c0e-814f-fb9d30db58bc"), + Name = "ingest", + Source = 0 + }); + }); + + modelBuilder.Entity("HyperBooru.UploadedFile", b => + { + b.HasBaseType("HyperBooru.HBObject"); + + b.Property("ChecksumVerified") + .HasColumnType("boolean"); + + b.Property("CreateTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Filename") + .HasColumnType("text"); + + b.Property("LastAccessTime") + .HasColumnType("timestamp with time zone"); + + b.Property("LastWriteTime") + .HasColumnType("timestamp with time zone"); + + b.Property("Length") + .HasColumnType("bigint"); + + b.Property("MediaObjectId") + .HasColumnType("integer"); + + b.Property("OriginalChecksum") + .IsRequired() + .HasColumnType("text"); + + b.Property("UploadTime") + .HasColumnType("timestamp with time zone"); + + b.HasIndex("MediaObjectId"); + + b.ToTable("UploadedFiles", (string)null); + }); + + modelBuilder.Entity("HyperBooru.OcrData", b => + { + b.HasOne("HyperBooru.Media", "Media") + .WithOne("OcrData") + .HasForeignKey("HyperBooru.OcrData", "MediaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Media"); + }); + + modelBuilder.Entity("TagDefinitionTagDefinition", b => + { + b.HasOne("HyperBooru.TagDefinition", null) + .WithMany() + .HasForeignKey("ImplicitTagsObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.TagDefinition", null) + .WithMany() + .HasForeignKey("TagDefinitionObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyperBooru.Media", b => + { + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.Media", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyperBooru.Tag", b => + { + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.Tag", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.TagDefinition", "TagDefinition") + .WithMany() + .HasForeignKey("TagDefinitionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.HBObject", "Target") + .WithMany("Tags") + .HasForeignKey("TargetObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TagDefinition"); + + b.Navigation("Target"); + }); + + modelBuilder.Entity("HyperBooru.TagDefinition", b => + { + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.TagDefinition", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HyperBooru.UploadedFile", b => + { + b.HasOne("HyperBooru.Media", "Media") + .WithMany("UploadedFiles") + .HasForeignKey("MediaObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HyperBooru.HBObject", null) + .WithOne() + .HasForeignKey("HyperBooru.UploadedFile", "ObjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Media"); + }); + + modelBuilder.Entity("HyperBooru.HBObject", b => + { + b.Navigation("Tags"); + }); + + modelBuilder.Entity("HyperBooru.Media", b => + { + b.Navigation("OcrData"); + + b.Navigation("UploadedFiles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20230905034704_ChecksumVerified.cs b/Migrations/20230905034704_ChecksumVerified.cs new file mode 100644 index 0000000..8ac1f58 --- /dev/null +++ b/Migrations/20230905034704_ChecksumVerified.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace HyperBooru.Migrations +{ + /// + public partial class ChecksumVerified : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ChecksumVerified", + table: "UploadedFiles", + type: "boolean", + nullable: false, + defaultValue: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ChecksumVerified", + table: "UploadedFiles"); + } + } +} diff --git a/Migrations/HBContextModelSnapshot.cs b/Migrations/HBContextModelSnapshot.cs index 72b662f..3211e1f 100644 --- a/Migrations/HBContextModelSnapshot.cs +++ b/Migrations/HBContextModelSnapshot.cs @@ -174,6 +174,9 @@ namespace HyperBooru.Migrations { b.HasBaseType("HyperBooru.HBObject"); + b.Property("ChecksumVerified") + .HasColumnType("boolean"); + b.Property("CreateTime") .HasColumnType("timestamp with time zone"); diff --git a/Pages/ViewMedia.razor b/Pages/ViewMedia.razor index f92111b..91f33e6 100644 --- a/Pages/ViewMedia.razor +++ b/Pages/ViewMedia.razor @@ -56,12 +56,21 @@ @foreach(var file in media.UploadedFiles) { - @(file.CreateTime?.ToString("d") ?? "N/A") - @(file.LastWriteTime?.ToString("d") ?? "N/A") + + @(file.CreateTime?.ToString("d") ?? "N/A") + + + @(file.LastWriteTime?.ToString("d") ?? "N/A") + @(file.UploadTime.ToString("d")) @file.Filename @file.Length.ToBytesSI() - @file.OriginalChecksum.Substring(0, 8) + + + @file.OriginalChecksum.Substring(0, 8) + } diff --git a/Pages/ViewMedia.razor.css b/Pages/ViewMedia.razor.css index 16f86ec..53d5eca 100644 --- a/Pages/ViewMedia.razor.css +++ b/Pages/ViewMedia.razor.css @@ -103,6 +103,10 @@ table#uploaded-files td:nth-child(4) { max-width: 170px; } +table#uploaded-files td.verified { + color: var(--col-checksum-verified-pri); +} + p.heading { margin-top: 30px; } diff --git a/Services/MediaService.cs b/Services/MediaService.cs index ccc3283..015eae9 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -121,6 +121,7 @@ public class MediaService : IMediaService { Filename = fileName, Length = fileData.Length, OriginalChecksum = hash, + ChecksumVerified = checksum is not null, UploadTime = DateTime.UtcNow, LastAccessTime = lastAccessTime, LastWriteTime = lastWriteTime, diff --git a/Todo.md b/Todo.md index 4d4bb3f..a196f6d 100644 --- a/Todo.md +++ b/Todo.md @@ -26,7 +26,6 @@ - OCR status reporting on admin page - Dynamically update OCR data on ViewMedia page - Image deduplication by visual similarity - - Rating system - Audit log - Journaled operations - Confirmation dialog before enabling NSFW mode diff --git a/wwwroot/styles/global.css b/wwwroot/styles/global.css index a8c4202..6c1df53 100644 --- a/wwwroot/styles/global.css +++ b/wwwroot/styles/global.css @@ -4,6 +4,7 @@ --col-accent-pri: #0aa; --col-accent-pri-hl: #0cc; --col-error-pri: #ffaa00; + --col-checksum-verified-pri: #8dff76; --col-bg: #222; --col-dialog-bg: #333; --col-navbar-bg: var(--col-accent-pri); -- cgit v1.3