Skip to content

Commit

Permalink
chore: merge rc into main (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsANameToo authored Nov 14, 2023
2 parents c3dfc31 + 9aba99f commit dc17a91
Show file tree
Hide file tree
Showing 398 changed files with 9,813 additions and 1,277 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ SEEDER_NFTS_CHUNK_SIZE=50
PORTFOLIO_ENABLED=true
GALLERIES_ENABLED=true
COLLECTIONS_ENABLED=true
ARTICLES_ENABLED=true

TESTNET_ENABLED=false

Expand All @@ -160,4 +161,7 @@ TELESCOPE_ENABLED=false

BROWSERSHOT_NODE_BINARY="/usr/local/bin/node"
BROWSERSHOT_NPM_BINARY="/usr/local/bin/npm"
BROWSERSHOT_TIMEOUT=60
BROWSERSHOT_TIMEOUT=60

AUDIO_CONVERSION_DELAY_SECONDS=3
AUDIO_CONVERSION_ENABLED=false
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = {
},
},
],
"sonarjs/no-duplicate-string": "off",
"import/default": "error",
"import/export": "error",
"import/first": "error",
Expand Down Expand Up @@ -140,7 +141,6 @@ module.exports = {
rules: {
"@typescript-eslint/no-unsafe-call": "off",
"import/no-namespace": "off",
"sonarjs/no-duplicate-string": "off",
},
},
],
Expand Down
70 changes: 70 additions & 0 deletions app/Console/Commands/GenerateAudioFileForArticle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Jobs\ConvertArticleToSpeech;
use App\Models\Article;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Builder;

class GenerateAudioFileForArticle extends Command
{
protected $signature = 'articles:generate-audio-file
{id? : ID of the article}
{--from= : ID of the starting article}
{--to= : ID of the ending article}
{--missing : Only query articles that have never had audio file generated}
';

protected $description = 'Regenerate audio file for the article with the given ID';

public function handle(): int
{
if (! ConvertArticleToSpeech::$enabled || ! (bool) config('dashbrd.text_to_speech.enabled')) {
$this->warn('Article text-to-speech is currently disabled.');

return Command::SUCCESS;
}

$articles = $this->articles()
->isPublished()
->when($this->option('missing'), static fn ($query) => $query->whereNull('audio_file_url'))
->get();

if ($articles->isEmpty()) {
$this->warn('No articles found.');

return Command::SUCCESS;
}

$articles->each(static function ($article) {
ConvertArticleToSpeech::dispatch($article);
});

$this->info('Regenerating audio files for '.$articles->count().' articles.');

$chars = $articles->sum(static fn ($article) => strlen($article->content));

$this->info('Total number of characters sent to AWS: '.number_format($chars).' (could be less because this also includes markdown characters).');

return Command::SUCCESS;
}

/**
* @return Builder<Article>
*/
private function articles(): Builder
{
if ($this->argument('id') !== null) {
return Article::where('id', $this->argument('id'));
}

return Article::query()
->orderBy('id', 'asc')
->limit(500)
->when($this->option('from'), static fn ($query, $from) => $query->where('id', '>=', $from))
->when($this->option('to'), static fn ($query, $to) => $query->where('id', '<=', $to));
}
}
18 changes: 9 additions & 9 deletions app/Console/Commands/LiveDumpNfts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Collection as NftCollection;
use App\Models\Network;
use App\Models\Token;
Expand Down Expand Up @@ -89,7 +89,7 @@ public function handle(): int
return Command::INVALID;
}

$chain = Chains::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));
$chain = Chain::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));

$topCollections = $this->getTopCollections($chain, self::COLLECTION_LIMIT);

Expand Down Expand Up @@ -133,7 +133,7 @@ public function handle(): int
return Command::SUCCESS;
}

private function prepareCollectionModel(Chains $chain, stdClass $collection): NftCollection
private function prepareCollectionModel(Chain $chain, stdClass $collection): NftCollection
{
$network = Network::firstWhere('chain_id', $chain->value);

Expand Down Expand Up @@ -161,7 +161,7 @@ private function prepareCollectionModel(Chains $chain, stdClass $collection): Nf
/**
* @return IlluminateCollection<int, array<string, mixed>> $collections
*/
private function getTopCollections(Chains $chain, int $limit = 25): IlluminateCollection
private function getTopCollections(Chain $chain, int $limit = 25): IlluminateCollection
{
$chainName = strtolower($chain->name);
$fileName = self::nftsSubDir."/top-{$chainName}-collections.json";
Expand Down Expand Up @@ -215,7 +215,7 @@ private function filterNftAttributes(array $nft): array

private function getCollectionNftsAndPersist(
NftCollection $collection,
Chains $chain,
Chain $chain,
int $itemsTotal,
int $chunk,
string $cursor = null,
Expand Down Expand Up @@ -250,7 +250,7 @@ private function getCollectionNftsAndPersist(
$progressBar->finish();
}

private function mergeNftChunks(Chains $chain, string $contractAddress): void
private function mergeNftChunks(Chain $chain, string $contractAddress): void
{
$fs = Storage::disk(self::diskName);

Expand All @@ -272,12 +272,12 @@ private function mergeNftChunks(Chains $chain, string $contractAddress): void
$this->info('Total NFTs count: '.count($nfts));
}

private function prepareCollectionPath(Chains $chain, string $contractAddress): string
private function prepareCollectionPath(Chain $chain, string $contractAddress): string
{
return self::nftsSubDir.'/'.Str::lower($chain->name).'_'.$contractAddress;
}

private function getTokenCursorForChunk(int $chunk, Chains $chain, string $contractAddress): ?string
private function getTokenCursorForChunk(int $chunk, Chain $chain, string $contractAddress): ?string
{
$path = $this->prepareCollectionPath($chain, $contractAddress);

Expand All @@ -294,7 +294,7 @@ private function getTokenCursorForChunk(int $chunk, Chains $chain, string $contr
return Arr::get($nftChunk, 'nextToken');
}

private function getCollectionTraitsAndPersist(Chains $chain, string $address): void
private function getCollectionTraitsAndPersist(Chain $chain, string $address): void
{
$this->info('Fetching collection traits...');

Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/LiveDumpWallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Contracts\Web3DataProvider;
use App\Data\Web3\Web3NftData;
use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Network;
use App\Models\User;
use App\Models\Wallet;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function handle(): int

$providers = [new AlchemyWeb3DataProvider(), new MoralisWeb3DataProvider()];

$chains = [Chains::ETH, Chains::Polygon];
$chains = [Chain::ETH, Chain::Polygon];

/** @var string[] */
$addresses = config('dashbrd.live_dump_wallets');
Expand Down Expand Up @@ -114,7 +114,7 @@ public function handle(): int
// Download traits for each collection
$allTraits = $nftCollections->mapWithKeys(function ($collectionAddresses, $chainId) {
$traits = $collectionAddresses->unique()
->mapWithKeys(fn ($collectionAddress) => [$collectionAddress => Mnemonic::getNftCollectionTraits(Chains::from($chainId), $collectionAddress)]);
->mapWithKeys(fn ($collectionAddress) => [$collectionAddress => Mnemonic::getNftCollectionTraits(Chain::from($chainId), $collectionAddress)]);

return [$chainId => $traits];
});
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/SyncActivityPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Enums\Chains;
use App\Enums\Chain;
use App\Enums\TokenGuid;
use App\Models\Network;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function handle(): int
DB::beginTransaction();
$this->info('Updating NFT activity table...');

$network = Network::firstWhere('chain_id', Chains::Polygon);
$network = Network::firstWhere('chain_id', Chain::Polygon);
$ethereumGuid = TokenGuid::Ethereum->value;
$polygonGuid = TokenGuid::Polygon->value;

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/SyncSpamContracts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Console\Commands;

use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Network;
use App\Models\SpamContract;
use App\Support\Facades\Alchemy;
Expand Down Expand Up @@ -33,7 +33,7 @@ class SyncSpamContracts extends Command
*/
public function handle(): int
{
$chain = Chains::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));
$chain = Chain::from($this->option('chain-id') === null ? 1 : (int) $this->option('chain-id'));

/** @var Network $network */
$network = Network::query()->where('chain_id', $chain)->first();
Expand Down
38 changes: 38 additions & 0 deletions app/Console/Commands/UpdateArticlesViewCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use App\Models\Article;
use App\Support\Queues;
use Illuminate\Console\Command;

class UpdateArticlesViewCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'articles:update-view-count';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Updates view count of the articles';

/**
* Execute the console command.
*/
public function handle(): int
{
dispatch(static function () {
Article::updateViewCounts();
})->onQueue(Queues::SCHEDULED_DEFAULT);

return Command::SUCCESS;
}
}
8 changes: 8 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\Console\Commands\MarketData\VerifySupportedCurrencies;
use App\Console\Commands\PruneMetaImages;
use App\Console\Commands\SyncSpamContracts;
use App\Console\Commands\UpdateArticlesViewCount;
use App\Console\Commands\UpdateCollectionsFiatValue;
use App\Console\Commands\UpdateDiscordMembers;
use App\Console\Commands\UpdateGalleriesScore;
Expand Down Expand Up @@ -96,6 +97,13 @@ protected function schedule(Schedule $schedule): void
->command(FetchCoingeckoTokens::class)
->withoutOverlapping()
->twiceMonthly(1, 16);

if (Feature::active(Features::Articles->value)) {
$schedule
->command(UpdateArticlesViewCount::class)
->withoutOverlapping()
->hourlyAt(2);
}
}

private function scheduleJobsForCollectionsOrGalleries(Schedule $schedule): void
Expand Down
17 changes: 17 additions & 0 deletions app/Contracts/TextToSpeechProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace App\Contracts;

use App\Enums\TextToSpeechConversionStatus;
use App\Models\Article;

interface TextToSpeechProvider
{
public function convert(Article $article): string;

public function status(string $conversionId): TextToSpeechConversionStatus;

public function url(string $conversionId): string;
}
4 changes: 2 additions & 2 deletions app/Contracts/Web3DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Data\Web3\Web3Erc20TokenData;
use App\Data\Web3\Web3NftCollectionFloorPrice;
use App\Data\Web3\Web3NftsChunk;
use App\Enums\Chains;
use App\Enums\Chain;
use App\Models\Collection as CollectionModel;
use App\Models\Network;
use App\Models\Wallet;
Expand Down Expand Up @@ -38,5 +38,5 @@ public function getBlockTimestamp(Network $network, int $blockNumber): Carbon;
*/
public function getMiddleware(): array;

public function getNftCollectionFloorPrice(Chains $chain, string $contractAddress): ?Web3NftCollectionFloorPrice;
public function getNftCollectionFloorPrice(Chain $chain, string $contractAddress): ?Web3NftCollectionFloorPrice;
}
Loading

0 comments on commit dc17a91

Please sign in to comment.