summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2023-09-06 02:46:10 +1000
committerJake Mannens <jake@asger.xyz>2025-08-20 00:51:51 +1000
commit6ed8b2f7a2bac84f582048181c58cc318b729322 (patch)
tree176d3342b51794d4235ae70e47f47d093db0de5e
parent0d12ecef127c2724e168c220f9d6b934090a4290 (diff)
Added pointer to current UploadedFile on Media
-rw-r--r--HBContext.cs9
-rw-r--r--Media.cs17
-rw-r--r--Services/MediaService.cs11
3 files changed, 22 insertions, 15 deletions
diff --git a/HBContext.cs b/HBContext.cs
index 15dad6d..415b745 100644
--- a/HBContext.cs
+++ b/HBContext.cs
@@ -55,10 +55,15 @@ public class HBContext : DbContext {
}
});
- // Implicit tags need some special attention to make many<->many
- // navigations work for the same object type.
+ // Some complex relationships cannot be inferred and require
+ // additional configuration, as seen below.
modelBuilder.Entity<TagDefinition>()
.HasMany(e => e.ImplicitTags)
.WithMany();
+
+ modelBuilder.Entity<Media>()
+ .HasOne(m => m.CurrentUploadedFile)
+ .WithOne()
+ .HasForeignKey<Media>("CurrentUploadedFileId");
}
} \ No newline at end of file
diff --git a/Media.cs b/Media.cs
index db38e9f..0335aa1 100644
--- a/Media.cs
+++ b/Media.cs
@@ -7,14 +7,15 @@ using System.Net.NetworkInformation;
namespace HyperBooru;
public class Media : HBObject {
- public string Checksum { get; set; }
- public string MimeType { get; set; }
- public string? ShortDescription { get; set; }
- public string? LongDescription { get; set; }
- public int Width { get; set; }
- public int Height { get; set; }
- public virtual OcrData? OcrData { get; set; }
- public virtual List<UploadedFile> UploadedFiles { get; set; } = new();
+ public string Checksum { get; set; }
+ public string MimeType { get; set; }
+ public string? ShortDescription { get; set; }
+ public string? LongDescription { get; set; }
+ public int Width { get; set; }
+ public int Height { get; set; }
+ public virtual OcrData? OcrData { get; set; }
+ public virtual UploadedFile? CurrentUploadedFile { get; set; }
+ public virtual List<UploadedFile> UploadedFiles { get; set; } = new();
public bool IsIngest => Tags
.Select(t => t.TagDefinitionId)
diff --git a/Services/MediaService.cs b/Services/MediaService.cs
index dece811..f814709 100644
--- a/Services/MediaService.cs
+++ b/Services/MediaService.cs
@@ -150,11 +150,12 @@ public class MediaService : IMediaService {
.First(td => td.Guid == HBContext.IngestTag);
media = new() {
- Checksum = hash,
- MimeType = mime,
- Width = magickImage.Width,
- Height = magickImage.Height,
- UploadedFiles = new() {
+ Checksum = hash,
+ MimeType = mime,
+ Width = magickImage.Width,
+ Height = magickImage.Height,
+ CurrentUploadedFile = fileRecord,
+ UploadedFiles = new() {
fileRecord
},
Tags = new() {