[backend/drive] Add flag that skips image processing; skip image processing for emojis by default

This commit is contained in:
Laura Hausmann 2024-07-17 17:39:23 +02:00
parent c0835d0cc7
commit 12cbc40f99
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 17 additions and 8 deletions

View file

@ -25,7 +25,7 @@ public class DriveService(
{
public async Task<DriveFile?> 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<DriveFile> StoreFile(Stream input, User user, DriveFileCreationRequest request)
public async Task<DriveFile> 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;

View file

@ -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.InstanceSection> config)
public partial class EmojiService(
DatabaseContext db,
DriveService driveSvc,
SystemUserService sysUserSvc,
IOptions<Config.InstanceSection> config
)
{
private static readonly AsyncKeyedLocker<string> 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<Emoji> 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