mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update WebfingerService. Fixes #3167
This commit is contained in:
parent
58f90e577b
commit
aff7456639
1 changed files with 29 additions and 6 deletions
|
@ -6,7 +6,7 @@ use Cache;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
use Illuminate\Support\Facades\Redis;
|
use Illuminate\Support\Facades\Redis;
|
||||||
use App\Util\Webfinger\WebfingerUrl;
|
use App\Util\Webfinger\WebfingerUrl;
|
||||||
use Zttp\Zttp;
|
use Illuminate\Support\Facades\Http;
|
||||||
use App\Util\ActivityPub\Helpers;
|
use App\Util\ActivityPub\Helpers;
|
||||||
use App\Transformer\Api\AccountTransformer;
|
use App\Transformer\Api\AccountTransformer;
|
||||||
use League\Fractal;
|
use League\Fractal;
|
||||||
|
@ -32,16 +32,39 @@ class WebfingerService
|
||||||
if(!Helpers::validateUrl($url)) {
|
if(!Helpers::validateUrl($url)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$res = Zttp::get($url);
|
|
||||||
$webfinger = $res->json();
|
$res = Http::retry(3, 500)
|
||||||
if(!isset($webfinger['links'])) {
|
->acceptJson()
|
||||||
|
->withHeaders([
|
||||||
|
'User-Agent' => '(Pixelfed/' . config('pixelfed.version') . '; +' . config('app.url') . ')'
|
||||||
|
])
|
||||||
|
->timeout(20)
|
||||||
|
->get($url);
|
||||||
|
|
||||||
|
if(!$res->successful()) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$profile = Helpers::profileFetch($webfinger['links'][0]['href']);
|
|
||||||
|
$webfinger = $res->json();
|
||||||
|
if(!isset($webfinger['links']) || !is_array($webfinger['links']) || empty($webfinger['links'])) {
|
||||||
|
return ['nolinks'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = collect($webfinger['links'])
|
||||||
|
->filter(function($link) {
|
||||||
|
return $link &&
|
||||||
|
isset($link['type']) &&
|
||||||
|
isset($link['href']) &&
|
||||||
|
$link['type'] == 'application/activity+json';
|
||||||
|
})
|
||||||
|
->pluck('href')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$profile = Helpers::profileFetch($link);
|
||||||
$fractal = new Fractal\Manager();
|
$fractal = new Fractal\Manager();
|
||||||
$fractal->setSerializer(new ArraySerializer());
|
$fractal->setSerializer(new ArraySerializer());
|
||||||
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
||||||
$res = $fractal->createData($resource)->toArray();
|
$res = $fractal->createData($resource)->toArray();
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue