diff --git a/Iceshrimp.Backend/Core/Services/DriveService.cs b/Iceshrimp.Backend/Core/Services/DriveService.cs index ccd095f2..37a64bf1 100644 --- a/Iceshrimp.Backend/Core/Services/DriveService.cs +++ b/Iceshrimp.Backend/Core/Services/DriveService.cs @@ -25,7 +25,7 @@ public class DriveService( { public async Task StoreFile( string? uri, User user, bool sensitive, string? description = null, string? mimeType = null, - bool logExisting = true, bool forceStore = false + bool logExisting = true, bool forceStore = false, bool skipImageProcessing = false ) { if (uri == null) return null; @@ -104,7 +104,7 @@ public class DriveService( MimeType = CleanMimeType(mimeType ?? res.Content.Headers.ContentType?.MediaType) }; - return await StoreFile(await res.Content.ReadAsStreamAsync(), user, request); + return await StoreFile(await res.Content.ReadAsStreamAsync(), user, request, skipImageProcessing); } catch (Exception e) { @@ -138,7 +138,9 @@ public class DriveService( } } - public async Task StoreFile(Stream input, User user, DriveFileCreationRequest request) + public async Task StoreFile( + Stream input, User user, DriveFileCreationRequest request, bool skipImageProcessing = false + ) { if (user.IsLocalUser && input.Length > storageConfig.Value.MaxUploadSizeBytes) throw GracefulException.UnprocessableEntity("Attachment is too large."); @@ -229,8 +231,9 @@ public class DriveService( { if (isImage && isReasonableSize) { - var genWebp = user.IsLocalUser; - var res = await imageProcessor.ProcessImage(data, request, true, genWebp); + var genThumb = !skipImageProcessing; + var genWebp = user.IsLocalUser && !skipImageProcessing; + var res = await imageProcessor.ProcessImage(data, request, genThumb, genWebp); properties = res?.Properties ?? properties; blurhash = res?.Blurhash; diff --git a/Iceshrimp.Backend/Core/Services/EmojiService.cs b/Iceshrimp.Backend/Core/Services/EmojiService.cs index 4e11241d..956747aa 100644 --- a/Iceshrimp.Backend/Core/Services/EmojiService.cs +++ b/Iceshrimp.Backend/Core/Services/EmojiService.cs @@ -13,7 +13,12 @@ using Microsoft.Extensions.Options; namespace Iceshrimp.Backend.Core.Services; -public partial class EmojiService(DatabaseContext db, DriveService driveSvc, SystemUserService sysUserSvc, IOptions config) +public partial class EmojiService( + DatabaseContext db, + DriveService driveSvc, + SystemUserService sysUserSvc, + IOptions config +) { private static readonly AsyncKeyedLocker KeyedLocker = new(o => { @@ -38,7 +43,7 @@ public partial class EmojiService(DatabaseContext db, DriveService driveSvc, Sys MimeType = mimeType, IsSensitive = false }; - var driveFile = await driveSvc.StoreFile(input, user, request); + var driveFile = await driveSvc.StoreFile(input, user, request, skipImageProcessing: true); var id = IdHelpers.GenerateSlowflakeId(); var emoji = new Emoji @@ -64,7 +69,8 @@ public partial class EmojiService(DatabaseContext db, DriveService driveSvc, Sys public async Task CloneEmoji(Emoji existing) { var user = await sysUserSvc.GetInstanceActorAsync(); - var driveFile = await driveSvc.StoreFile(existing.OriginalUrl, user, sensitive: false, forceStore: true) ?? + var driveFile = await driveSvc.StoreFile(existing.OriginalUrl, user, sensitive: false, forceStore: true, + skipImageProcessing: false) ?? throw new Exception("Error storing emoji file"); var emoji = new Emoji