forked from mirror/pixelfed
commit
9f9a52b683
|
@ -11,6 +11,7 @@
|
|||
|
||||
### Updated
|
||||
- Updated MediaStorageService, fix remote avatar bug. ([1c20d696](https://github.com/pixelfed/pixelfed/commit/1c20d696))
|
||||
- Updated WebfingerService. Fixes #3167. ([aff74566](https://github.com/pixelfed/pixelfed/commit/aff74566))
|
||||
|
||||
## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2)
|
||||
|
||||
|
|
|
@ -4,14 +4,10 @@ namespace App\Services;
|
|||
|
||||
use Cache;
|
||||
use App\Profile;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Util\Webfinger\WebfingerUrl;
|
||||
use Zttp\Zttp;
|
||||
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,25 +19,41 @@ 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 = Zttp::get($url);
|
||||
$webfinger = $res->json();
|
||||
if(!isset($webfinger['links'])) {
|
||||
|
||||
$res = Http::retry(3, 100)
|
||||
->acceptJson()
|
||||
->withHeaders([
|
||||
'User-Agent' => '(Pixelfed/' . config('pixelfed.version') . '; +' . config('app.url') . ')'
|
||||
])
|
||||
->timeout(20)
|
||||
->get($url);
|
||||
|
||||
if(!$res->successful()) {
|
||||
return [];
|
||||
}
|
||||
$profile = Helpers::profileFetch($webfinger['links'][0]['href']);
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
||||
$res = $fractal->createData($resource)->toArray();
|
||||
return $res;
|
||||
|
||||
$webfinger = $res->json();
|
||||
if(!isset($webfinger['links']) || !is_array($webfinger['links']) || empty($webfinger['links'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$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);
|
||||
return AccountService::get($profile->id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue