mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update Webfinger util, add avatar entity. Fixes #1629
This commit is contained in:
parent
5f5cb0616d
commit
bca2484994
1 changed files with 54 additions and 37 deletions
|
@ -4,43 +4,60 @@ namespace App\Util\Webfinger;
|
||||||
|
|
||||||
class Webfinger
|
class Webfinger
|
||||||
{
|
{
|
||||||
protected $user;
|
protected $user;
|
||||||
protected $subject;
|
protected $subject;
|
||||||
protected $aliases;
|
protected $aliases;
|
||||||
protected $links;
|
protected $links;
|
||||||
|
|
||||||
public function __construct($user)
|
public function __construct($user)
|
||||||
{
|
{
|
||||||
$this->subject = 'acct:'.$user->username.'@'.parse_url(config('app.url'), PHP_URL_HOST);
|
$avatar = $user ? $user->avatarUrl() : url('/storage/avatars/default.jpg');
|
||||||
$this->aliases = [
|
$avatarPath = parse_url($avatar, PHP_URL_PATH);
|
||||||
$user->url(),
|
$extension = pathinfo($avatarPath, PATHINFO_EXTENSION);
|
||||||
$user->permalink(),
|
$mimeTypes = [
|
||||||
];
|
'jpg' => 'image/jpeg',
|
||||||
$this->links = [
|
'jpeg' => 'image/jpeg',
|
||||||
[
|
'png' => 'image/png',
|
||||||
'rel' => 'http://webfinger.net/rel/profile-page',
|
'gif' => 'image/gif',
|
||||||
'type' => 'text/html',
|
'svg' => 'image/svg',
|
||||||
'href' => $user->url(),
|
];
|
||||||
],
|
$avatarType = $mimeTypes[$extension] ?? 'application/octet-stream';
|
||||||
[
|
|
||||||
'rel' => 'http://schemas.google.com/g/2010#updates-from',
|
|
||||||
'type' => 'application/atom+xml',
|
|
||||||
'href' => $user->permalink('.atom'),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'rel' => 'self',
|
|
||||||
'type' => 'application/activity+json',
|
|
||||||
'href' => $user->permalink(),
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function generate()
|
$this->subject = 'acct:'.$user->username.'@'.parse_url(config('app.url'), PHP_URL_HOST);
|
||||||
{
|
$this->aliases = [
|
||||||
return [
|
$user->url(),
|
||||||
'subject' => $this->subject,
|
$user->permalink(),
|
||||||
'aliases' => $this->aliases,
|
];
|
||||||
'links' => $this->links,
|
$this->links = [
|
||||||
];
|
[
|
||||||
}
|
'rel' => 'http://webfinger.net/rel/profile-page',
|
||||||
|
'type' => 'text/html',
|
||||||
|
'href' => $user->url(),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rel' => 'http://schemas.google.com/g/2010#updates-from',
|
||||||
|
'type' => 'application/atom+xml',
|
||||||
|
'href' => $user->permalink('.atom'),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rel' => 'self',
|
||||||
|
'type' => 'application/activity+json',
|
||||||
|
'href' => $user->permalink(),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'rel' => 'http://webfinger.net/rel/avatar',
|
||||||
|
'type' => $avatarType,
|
||||||
|
'href' => $avatar,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generate()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'subject' => $this->subject,
|
||||||
|
'aliases' => $this->aliases,
|
||||||
|
'links' => $this->links,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue