mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-27 15:33:17 +00:00
Add WebfingerService
This commit is contained in:
parent
9aa8864d55
commit
c47fbe2d66
1 changed files with 40 additions and 0 deletions
40
app/Services/WebfingerService.php
Normal file
40
app/Services/WebfingerService.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Cache;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Util\Webfinger\WebfingerUrl;
|
||||
use Zttp\Zttp;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Transformer\Api\AccountTransformer;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
|
||||
class WebfingerService
|
||||
{
|
||||
public static function lookup($query)
|
||||
{
|
||||
return (new self)->run($query);
|
||||
}
|
||||
|
||||
protected function run($query)
|
||||
{
|
||||
$url = WebfingerUrl::generateWebfingerUrl($query);
|
||||
if(!Helpers::validateUrl($url)) {
|
||||
return [];
|
||||
}
|
||||
$res = Zttp::get($url);
|
||||
$webfinger = $res->json();
|
||||
if(!isset($webfinger['links'])) {
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue