diff options
| author | Daniel Friesel <derf@finalrewind.org> | 2023-01-08 09:40:49 +0100 | 
|---|---|---|
| committer | Daniel Friesel <derf@finalrewind.org> | 2023-01-08 09:40:49 +0100 | 
| commit | 7b2cd23c3998ac2c30b21c0e82ec7a7ea5ece393 (patch) | |
| tree | a0dc3fbc26dd2fe8aa4d59295ed00172c9f50cf6 /lib | |
| parent | dbd9d9951f8c087c74bb173af8017ce0ac5d8bb9 (diff) | |
add webfinger "profile-page" support (for public profiles only)
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/Travelynx.pm | 1 | ||||
| -rw-r--r-- | lib/Travelynx/Controller/Account.pm | 50 | 
2 files changed, 50 insertions, 1 deletions
| diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index db87ad6..a26fc11 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -2182,6 +2182,7 @@ sub startup {  	$r->get('/ajax/status/:name/:ts')->to('traveling#public_status_card');  	$r->get('/p/:name')->to('traveling#public_profile');  	$r->get('/p/:name/j/:id')->to('traveling#public_journey_details'); +	$r->get('/.well-known/webfinger')->to('account#webfinger');  	$r->post('/api/v1/import')->to('api#import_v1');  	$r->post('/api/v1/travel')->to('api#travel_v1');  	$r->post('/action')->to('traveling#travel_action'); diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm index 12b179b..334ec97 100644 --- a/lib/Travelynx/Controller/Account.pm +++ b/lib/Travelynx/Controller/Account.pm @@ -6,7 +6,8 @@ package Travelynx::Controller::Account;  use Mojo::Base 'Mojolicious::Controller';  use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); -use UUID::Tiny                 qw(:std); +use JSON; +use UUID::Tiny qw(:std);  # Internal Helpers @@ -967,4 +968,51 @@ sub json_export {  	);  } +sub webfinger { +	my ($self) = @_; + +	my $resource = $self->param('resource'); + +	if ( not $resource ) { +		$self->render('not_found'); +		return; +	} + +	my $root_url = $self->url_for('/')->host; + +	if (   not $root_url +		or not $resource =~ m{ ^ (?<name> [^@]+ ) [@] $root_url $ }x ) +	{ +		$self->render('not_found'); +		return; +	} + +	my $name = $+{name}; +	my $user = $self->users->get_privacy_by_name( name => $name ); + +	if ( not $user or not $user->{public_level} & 0x22 ) { +		$self->render('not_found'); +	} + +	my $profile_url +	  = $self->url_for("/p/${name}")->to_abs->scheme('https')->to_string; + +	$self->render( +		text => JSON->new->encode( +			{ +				subject => "acct:${resource}", +				aliases => [ $profile_url, ], +				links   => [ +					{ +						rel  => 'http://webfinger.net/rel/profile-page', +						type => 'text/html', +						href => $profile_url, +					}, +				], +			} +		), +		format => 'json', +	); +} +  1; | 
