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