From 79d383f6f48df0078e6ba13239f9c4c94fbc9ea6 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Fri, 19 Jun 2026 02:21:16 +1000 Subject: v0.19a --- Server.csproj | 4 ++-- Services/MediaService.cs | 20 +++++++++++++------- Util.cs | 5 +++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Server.csproj b/Server.csproj index 9d60d7d..8de0960 100644 --- a/Server.csproj +++ b/Server.csproj @@ -6,9 +6,9 @@ enable HyperBooru HyperBooru - 0.18.0.0 + 0.19.0.0 $(AssemblyVersion) - 0.18-alpha + 0.19-alpha 2907567f-4640-4581-8f4d-0977952d26bd diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 2d1533c..a0521db 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -1,8 +1,10 @@ using HyperBooru.ApiModels; +using HyperBooru.Util; using ImageMagick; using Microsoft.EntityFrameworkCore; using MimeDetective; using MimeDetective.Definitions; +using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using System.Text.RegularExpressions; @@ -230,7 +232,10 @@ public class MediaService : IMediaService { public void Delete(Guid media) { using var db = dbFactory.CreateDbContext(); - var m = db.Media.First(m => m.Guid == media); + var m = db.Media.FirstOrDefault(m => m.Guid == media); + + if(m is null) + throw new ObjectNotFoundException([ media ]); var path = Path.Join( config.MediaBasePath, @@ -391,10 +396,11 @@ public class MediaService : IMediaService { public string GetConvertedPath(Media media, string mimeType) => GetConvertedPath(media.Guid, mimeType); - private int GetUploadedFileHash(UploadedFile uf) => ( - uf.CreateTime, - uf.LastWriteTime, - uf.Filename, - uf.Length, - uf.Checksum).GetHashCode(); + private int GetUploadedFileHash(UploadedFile uf) => + HashCode.Combine( + uf.CreateTime?.GetRoundedHashCode(), + uf.LastWriteTime?.GetRoundedHashCode(), + uf.Filename, + uf.Length, + uf.Checksum); } diff --git a/Util.cs b/Util.cs index 7de2b6e..532064e 100644 --- a/Util.cs +++ b/Util.cs @@ -35,6 +35,11 @@ public static class Extensions { return string.Format("{0:0}h{0:0}m", t.TotalHours, t.Minutes); return string.Format("{0:0.00}d", t.TotalDays); } + + public static int GetRoundedHashCode(this DateTime dt) { + var t = dt.ToUniversalTime(); + return HashCode.Combine(t.Year, t.Month, t.Date, t.Hour, t.Minute, t.Second); + } } public class LimitedConcurrencyTaskScheduler : TaskScheduler { -- cgit v1.3