From 18fde9f16cce441e14465784d8b7498ee8d4832d Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 18 May 2025 13:01:38 +0800 Subject: [PATCH] :bug: Fixes on image processing --- DysonNetwork.Sphere/Storage/FileService.cs | 18 +++++++----------- .../Handlers/MessageReadReceiptFlushHandler.cs | 4 +--- DysonNetwork.sln.DotSettings.user | 1 + 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/DysonNetwork.Sphere/Storage/FileService.cs b/DysonNetwork.Sphere/Storage/FileService.cs index 295882e..f90dd19 100644 --- a/DysonNetwork.Sphere/Storage/FileService.cs +++ b/DysonNetwork.Sphere/Storage/FileService.cs @@ -31,7 +31,8 @@ public class FileService( ) { var result = new List<(string filePath, string suffix)>(); - + + var ogFilePath = Path.Join(configuration.GetValue("Tus:StorePath"), fileId); var fileSize = stream.Length; var hash = await HashFileAsync(stream, fileSize: fileSize); contentType ??= !fileName.Contains('.') ? "application/octet-stream" : MimeTypes.GetMimeType(fileName); @@ -49,9 +50,9 @@ public class FileService( switch (contentType.Split('/')[0]) { case "image": - var blurhash = BlurHashSharp.SkiaSharp.BlurHashEncoder.Encode(xComponent: 3, yComponent: 3, stream); + var blurhash = BlurHashSharp.SkiaSharp.BlurHashEncoder.Encode(xComponent: 3, yComponent: 3, filename: ogFilePath); - // Reset stream position after bitmap read + // Rewind stream stream.Position = 0; // Use NetVips for the rest @@ -62,14 +63,14 @@ public class FileService( var format = vipsImage.Get("vips-loader") ?? "unknown"; // Try to get orientation from exif data - ushort orientation = 1; + int orientation = 1; Dictionary exif = []; foreach (var field in vipsImage.GetFields()) { var value = vipsImage.Get(field); exif.Add(field, value); - if (field == "orientation") orientation = (ushort)value; + if (field == "orientation") orientation = (int)value; } if (orientation is 6 or 8) @@ -129,10 +130,7 @@ public class FileService( if (contentType.Split('/')[0] == "image") { file.MimeType = "image/webp"; - - List tasks = []; - - var ogFilePath = Path.Join(configuration.GetValue("Tus:StorePath"), file.Id); + using var vipsImage = NetVips.Image.NewFromFile(ogFilePath); var imagePath = Path.Join(Path.GetTempPath(), $"{TempFilePrefix}#{file.Id}"); vipsImage.WriteToFile(imagePath + ".webp"); @@ -151,8 +149,6 @@ public class FileService( result.Add((imageCompressedPath + ".webp", ".compressed")); file.HasCompression = true; } - - await Task.WhenAll(tasks); } else { diff --git a/DysonNetwork.Sphere/Storage/Handlers/MessageReadReceiptFlushHandler.cs b/DysonNetwork.Sphere/Storage/Handlers/MessageReadReceiptFlushHandler.cs index 7ef02b1..5231928 100644 --- a/DysonNetwork.Sphere/Storage/Handlers/MessageReadReceiptFlushHandler.cs +++ b/DysonNetwork.Sphere/Storage/Handlers/MessageReadReceiptFlushHandler.cs @@ -13,9 +13,7 @@ public class MessageReadReceiptFlushHandler(IServiceProvider serviceProvider) : var distinctItems = items.DistinctBy(x => new { x.MessageId, x.SenderId }).ToList(); using var scope = serviceProvider.CreateScope(); - var db = scope.ServiceProvider.GetRequiredService(); - - await db.BulkInsertAsync(distinctItems); + var db = scope.ServiceProvider.GetRequiredService(); await db.BulkInsertAsync(distinctItems); } } diff --git a/DysonNetwork.sln.DotSettings.user b/DysonNetwork.sln.DotSettings.user index 42826b1..2419506 100644 --- a/DysonNetwork.sln.DotSettings.user +++ b/DysonNetwork.sln.DotSettings.user @@ -3,6 +3,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded