From a2eb39e61ebda36fa4b6d43455b5e3943b05dbdd Mon Sep 17 00:00:00 2001 From: fsociety Date: Wed, 16 Oct 2024 16:34:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20feat(NostrFetcher):=20add=20null?= =?UTF-8?q?=20check=20for=20event=20before=20processing=20JSON=20data=20in?= =?UTF-8?q?=20profile=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Traits/NostrFetcherTrait.php | 36 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/Traits/NostrFetcherTrait.php b/app/Traits/NostrFetcherTrait.php index d256cdf..9c6c921 100644 --- a/app/Traits/NostrFetcherTrait.php +++ b/app/Traits/NostrFetcherTrait.php @@ -3,6 +3,7 @@ namespace App\Traits; use App\Models\Profile; +use Illuminate\Support\Facades\Log; use swentel\nostr\Filter\Filter; use swentel\nostr\Key\Key; use swentel\nostr\Message\RequestMessage; @@ -71,27 +72,28 @@ trait NostrFetcherTrait foreach ($data as $item) { try { - $result = json_decode($item->event->content, true, 512, JSON_THROW_ON_ERROR); + if (isset($item->event)) { + $result = json_decode($item->event->content, true, 512, JSON_THROW_ON_ERROR); + Profile::query()->updateOrCreate( + ['pubkey' => $item->event->pubkey], + [ + 'name' => $result['name'] ?? null, + 'display_name' => $result['display_name'] ?? null, + 'picture' => $result['picture'] ?? null, + 'banner' => $result['banner'] ?? null, + 'website' => $result['website'] ?? null, + 'about' => $result['about'] ?? null, + 'nip05' => $result['nip05'] ?? null, + 'lud16' => $result['lud16'] ?? null, + 'lud06' => $result['lud06'] ?? null, + 'deleted' => $result['deleted'] ?? false, + ], + ); + } } catch (\JsonException $e) { throw new \RuntimeException('Error decoding JSON: ' . $e->getMessage()); } - Profile::query()->updateOrCreate( - ['pubkey' => $item->event->pubkey], - [ - 'name' => $result['name'] ?? null, - 'display_name' => $result['display_name'] ?? null, - 'picture' => $result['picture'] ?? null, - 'banner' => $result['banner'] ?? null, - 'website' => $result['website'] ?? null, - 'about' => $result['about'] ?? null, - 'nip05' => $result['nip05'] ?? null, - 'lud16' => $result['lud16'] ?? null, - 'lud06' => $result['lud06'] ?? null, - 'deleted' => $result['deleted'] ?? false, - ] - ); } - } }