Skip to content

Commit

Permalink
feat: activity nft image resize
Browse files Browse the repository at this point in the history
  • Loading branch information
mixhsnhd committed Dec 17, 2024
1 parent d246f78 commit 83833fc
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

namespace EoaServer.UserAssets.Provider;

public interface IImageProcessProvider
{
Task<string> GetResizeImageAsync(string imageUrl, int width, int height, ImageResizeType type);
}

public class ImageProcessProvider : IImageProcessProvider, ISingletonDependency
{
private readonly ILogger<ImageProcessProvider> _logger;
Expand Down
19 changes: 13 additions & 6 deletions src/EoaServer.Application/UserActivity/UserActivityAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using EoaServer.UserActivity.Dtos;
using EoaServer.UserAssets;
using EoaServer.UserAssets.Dtos;
using EoaServer.UserAssets.Provider;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MongoDB.Bson;
Expand All @@ -33,12 +34,14 @@ public class UserActivityAppService : EoaServerBaseService, IUserActivityAppServ
private readonly ChainOptions _chainOptions;
private readonly ITokenInfoProvider _tokenInfoProvider;
private readonly IAElfScanDataProvider _aelfScanDataProvider;
private readonly IImageProcessProvider _imageProcessProvider;

public UserActivityAppService(ILogger<UserActivityAppService> logger,
IOptionsSnapshot<ActivityOptions> activityOptions,
IOptionsSnapshot<TokenSpenderOptions> tokenSpenderOptions,
IOptionsSnapshot<ChainOptions> chainOptions,
ITokenInfoProvider tokenInfoProvider,
IImageProcessProvider imageProcessProvider,
IAElfScanDataProvider aelfScanDataProvider)
{
_logger = logger;
Expand All @@ -47,7 +50,7 @@ public UserActivityAppService(ILogger<UserActivityAppService> logger,
_chainOptions = chainOptions.Value;
_tokenInfoProvider = tokenInfoProvider;
_aelfScanDataProvider = aelfScanDataProvider;

_imageProcessProvider = imageProcessProvider;
}

public async Task<GetActivityDto> GetActivityAsync(GetActivityRequestDto request)
Expand All @@ -61,7 +64,7 @@ public async Task<GetActivityDto> GetActivityAsync(GetActivityRequestDto request
}

var tokenMap = await GetTokenMapAsync(txnDto.List);
return await ConvertDtoAsync(request.ChainId, txnDto.List[0], tokenMap);
return await ConvertDtoAsync(request.ChainId, txnDto.List[0], tokenMap, 0, 0);
}

public async Task<GetActivitiesDto> GetActivitiesAsync(GetActivitiesRequestDto request)
Expand Down Expand Up @@ -130,7 +133,7 @@ public async Task<GetActivitiesDto> GetActivitiesAsync(GetActivitiesRequestDto r
var activityDtos = new List<GetActivityDto>();
foreach (var txnDetail in txnDetails)
{
activityDtos.Add(await ConvertDtoAsync(txnChainMap[txnDetail.TransactionId], txnDetail, tokenMap));
activityDtos.Add(await ConvertDtoAsync(txnChainMap[txnDetail.TransactionId], txnDetail, tokenMap, request.Width, request.Height));
}

return new GetActivitiesDto()
Expand Down Expand Up @@ -245,7 +248,7 @@ private void SetDAppInfo(string toContractAddress, GetActivityDto activityDto, s
activityDto.DappIcon = tokenSpender.Icon;
}

private async Task<GetActivityDto> ConvertDtoAsync(string chainId, TransactionDetailDto dto, Dictionary<string, TokenInfoDto> tokenMap)
private async Task<GetActivityDto> ConvertDtoAsync(string chainId, TransactionDetailDto dto, Dictionary<string, TokenInfoDto> tokenMap, int width, int height)
{
var activityDto = new GetActivityDto
{
Expand Down Expand Up @@ -340,7 +343,9 @@ private async Task<GetActivityDto> ConvertDtoAsync(string chainId, TransactionDe

var nftInfo = new NftDetail()
{
ImageUrl = nftsTransferred.ImageUrl,
ImageUrl = await _imageProcessProvider.GetResizeImageAsync(
nftsTransferred.ImageUrl, width, height,
ImageResizeType.Forest),
Alias = tokenMap[nftsTransferred.Symbol]?.TokenName,
NftId = nftsTransferred.Symbol.Split("-").Last(),
IsSeed = isSeed,
Expand Down Expand Up @@ -375,7 +380,9 @@ private async Task<GetActivityDto> ConvertDtoAsync(string chainId, TransactionDe

var nftInfo = new NftDetail()
{
ImageUrl = nftsTransferred.ImageUrl,
ImageUrl = await _imageProcessProvider.GetResizeImageAsync(
nftsTransferred.ImageUrl, width, height,
ImageResizeType.Forest),
Alias = tokenMap[nftsTransferred.Symbol]?.TokenName,
NftId = nftsTransferred.Symbol.Split("-").Last(),
IsSeed = isSeed,
Expand Down

This file was deleted.

0 comments on commit 83833fc

Please sign in to comment.