From 5a7ed1f2f803d0800b4e2ff3bede5b465b59d8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Wed, 3 Dec 2025 13:15:00 +0100 Subject: [PATCH] Media --- src/Command/CacheMediaDiscoveryCommand.php | 19 ++++++++++++++++++- src/Service/NostrClient.php | 10 +++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Command/CacheMediaDiscoveryCommand.php b/src/Command/CacheMediaDiscoveryCommand.php index 645d9cb..17af844 100644 --- a/src/Command/CacheMediaDiscoveryCommand.php +++ b/src/Command/CacheMediaDiscoveryCommand.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Command; use App\Service\NostrClient; +use App\Util\NostrKeyUtil; use Psr\Log\LoggerInterface; use swentel\nostr\Nip19\Nip19Helper; use Symfony\Component\Console\Attribute\AsCommand; @@ -64,7 +65,7 @@ class CacheMediaDiscoveryCommand extends Command } $env = $this->params->get('kernel.environment'); - $cacheKey = 'media_discovery_events_all_' . $env; + $cacheKey = 'media_discovery_events_all_prod'; if ($force) { $io->info('Force refresh enabled - deleting existing cache'); @@ -98,6 +99,22 @@ class CacheMediaDiscoveryCommand extends Command $mediaEvents = $this->filterNSFW($mediaEvents); $io->comment(sprintf('After NSFW filter: %d events', count($mediaEvents))); + $keyUtil = new NostrKeyUtil(); + // Filter out npubs in blocklist + $blocked = [ + $keyUtil->npubToHex('npub1prxnwedta6z2sv8atavcsd3hl8f8s8c9acc3syw6myfug92q07us5429qj'), + $keyUtil->npubToHex('npub1jpc8h8fwdrsw5r3e7huahktd6npxzz9prq9t4dgcv9djdq8ggwhqd4xrcs'), + ]; + + $mediaEvents = array_filter($mediaEvents, function($event) use ($blocked, $io) { + $io->comment($event->pubkey); + + return !in_array($event->pubkey, $blocked); + }); + + $io->comment(sprintf('After blocklist filter: %d events', count($mediaEvents))); + + // Encode event IDs as note1... for each event $nip19 = new Nip19Helper(); foreach ($mediaEvents as $event) { diff --git a/src/Service/NostrClient.php b/src/Service/NostrClient.php index 81423ee..de75d59 100644 --- a/src/Service/NostrClient.php +++ b/src/Service/NostrClient.php @@ -827,14 +827,14 @@ class NostrClient $allEvents = []; // Fetch events for each hashtag - foreach ($hashtags as $hashtag) { + $request = $this->createNostrRequest( kinds: [20], // NIP-68 Pictures; consider expanding to 21/22 later filters: [ - 'tag' => ['#t', [$hashtag]], - 'limit' => 100 // Fetch up to 100 per hashtag + 'tag' => ['#t', $hashtags], + 'limit' => 500 // Fetch up to 100 per hashtag ], - relaySet: $this->createRelaySet(static::REPUTABLE_RELAYS) + relaySet: $this->createRelaySet(['wss://theforest.nostr1.com']) ); $events = $this->processResponse($request->send(), function($event) { @@ -842,7 +842,7 @@ class NostrClient }); $allEvents = array_merge($allEvents, $events); - } + return $allEvents; }