diff options
| -rw-r--r-- | Server.csproj | 4 | ||||
| -rw-r--r-- | Services/MediaService.cs | 20 | ||||
| -rw-r--r-- | 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 @@ <ImplicitUsings>enable</ImplicitUsings> <AssemblyName>HyperBooru</AssemblyName> <RootNamespace>HyperBooru</RootNamespace> - <AssemblyVersion>0.18.0.0</AssemblyVersion> + <AssemblyVersion>0.19.0.0</AssemblyVersion> <FileVersion>$(AssemblyVersion)</FileVersion> - <Version>0.18-alpha</Version> + <Version>0.19-alpha</Version> <UserSecretsId>2907567f-4640-4581-8f4d-0977952d26bd</UserSecretsId> </PropertyGroup> 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); } @@ -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 { |
