mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-30 10:13:16 +00:00
commit
9f9a52b683
2 changed files with 33 additions and 20 deletions
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
- Updated MediaStorageService, fix remote avatar bug. ([1c20d696](https://github.com/pixelfed/pixelfed/commit/1c20d696))
|
- 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)
|
## [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 Cache;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
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\Services\AccountService;
|
||||||
use League\Fractal;
|
|
||||||
use League\Fractal\Serializer\ArraySerializer;
|
|
||||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
||||||
|
|
||||||
class WebfingerService
|
class WebfingerService
|
||||||
{
|
{
|
||||||
|
@ -23,25 +19,41 @@ 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 = Zttp::get($url);
|
|
||||||
$webfinger = $res->json();
|
$res = Http::retry(3, 100)
|
||||||
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']);
|
|
||||||
$fractal = new Fractal\Manager();
|
$webfinger = $res->json();
|
||||||
$fractal->setSerializer(new ArraySerializer());
|
if(!isset($webfinger['links']) || !is_array($webfinger['links']) || empty($webfinger['links'])) {
|
||||||
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
return [];
|
||||||
$res = $fractal->createData($resource)->toArray();
|
}
|
||||||
return $res;
|
|
||||||
|
$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 a new issue