feat(*): refactor metadata handling; move metadata to backend where possible, refine client views

This commit is contained in:
Cory Dransfeldt 2025-05-25 20:15:45 -07:00
parent 929bc9f9f8
commit 9687509e4a
No known key found for this signature in database
35 changed files with 506 additions and 339 deletions

View file

@ -3,23 +3,29 @@
namespace App\Classes;
use App\Classes\BaseHandler;
use App\Classes\GlobalsFetcher;
abstract class PageFetcher extends BaseHandler
{
protected ?array $globals = null;
protected function cacheGet(string $key): mixed
{
return $this->cache && $this->cache->exists($key) ? json_decode($this->cache->get($key), true) : null;
return $this->cache && $this->cache->exists($key)
? json_decode($this->cache->get($key), true)
: null;
}
protected function cacheSet(string $key, mixed $value, int $ttl = 3600): void
{
if ($this->cache) $this->cache->setex($key, $ttl, json_encode($value));
if ($this->cache) {
$this->cache->setex($key, $ttl, json_encode($value));
}
}
protected function fetchSingleFromApi(string $endpoint, string $url): ?array
{
$data = $this->fetchFromApi($endpoint, "url=eq./{$url}");
return $data[0] ?? null;
}
@ -27,4 +33,14 @@ abstract class PageFetcher extends BaseHandler
{
return $this->makeRequest("POST", $endpoint, ['json' => $body]);
}
public function getGlobals(): ?array
{
if ($this->globals !== null) return $this->globals;
$fetcher = new GlobalsFetcher();
$this->globals = $fetcher->fetch();
return $this->globals;
}
}