diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-08-29 13:02:41 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2025-08-20 00:48:44 +1000 |
| commit | 49dc2dda8b6188de0a99ff5070d6280122143e70 (patch) | |
| tree | 2bda1f99c18e04f4019ca8fa57bcfd3c2064c100 /Services/MediaService.cs | |
| parent | 277642e460e2c1cb68952de86249f1525a9c1ab0 (diff) | |
Added width and height properties to media objects
Diffstat (limited to 'Services/MediaService.cs')
| -rw-r--r-- | Services/MediaService.cs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 460e0c7..a9bd678 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using ImageMagick; +using Microsoft.EntityFrameworkCore; using MimeDetective; using MimeDetective.Definitions; using System.Security.Cryptography; @@ -123,13 +124,17 @@ public class MediaService : IMediaService { CreateTime = createTime }; + // Determine the MIME type fileData.Seek(0, SeekOrigin.Begin); var defs = inspector.Inspect(fileData); - var mime = defs.ByMimeType().FirstOrDefault()?.MimeType; if(mime is null) throw new MediaCreateException("Unsupported file type"); + // Read the image with ImageMagick to determine the width and height + fileData.Seek(0, SeekOrigin.Begin); + using var magickImage = new MagickImage(fileData); + var media = db.Media .FirstOrDefault(m => m.Checksum == hash); @@ -138,6 +143,10 @@ public class MediaService : IMediaService { .First(td => td.Guid == HBContext.IngestTag); media = new() { + Checksum = hash, + MimeType = mime, + Width = magickImage.Width, + Height = magickImage.Height, UploadedFiles = new() { fileRecord }, |
