Browse Source

Get media from all over

imwald
Nuša Pukšič 1 month ago
parent
commit
0044644610
  1. 5
      src/Command/CacheMediaDiscoveryCommand.php
  2. 6
      src/Controller/MediaDiscoveryController.php
  3. 19
      src/Service/NostrClient.php

5
src/Command/CacheMediaDiscoveryCommand.php

@ -13,6 +13,7 @@ use Symfony\Component\Console\Input\InputInterface; @@ -13,6 +13,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Contracts\Cache\CacheInterface;
#[AsCommand(
@ -35,6 +36,7 @@ class CacheMediaDiscoveryCommand extends Command @@ -35,6 +36,7 @@ class CacheMediaDiscoveryCommand extends Command
private readonly NostrClient $nostrClient,
private readonly CacheInterface $cache,
private readonly LoggerInterface $logger,
private readonly ParameterBagInterface $params,
) {
parent::__construct();
}
@ -61,7 +63,8 @@ class CacheMediaDiscoveryCommand extends Command @@ -61,7 +63,8 @@ class CacheMediaDiscoveryCommand extends Command
$allHashtags = array_merge($allHashtags, self::TOPIC_HASHTAGS[$topic]);
}
$cacheKey = 'media_discovery_events_all';
$env = $this->params->get('kernel.environment');
$cacheKey = 'media_discovery_events_all_' . $env;
if ($force) {
$io->info('Force refresh enabled - deleting existing cache');

6
src/Controller/MediaDiscoveryController.php

@ -5,6 +5,7 @@ declare(strict_types=1); @@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Cache\CacheInterface;
@ -22,7 +23,7 @@ class MediaDiscoveryController extends AbstractController @@ -22,7 +23,7 @@ class MediaDiscoveryController extends AbstractController
];
#[Route('/multimedia', name: 'media-discovery')]
public function discover(CacheInterface $cache): Response
public function discover(CacheInterface $cache, ParameterBagInterface $params): Response
{
// Defaulting to all, might do topics later
try {
@ -33,7 +34,8 @@ class MediaDiscoveryController extends AbstractController @@ -33,7 +34,8 @@ class MediaDiscoveryController extends AbstractController
}
// Cache key for all media events
$cacheKey = 'media_discovery_events_all';
$env = $params->get('kernel.environment');
$cacheKey = 'media_discovery_events_all_' . $env;
// Read from cache only - the cache is populated by the CacheMediaDiscoveryCommand
$allCachedEvents = $cache->get($cacheKey, function () {

19
src/Service/NostrClient.php

@ -826,23 +826,6 @@ class NostrClient @@ -826,23 +826,6 @@ class NostrClient
{
$allEvents = [];
// Prefer local relay if configured
if ($this->nostrDefaultRelay) {
$this->logger->info('Using local relay for media discovery hashtag fetch', [
'relay' => $this->nostrDefaultRelay,
'hashtags' => $hashtags,
]);
$relayset = $this->createRelaySet([$this->nostrDefaultRelay]);
} else {
// Fallback to known public media-friendly relays
$relayUrls = ['wss://theforest.nostr1.com', 'wss://relay.nostr.band'];
$this->logger->info('Using public relays for media discovery hashtag fetch', [
'relays' => $relayUrls,
'hashtags' => $hashtags,
]);
$relayset = $this->createRelaySet($relayUrls);
}
// Fetch events for each hashtag
foreach ($hashtags as $hashtag) {
$request = $this->createNostrRequest(
@ -851,7 +834,7 @@ class NostrClient @@ -851,7 +834,7 @@ class NostrClient
'tag' => ['#t', [$hashtag]],
'limit' => 100 // Fetch up to 100 per hashtag
],
relaySet: $relayset
relaySet: $this->createRelaySet(static::REPUTABLE_RELAYS)
);
$events = $this->processResponse($request->send(), function($event) {

Loading…
Cancel
Save