Skip to content

preocompute account details #1475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 63 commits into
base: feat/performance-improvements
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
1ed33e8
create redirect to media controller
gabrielmatei Nov 18, 2024
dbdd216
redirect to media
gabrielmatei Nov 22, 2024
898b933
add unit tests
gabrielmatei Mar 11, 2025
2649ec9
Merge remote-tracking branch 'origin/development' into API-73-media-u…
gabrielmatei Mar 11, 2025
26afc3e
fixes
gabrielmatei Mar 11, 2025
b91e355
create NFT_THUMBNAIL_DEFAULT based on configs
gabrielmatei Mar 11, 2025
b5c8eb0
update media storage urls
gabrielmatei Mar 11, 2025
1a46b7d
apply redirect media on cached media
gabrielmatei Mar 12, 2025
046bbbb
priority ppu metadata first implementation
dragos-rebegea Mar 13, 2025
522d28a
fix distributeTransactionsIntoGasBuckets
dragos-rebegea Mar 13, 2025
6bed793
add last bucket only it has transactions
dragos-rebegea Mar 13, 2025
3116d1d
fix shard validation
dragos-rebegea Mar 13, 2025
2ad1561
fixes
gabrielmatei Mar 14, 2025
97b8b84
add csp header
gabrielmatei Mar 14, 2025
1f74198
update header
gabrielmatei Mar 14, 2025
27fcb43
stream files
gabrielmatei Mar 14, 2025
c4b42e2
update headers
gabrielmatei Mar 17, 2025
4a24c77
fix log message
gabrielmatei Mar 18, 2025
371b407
Merge branch 'API-73-media-url-resolving' into API-499-compute-media-…
gabrielmatei Mar 18, 2025
8a9e42e
Merge pull request #1460 from multiversx/API-73-media-url-resolving
gabrielmatei Mar 18, 2025
8957dc8
Merge pull request #1461 from multiversx/API-499-compute-media-url-links
gabrielmatei Mar 18, 2025
cc9f50f
fix lint errors on media.controller.ts
gabrielmatei Mar 18, 2025
eee5073
fix tests
gabrielmatei Mar 18, 2025
bda6634
refactor + add test ppu
cfaur09 Mar 18, 2025
ab0cc03
Merge pull request #1467 from multiversx/fix-media-tests
gabrielmatei Mar 18, 2025
0129970
linter fixes
cfaur09 Mar 18, 2025
bb2f30d
fix unit tests
cfaur09 Mar 18, 2025
793fb17
fix test
cfaur09 Mar 18, 2025
b4f9aa9
remove async await for sync functions
GuticaStefan Mar 19, 2025
8c0ff46
Merge pull request #1466 from multiversx/feat/media-redirect
dragos-rebegea Mar 20, 2025
958d9d0
remove async await for sync functions (#1469)
GuticaStefan Mar 24, 2025
fb35d87
add epoch field for transactions (#1464)
bogdan-rosianu Mar 24, 2025
232fd06
added missing relayer fields for sending txs (#1472)
bogdan-rosianu Mar 25, 2025
cc95a6a
Update dependencies and refactor imports for transaction processing
cfaur09 Mar 26, 2025
1466d6f
update tests
cfaur09 Mar 26, 2025
de00ac6
update API to latest nestjs-sdk
cfaur09 Mar 26, 2025
f48219c
add empty line after import
cfaur09 Mar 27, 2025
b7bc85c
precompute account details
GuticaStefan Mar 31, 2025
17f8863
add support for identities secondary sort criteria
cfaur09 Mar 31, 2025
d49bd36
use mongoose instead of typeorm
GuticaStefan Mar 31, 2025
8ccec33
Media redirect bugfixing (#1471)
gabrielmatei Mar 31, 2025
eec5e94
add andromeda support (#1468)
bogdan-rosianu Mar 31, 2025
ffe0ed5
precompute account tokens/nfts
GuticaStefan Mar 31, 2025
a8efeb2
db queries improvements
GuticaStefan Apr 1, 2025
35f3554
fix token isPaused property (#1477)
cfaur09 Apr 2, 2025
c523366
fetch token/nft for address from db
GuticaStefan Apr 2, 2025
cec74b2
add support for refreshRate round length (#1478)
cfaur09 Apr 3, 2025
008eaf0
Merge pull request #1473 from multiversx/API-530-update-api-multivers…
dragos-rebegea Apr 3, 2025
5f954f2
Merge branch 'development' into API-538-add-support-for-identities-se…
cfaur09 Apr 3, 2025
d342aa0
add support for receivedAt timestamp for account nfts (#1462)
cfaur09 Apr 3, 2025
ebfbe05
fix naming
dragos-rebegea Apr 3, 2025
e649765
lowercase naming
dragos-rebegea Apr 3, 2025
2de799a
Merge pull request #1463 from multiversx/transactions-ppu-by-shard
dragos-rebegea Apr 3, 2025
977dd05
improve sorting with multiple criterias (#1479)
dragos-rebegea Apr 3, 2025
a383889
Merge pull request #1476 from multiversx/API-538-add-support-for-iden…
dragos-rebegea Apr 3, 2025
29ee4b9
no cache on v2 endpoints
GuticaStefan Apr 7, 2025
622024b
Merge branch 'development' into API-507-api-improvements
GuticaStefan Apr 7, 2025
8b36bf3
restore tx processor
GuticaStefan Apr 7, 2025
a00fe8c
populate db script
GuticaStefan Apr 7, 2025
c34fa45
update scripts
gabrielmatei Apr 7, 2025
bef97d0
add index on populate db script
GuticaStefan Apr 8, 2025
ef67998
ignore account code in query
gabrielmatei Apr 8, 2025
1173804
remove no cache decorator
GuticaStefan Apr 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ features:
enabled: false
cronExpression: '*/5 * * * * *'
activationEpoch: 1043
chainAndromeda:
enabled: false
activationEpoch: 4
nodeEpochsLeft:
enabled: false
transactionProcessor:
Expand Down
3 changes: 3 additions & 0 deletions config/config.e2e.mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ features:
enabled: false
cronExpression: '*/5 * * * * *'
activationEpoch: 1391
chainAndromeda:
enabled: false
activationEpoch: 4
nodeEpochsLeft:
enabled: false
transactionProcessor:
Expand Down
3 changes: 3 additions & 0 deletions config/config.mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ features:
enabled: false
cronExpression: '*/5 * * * * *'
activationEpoch: 1391
chainAndromeda:
enabled: false
activationEpoch: 4
nodeEpochsLeft:
enabled: false
transactionProcessor:
Expand Down
3 changes: 3 additions & 0 deletions config/config.testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ features:
enabled: false
cronExpression: '*/5 * * * * *'
activationEpoch: 1043
chainAndromeda:
enabled: false
activationEpoch: 4
nodeEpochsLeft:
enabled: false
transactionProcessor:
Expand Down
4,299 changes: 2,031 additions & 2,268 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,19 @@
},
"dependencies": {
"@aws-sdk/client-s3": "^3.54.0",
"@elrondnetwork/erdjs-dex": "^0.2.12-alpha",
"@elrondnetwork/native-auth": "^0.1.19",
"@elrondnetwork/transaction-processor": "^0.1.26",
"@golevelup/nestjs-rabbitmq": "^4.0.0",
"@multiversx/sdk-core": "^13.2.2",
"@multiversx/sdk-data-api-client": "^0.7.0",
"@multiversx/sdk-nestjs-auth": "4.2.0",
"@multiversx/sdk-nestjs-cache": "4.2.0",
"@multiversx/sdk-nestjs-common": "4.2.0",
"@multiversx/sdk-nestjs-elastic": "^4.2.0",
"@multiversx/sdk-nestjs-http": "4.2.0",
"@multiversx/sdk-nestjs-monitoring": "4.2.0",
"@multiversx/sdk-nestjs-rabbitmq": "4.2.0",
"@multiversx/sdk-nestjs-redis": "4.2.0",
"@multiversx/sdk-wallet": "^4.0.0",
"@multiversx/sdk-exchange": "^0.2.21",
"@multiversx/sdk-nestjs-auth": "5.0.0",
"@multiversx/sdk-nestjs-cache": "5.0.0",
"@multiversx/sdk-nestjs-common": "5.0.0",
"@multiversx/sdk-nestjs-elastic": "5.0.0",
"@multiversx/sdk-nestjs-http": "5.0.0",
"@multiversx/sdk-nestjs-monitoring": "5.0.0",
"@multiversx/sdk-nestjs-rabbitmq": "5.0.0",
"@multiversx/sdk-nestjs-redis": "5.0.0",
"@multiversx/sdk-transaction-processor": "^0.1.35",
"@nestjs/apollo": "12.0.11",
"@nestjs/common": "10.2.0",
"@nestjs/config": "3.0.1",
Expand Down
10 changes: 9 additions & 1 deletion src/common/api-config/api.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Constants } from '@multiversx/sdk-nestjs-common';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DatabaseConnectionOptions } from '../persistence/entities/connection.options';
import { LogTopic } from '@elrondnetwork/transaction-processor';
import { StatusCheckerThresholds } from './entities/status-checker-thresholds';
import { LogTopic } from '@multiversx/sdk-transaction-processor/lib/types/log-topic';

@Injectable()
export class ApiConfigService {
Expand Down Expand Up @@ -862,6 +862,14 @@ export class ApiConfigService {
return deepHistoryUrl;
}

isChainAndromedaEnabled(): boolean {
return this.configService.get<boolean>('features.chainAndromeda.enabled') ?? false;
}

getChainAndromedaActivationEpoch(): number {
return this.configService.get<number>('features.chainAndromeda.activationEpoch') ?? 99999;
}

isAssetsCdnFeatureEnabled(): boolean {
return this.configService.get<boolean>('features.assetsFetch.enabled') ?? false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/indexer/elastic/elastic.indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ export class ElasticIndexerService implements IndexerInterface {
async getAllFungibleTokens(): Promise<any[]> {
const query = ElasticQuery.create()
.withMustMatchCondition('type', TokenType.FungibleESDT)
.withFields(["name", "type", "currentOwner", "numDecimals", "properties", "timestamp", "ownersHistory"])
.withFields(["name", "type", "currentOwner", "numDecimals", "properties", "timestamp", "ownersHistory", "paused"])
.withMustNotExistCondition('identifier')
.withPagination({ from: 0, size: 1000 });

Expand Down
2 changes: 1 addition & 1 deletion src/common/locked-asset/locked-asset.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from '@nestjs/common';
import { LockedAssetAttributes, UnlockMilestone, LockedTokenAttributes } from '@elrondnetwork/erdjs-dex';
import { ApiConfigService } from '../api-config/api.config.service';
import { VmQueryService } from '../../endpoints/vm.query/vm.query.service';
import { CacheInfo } from '../../utils/cache.info';
Expand All @@ -10,6 +9,7 @@ import { GatewayService } from '../gateway/gateway.service';
import { MexSettingsService } from 'src/endpoints/mex/mex.settings.service';
import { LockedTokensInterface } from './entities/locked.tokens.interface';
import { UnlockMileStoneModel } from './entities/unlock.milestone.model';
import { LockedAssetAttributes, UnlockMilestone, LockedTokenAttributes } from '@multiversx/sdk-exchange';

@Injectable()
export class LockedAssetService {
Expand Down
2 changes: 1 addition & 1 deletion src/common/websockets/web-socket-publisher-controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OriginLogger } from "@multiversx/sdk-nestjs-common";
import { ShardTransaction } from "@elrondnetwork/transaction-processor";
import { ShardTransaction } from "@multiversx/sdk-transaction-processor";
import { Controller } from "@nestjs/common";
import { EventPattern } from "@nestjs/microservices";
import { WebSocketPublisherService } from "src/common/websockets/web-socket-publisher-service";
Expand Down
2 changes: 1 addition & 1 deletion src/common/websockets/web-socket-publisher-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AddressUtils } from "@multiversx/sdk-nestjs-common";
import { ShardTransaction } from "@elrondnetwork/transaction-processor";
import { ShardTransaction } from "@multiversx/sdk-transaction-processor";
import { Injectable } from "@nestjs/common";
import { WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
import { Server, Socket } from 'socket.io';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CacheService } from "@multiversx/sdk-nestjs-cache";
import { ShardTransaction, TransactionProcessor } from "@elrondnetwork/transaction-processor";
import { ShardTransaction, TransactionProcessor } from "@multiversx/sdk-transaction-processor";
import { Inject, Injectable, Logger } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { Cron } from "@nestjs/schedule";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AddressUtils, BinaryUtils, OriginLogger } from "@multiversx/sdk-nestjs-common";
import { ShardTransaction } from "@elrondnetwork/transaction-processor";
import { ShardTransaction } from "@multiversx/sdk-transaction-processor";
import { Logger } from "@nestjs/common";
import { TransactionDetailed } from "src/endpoints/transactions/entities/transaction.detailed";
import { TransactionExtractorInterface } from "./transaction.extractor.interface";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BinaryUtils } from "@multiversx/sdk-nestjs-common";
import { ShardTransaction } from "@elrondnetwork/transaction-processor";
import { ShardTransaction } from "@multiversx/sdk-transaction-processor";
import { Logger } from "@nestjs/common";
import { TransactionExtractorInterface } from "./transaction.extractor.interface";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BinaryUtils } from "@multiversx/sdk-nestjs-common";
import { ShardTransaction } from "@elrondnetwork/transaction-processor";
import { ShardTransaction } from "@multiversx/sdk-transaction-processor";
import { Logger } from "@nestjs/common";
import { TransactionExtractorInterface } from "./transaction.extractor.interface";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ShardTransaction } from "@elrondnetwork/transaction-processor";
import { ShardTransaction } from "@multiversx/sdk-transaction-processor";
import { TransactionDetailed } from "src/endpoints/transactions/entities/transaction.detailed";

export interface TransactionExtractorInterface<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BinaryUtils } from "@multiversx/sdk-nestjs-common";
import { ShardTransaction } from "@elrondnetwork/transaction-processor";
import { ShardTransaction } from "@multiversx/sdk-transaction-processor";
import { Logger } from "@nestjs/common";
import { TransactionExtractorInterface } from "./transaction.extractor.interface";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CacheService } from "@multiversx/sdk-nestjs-cache";
import { LogTopic, TransactionProcessor } from "@elrondnetwork/transaction-processor";
import { Inject, Injectable, Logger } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { Cron } from "@nestjs/schedule";
Expand All @@ -8,6 +7,8 @@ import { CacheInfo } from "src/utils/cache.info";
import { LogMetricsEvent } from "src/common/entities/log.metrics.event";
import { EventEmitter2 } from "@nestjs/event-emitter";
import { MetricsEvents } from "src/utils/metrics-events.constants";
import { TransactionProcessor } from "@multiversx/sdk-transaction-processor";
import { LogTopic } from "@multiversx/sdk-transaction-processor/lib/types/log-topic";

@Injectable()
export class TransactionCompletedService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ClientProxy } from "@nestjs/microservices";
import { Cron } from "@nestjs/schedule";
import { ApiConfigService } from "src/common/api-config/api.config.service";
import { NodeService } from "src/endpoints/nodes/node.service";
import { ShardTransaction, TransactionProcessor } from "@elrondnetwork/transaction-processor";
import { CacheInfo } from "src/utils/cache.info";
import { EventEmitter2 } from '@nestjs/event-emitter';
import { SftChangeTransactionExtractor } from "./extractor/sft.change.transaction.extractor";
Expand All @@ -15,7 +14,7 @@ import { CacheService } from "@multiversx/sdk-nestjs-cache";
import { BinaryUtils, OriginLogger } from "@multiversx/sdk-nestjs-common";
import { PerformanceProfiler } from "@multiversx/sdk-nestjs-monitoring";
import { StakeFunction } from "src/endpoints/transactions/transaction-action/recognizers/staking/entities/stake.function";

import { ShardTransaction, TransactionProcessor } from "@multiversx/sdk-transaction-processor";

@Injectable()
export class TransactionProcessorService {
Expand Down
18 changes: 13 additions & 5 deletions src/endpoints/blocks/block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CacheService } from "@multiversx/sdk-nestjs-cache";
import { IndexerService } from "src/common/indexer/indexer.service";
import { NodeService } from "../nodes/node.service";
import { IdentitiesService } from "../identities/identities.service";
import { ApiConfigService } from "../../common/api-config/api.config.service";

@Injectable()
export class BlockService {
Expand All @@ -20,13 +21,14 @@ export class BlockService {
private readonly nodeService: NodeService,
@Inject(forwardRef(() => IdentitiesService))
private readonly identitiesService: IdentitiesService,
private readonly apiConfigService: ApiConfigService,
) { }

async getBlocksCount(filter: BlockFilter): Promise<number> {
return await this.cachingService.getOrSet(
CacheInfo.BlocksCount(filter).key,
async () => await this.indexerService.getBlocksCount(filter),
CacheInfo.BlocksCount(filter).ttl
CacheInfo.BlocksCount(filter).ttl,
);
}

Expand Down Expand Up @@ -96,21 +98,27 @@ export class BlockService {
validators = validators.map((index: number) => blses[index]);
}

return { shardId, epoch, validators, ...rest, proposer };
return {shardId, epoch, validators, ...rest, proposer};
}

async getBlock(hash: string): Promise<BlockDetailed> {
const result = await this.indexerService.getBlock(hash) as any;

const isChainAndromedaEnabled = this.apiConfigService.isChainAndromedaEnabled()
&& result.epoch >= this.apiConfigService.getChainAndromedaActivationEpoch();

if (result.round > 0) {
const publicKeys = await this.blsService.getPublicKeys(result.shardId, result.epoch);
result.proposer = publicKeys[result.proposer];
result.validators = result.validators.map((validator: number) => publicKeys[validator]);
if (!isChainAndromedaEnabled) {
result.validators = result.validators.map((validator: number) => publicKeys[validator]);
} else {
result.validators = publicKeys;
}
} else {
result.validators = [];
}


const block = BlockDetailed.mergeWithElasticResponse(new BlockDetailed(), result);
await this.applyProposerIdentity([block]);

Expand All @@ -131,7 +139,7 @@ export class BlockService {
CacheInfo.BlocksLatest(ttl).key,
async () => await this.getLatestBlockRaw(),
CacheInfo.BlocksLatest(ttl).ttl,
Math.round(CacheInfo.BlocksLatest(ttl).ttl / 10)
Math.round(CacheInfo.BlocksLatest(ttl).ttl / 10),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/dapp-config/dapp.config.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class DappConfigController {
@ApiOperation({ summary: 'Dapp configuration', description: 'Returns configuration used in dapps' })
@ApiOkResponse({ type: DappConfig })
@ApiNotFoundResponse({ description: 'Network configuration not found' })
getDappConfiguration(): DappConfig {
const configuration = this.dappConfigService.getDappConfiguration();
async getDappConfiguration(): Promise<DappConfig | undefined> {
const configuration = await this.dappConfigService.getDappConfiguration();
if (!configuration) {
throw new NotFoundException(`Network configuration not found`);
}
Expand Down
18 changes: 17 additions & 1 deletion src/endpoints/dapp-config/dapp.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@ import { FileUtils } from "@multiversx/sdk-nestjs-common";
import { Injectable } from "@nestjs/common";
import { ApiConfigService } from "src/common/api-config/api.config.service";
import { DappConfig } from "./entities/dapp-config";
import { GatewayService } from "src/common/gateway/gateway.service";

@Injectable()
export class DappConfigService {
private readonly dappConfig: DappConfig | undefined;

constructor(
private readonly apiConfigService: ApiConfigService,
private readonly gatewayService: GatewayService,
) {
this.dappConfig = this.getDappConfigurationRaw();
}

getDappConfiguration(): DappConfig | undefined {
async getDappConfiguration(): Promise<DappConfig | undefined> {
if (!this.dappConfig) {
return undefined;
}

const networkConfig = await this.gatewayService.getNetworkConfig();
const refreshRate = networkConfig.erd_round_duration;

if (refreshRate) {
return {
...this.dappConfig,
refreshRate,
};
}

return this.dappConfig;
}

Expand Down
3 changes: 3 additions & 0 deletions src/endpoints/dapp-config/entities/dapp-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ export class DappConfig {

@ApiProperty({ type: String, example: '1' })
chainId: string = '';

@ApiProperty({ type: Number, example: 6000 })
refreshRate: number = 0;
}
2 changes: 1 addition & 1 deletion src/endpoints/esdt/esdt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class EsdtService {
canAddSpecialRoles: elasticProperties.properties?.canAddSpecialRoles ?? false,
canTransferNFTCreateRole: elasticProperties.properties?.canTransferNFTCreateRole ?? false,
NFTCreateStopped: elasticProperties.properties?.NFTCreateStopped ?? false,
isPaused: elasticProperties.properties?.isPaused ?? false,
isPaused: elasticProperties.paused ?? false,
timestamp: elasticProperties.timestamp,
});

Expand Down
5 changes: 3 additions & 2 deletions src/endpoints/media/media.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OriginLogger } from "@multiversx/sdk-nestjs-common";
import { ApiService } from "@multiversx/sdk-nestjs-http";
import { BadRequestException, Injectable } from "@nestjs/common";
import { Injectable } from "@nestjs/common";
import { ApiConfigService } from "src/common/api-config/api.config.service";

@Injectable()
Expand All @@ -17,7 +17,8 @@ export class MediaService {
public async getRedirectUrl(uri: string): Promise<string | undefined> {
const isFeatureEnabled = this.apiConfigService.isMediaRedirectFeatureEnabled();
if (!isFeatureEnabled) {
throw new BadRequestException('Media redirect is not allowed');
// TODO: throw error
// throw new BadRequestException('Media redirect is not allowed');
}

// providers logos
Expand Down
24 changes: 15 additions & 9 deletions src/endpoints/nfts/nft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,25 +653,31 @@ export class NftService {
}

private applyRedirectMedia(nft: Nft) {
// FIXME: This is a temporary fix to avoid breaking the API
const isMediaRedirectFeatureEnabled = this.apiConfigService.isMediaRedirectFeatureEnabled();
if (!isMediaRedirectFeatureEnabled) {
return;
// return;
}

if (!nft.media || nft.media.length === 0) {
return;
}

const network = this.apiConfigService.getNetwork();
const defaultMediaUrl = `https://${network === 'mainnet' ? '' : `${network}-`}media.elrond.com`;
try {
const network = this.apiConfigService.getNetwork();
// const defaultMediaUrl = `https://${network === 'mainnet' ? '' : `${network}-`}media.elrond.com`;
const defaultMediaUrl = `https://${network === 'mainnet' ? '' : `${network}-`}api.multiversx.com/media`;

for (const media of nft.media) {
if (media.url) {
media.url = media.url.replace(defaultMediaUrl, this.apiConfigService.getMediaUrl());
}
if (media.thumbnailUrl) {
media.thumbnailUrl = media.thumbnailUrl.replace(defaultMediaUrl, this.apiConfigService.getMediaUrl());
for (const media of nft.media) {
if (media.url) {
media.url = media.url.replace(defaultMediaUrl, this.apiConfigService.getMediaUrl());
}
if (media.thumbnailUrl) {
media.thumbnailUrl = media.thumbnailUrl.replace(defaultMediaUrl, this.apiConfigService.getMediaUrl());
}
}
} catch {
// TODO: there are some cases where the nft.media is an empty object, we should investigate why
}
}
}
Loading