1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-23 16:24:29 +00:00
This commit is contained in:
Daniel Supernault 2022-01-22 19:42:37 -07:00
parent 127777261a
commit 792212b655
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -4,14 +4,10 @@ namespace App\Services;
use Cache; use Cache;
use App\Profile; use App\Profile;
use Illuminate\Support\Facades\Redis;
use App\Util\Webfinger\WebfingerUrl; use App\Util\Webfinger\WebfingerUrl;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use App\Util\ActivityPub\Helpers; use App\Util\ActivityPub\Helpers;
use App\Transformer\Api\AccountTransformer; use App\Services\AccountService;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
class WebfingerService class WebfingerService
{ {
@ -23,17 +19,14 @@ class WebfingerService
protected function run($query) protected function run($query)
{ {
if($profile = Profile::whereUsername($query)->first()) { if($profile = Profile::whereUsername($query)->first()) {
$fractal = new Fractal\Manager(); return AccountService::get($profile->id);
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
return $fractal->createData($resource)->toArray();
} }
$url = WebfingerUrl::generateWebfingerUrl($query); $url = WebfingerUrl::generateWebfingerUrl($query);
if(!Helpers::validateUrl($url)) { if(!Helpers::validateUrl($url)) {
return []; return [];
} }
$res = Http::retry(3, 500) $res = Http::retry(3, 100)
->acceptJson() ->acceptJson()
->withHeaders([ ->withHeaders([
'User-Agent' => '(Pixelfed/' . config('pixelfed.version') . '; +' . config('app.url') . ')' 'User-Agent' => '(Pixelfed/' . config('pixelfed.version') . '; +' . config('app.url') . ')'
@ -47,7 +40,7 @@ class WebfingerService
$webfinger = $res->json(); $webfinger = $res->json();
if(!isset($webfinger['links']) || !is_array($webfinger['links']) || empty($webfinger['links'])) { if(!isset($webfinger['links']) || !is_array($webfinger['links']) || empty($webfinger['links'])) {
return ['nolinks']; return [];
} }
$link = collect($webfinger['links']) $link = collect($webfinger['links'])
@ -61,10 +54,6 @@ class WebfingerService
->first(); ->first();
$profile = Helpers::profileFetch($link); $profile = Helpers::profileFetch($link);
$fractal = new Fractal\Manager(); return AccountService::get($profile->id);
$fractal->setSerializer(new ArraySerializer());
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
$res = $fractal->createData($resource)->toArray();
return $res;
} }
} }