From 3584625b47fd55e2756884b2cdb811f0c6de06b8 Mon Sep 17 00:00:00 2001 From: unarist <m.unarist@gmail.com> Date: Mon, 11 Feb 2019 01:43:29 +0900 Subject: [PATCH] =?UTF-8?q?Actor=E3=81=AE=E5=8F=96=E5=BE=97=E5=A4=B1?= =?UTF-8?q?=E6=95=97=E3=82=92=E3=81=A1=E3=82=83=E3=82=93=E3=81=A8=E7=84=A1?= =?UTF-8?q?=E8=A6=96=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MetadataResolver/ActivityPubResolver.php | 28 +++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/MetadataResolver/ActivityPubResolver.php b/app/MetadataResolver/ActivityPubResolver.php index f790f02..10fc27e 100644 --- a/app/MetadataResolver/ActivityPubResolver.php +++ b/app/MetadataResolver/ActivityPubResolver.php @@ -3,6 +3,8 @@ namespace App\MetadataResolver; use Psr\Http\Message\ResponseInterface; +use GuzzleHttp\Exception\TransferException; +use Illuminate\Support\Facades\Log; class ActivityPubResolver implements Resolver, Parser { @@ -46,18 +48,24 @@ class ActivityPubResolver implements Resolver, Parser private function getTitleFromActor(string $url): string { - $res = $this->activityClient->get($url); - if ($res->getStatusCode() !== 200) { + try { + $res = $this->activityClient->get($url); + if ($res->getStatusCode() !== 200) { + Log::info(self::class . ': Actorの取得に失敗 URL=' . $url); + return ''; + } + + $actor = json_decode($res->getBody(), true); + $title = $actor['name'] ?? ''; + if (isset($actor['preferredUsername'])) { + $title .= ' (@' . $actor['preferredUsername'] . '@' . parse_url($actor['id'], PHP_URL_HOST) . ')'; + } + + return $title; + } catch (TransferException $e) { + Log::info(self::class . ': Actorの取得に失敗 URL=' . $url); return ''; } - - $actor = json_decode($res->getBody(), true); - $title = $actor['name'] ?? ''; - if (isset($actor['preferredUsername'])) { - $title .= ' (@' . $actor['preferredUsername'] . '@' . parse_url($actor['id'], PHP_URL_HOST) . ')'; - } - - return $title; } private function html2text(string $html): string