refactor: change ConvertBase64UriToImage from extension method to static method
This commit is contained in:
parent
6abf505c40
commit
d87856bf2c
4 changed files with 14 additions and 5 deletions
|
@ -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
|
||||
)
|
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue