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;
|
namespace Foxnouns.Backend.Extensions;
|
||||||
|
|
||||||
public static class AvatarObjectExtensions
|
public static class ImageObjectExtensions
|
||||||
{
|
{
|
||||||
private static readonly string[] ValidContentTypes = ["image/png", "image/webp", "image/jpeg"];
|
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);
|
) => await objectStorageService.RemoveObjectAsync(CreateFlagInvocable.Path(hash), ct);
|
||||||
|
|
||||||
public static async Task<(string Hash, Stream Image)> ConvertBase64UriToImage(
|
public static async Task<(string Hash, Stream Image)> ConvertBase64UriToImage(
|
||||||
this string uri,
|
string uri,
|
||||||
int size,
|
int size,
|
||||||
bool crop
|
bool crop
|
||||||
)
|
)
|
|
@ -26,7 +26,8 @@ public class CreateFlagInvocable(
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var (hash, image) = await Payload.ImageData.ConvertBase64UriToImage(
|
var (hash, image) = await ImageObjectExtensions.ConvertBase64UriToImage(
|
||||||
|
Payload.ImageData,
|
||||||
size: 256,
|
size: 256,
|
||||||
crop: false
|
crop: false
|
||||||
);
|
);
|
||||||
|
|
|
@ -39,7 +39,11 @@ public class MemberAvatarUpdateInvocable(
|
||||||
|
|
||||||
try
|
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;
|
var prevHash = member.Avatar;
|
||||||
|
|
||||||
await objectStorageService.PutObjectAsync(Path(id, hash), image, "image/webp");
|
await objectStorageService.PutObjectAsync(Path(id, hash), image, "image/webp");
|
||||||
|
|
|
@ -39,7 +39,11 @@ public class UserAvatarUpdateInvocable(
|
||||||
|
|
||||||
try
|
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);
|
image.Seek(0, SeekOrigin.Begin);
|
||||||
var prevHash = user.Avatar;
|
var prevHash = user.Avatar;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue