refactor: change ConvertBase64UriToImage from extension method to static method

This commit is contained in:
sam 2024-11-23 20:41:41 +01:00
parent 6abf505c40
commit d87856bf2c
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
4 changed files with 14 additions and 5 deletions

View file

@ -10,7 +10,7 @@ using SixLabors.ImageSharp.Processing.Processors.Transforms;
namespace Foxnouns.Backend.Extensions;
public static class AvatarObjectExtensions
public static class ImageObjectExtensions
{
private static readonly string[] ValidContentTypes = ["image/png", "image/webp", "image/jpeg"];
@ -39,7 +39,7 @@ public static class AvatarObjectExtensions
) => await objectStorageService.RemoveObjectAsync(CreateFlagInvocable.Path(hash), ct);
public static async Task<(string Hash, Stream Image)> ConvertBase64UriToImage(
this string uri,
string uri,
int size,
bool crop
)

View file

@ -26,7 +26,8 @@ public class CreateFlagInvocable(
try
{
var (hash, image) = await Payload.ImageData.ConvertBase64UriToImage(
var (hash, image) = await ImageObjectExtensions.ConvertBase64UriToImage(
Payload.ImageData,
size: 256,
crop: false
);

View file

@ -39,7 +39,11 @@ public class MemberAvatarUpdateInvocable(
try
{
var (hash, image) = await newAvatar.ConvertBase64UriToImage(size: 512, crop: true);
var (hash, image) = await ImageObjectExtensions.ConvertBase64UriToImage(
newAvatar,
size: 512,
crop: true
);
var prevHash = member.Avatar;
await objectStorageService.PutObjectAsync(Path(id, hash), image, "image/webp");

View file

@ -39,7 +39,11 @@ public class UserAvatarUpdateInvocable(
try
{
var (hash, image) = await newAvatar.ConvertBase64UriToImage(size: 512, crop: true);
var (hash, image) = await ImageObjectExtensions.ConvertBase64UriToImage(
newAvatar,
size: 512,
crop: true
);
image.Seek(0, SeekOrigin.Begin);
var prevHash = user.Avatar;