diff --git a/app/Jobs/InboxPipeline/DeleteWorker.php b/app/Jobs/InboxPipeline/DeleteWorker.php index dead58163..74039d40a 100644 --- a/app/Jobs/InboxPipeline/DeleteWorker.php +++ b/app/Jobs/InboxPipeline/DeleteWorker.php @@ -14,8 +14,9 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Zttp\Zttp; use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline; +use Illuminate\Support\Facades\Http; +use Illuminate\Http\Client\ConnectionException; class DeleteWorker implements ShouldQueue { @@ -200,10 +201,20 @@ class DeleteWorker implements ShouldQueue if(Helpers::validateUrl($actor->remote_url) == false) { return; } - $res = Zttp::timeout(60)->withHeaders([ - 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', - 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', - ])->get($actor->remote_url); + + try { + $res = Http::timeout(20)->withHeaders([ + 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', + ])->get($actor->remote_url); + } catch (ConnectionException $e) { + return false; + } + + if(!$res->ok()) { + return false; + } + $res = json_decode($res->body(), true, 8); if(!isset($res['publicKey'], $res['publicKey']['id'])) { return; diff --git a/app/Jobs/InboxPipeline/InboxValidator.php b/app/Jobs/InboxPipeline/InboxValidator.php index 366d81326..3587ec2f5 100644 --- a/app/Jobs/InboxPipeline/InboxValidator.php +++ b/app/Jobs/InboxPipeline/InboxValidator.php @@ -14,8 +14,9 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Zttp\Zttp; use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline; +use Illuminate\Support\Facades\Http; +use Illuminate\Http\Client\ConnectionException; class InboxValidator implements ShouldQueue { @@ -27,6 +28,7 @@ class InboxValidator implements ShouldQueue public $timeout = 60; public $tries = 1; + public $maxExceptions = 1; /** * Create a new job instance. @@ -177,10 +179,20 @@ class InboxValidator implements ShouldQueue if(Helpers::validateUrl($actor->remote_url) == false) { return; } - $res = Zttp::timeout(60)->withHeaders([ - 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', - 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', - ])->get($actor->remote_url); + + try { + $res = Http::timeout(20)->withHeaders([ + 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', + ])->get($actor->remote_url); + } catch (ConnectionException $e) { + return false; + } + + if(!$res->ok()) { + return false; + } + $res = json_decode($res->body(), true, 8); if(!$res || empty($res) || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { return; diff --git a/app/Jobs/InboxPipeline/InboxWorker.php b/app/Jobs/InboxPipeline/InboxWorker.php index e3165666a..be5eaab95 100644 --- a/app/Jobs/InboxPipeline/InboxWorker.php +++ b/app/Jobs/InboxPipeline/InboxWorker.php @@ -14,8 +14,9 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Zttp\Zttp; use App\Jobs\DeletePipeline\DeleteRemoteProfilePipeline; +use Illuminate\Support\Facades\Http; +use Illuminate\Http\Client\ConnectionException; class InboxWorker implements ShouldQueue { @@ -26,6 +27,7 @@ class InboxWorker implements ShouldQueue public $timeout = 60; public $tries = 1; + public $maxExceptions = 1; /** * Create a new job instance. @@ -163,10 +165,20 @@ class InboxWorker implements ShouldQueue if(Helpers::validateUrl($actor->remote_url) == false) { return; } - $res = Zttp::timeout(60)->withHeaders([ - 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', - 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', - ])->get($actor->remote_url); + + try { + $res = Http::timeout(20)->withHeaders([ + 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => 'PixelfedBot v0.1 - https://pixelfed.org', + ])->get($actor->remote_url); + } catch (ConnectionException $e) { + return false; + } + + if(!$res->ok()) { + return false; + } + $res = json_decode($res->body(), true, 8); if(!$res || empty($res) || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { return; diff --git a/database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php b/database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php new file mode 100644 index 000000000..32cf0af65 --- /dev/null +++ b/database/migrations/2022_12_05_064156_add_key_id_index_to_profiles_table.php @@ -0,0 +1,34 @@ +index('key_id'); + $table->index('remote_url'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('profiles', function (Blueprint $table) { + $table->dropIndex('profiles_key_id_index'); + $table->dropIndex('profiles_remote_url_index'); + }); + } +};