From 0462b0a3646065c98dcada80f020bb1de3181f95 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 13 Aug 2018 18:10:47 -0600 Subject: [PATCH 1/3] Update web routes for AP actor object --- app/Http/Controllers/ProfileController.php | 17 +++++++++++++++++ routes/web.php | 4 +--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index f56d65880..dbe31588a 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -48,6 +48,23 @@ class ProfileController extends Controller return view('profile.show', compact('user', 'settings', 'owner', 'is_following', 'is_admin', 'timeline')); } + public function permalinkRedirect(Request $request, $username) + { + $user = Profile::whereUsername($username)->firstOrFail(); + $settings = User::whereUsername($username)->firstOrFail()->settings; + + $mimes = [ + 'application/activity+json', + 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' + ]; + + if(in_array($request->header('accept'), $mimes) && config('pixelfed.activitypub_enabled')) { + return $this->showActivityPub($request, $user); + } + + return redirect($user->url()); + } + protected function privateProfileCheck(Profile $profile) { if(Auth::check() === false) { diff --git a/routes/web.php b/routes/web.php index 53f34cc70..41625e378 100644 --- a/routes/web.php +++ b/routes/web.php @@ -123,9 +123,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware('validemail')->group(fu Route::redirect('/', '/'); Route::get('{user}.atom', 'ProfileController@showAtomFeed'); Route::get('{username}/outbox', 'FederationController@userOutbox'); - Route::get('{user}', function($user) { - return redirect('/'.$user); - }); + Route::get('{username}', 'ProfileController@permalinkRedirect'); }); Route::get('p/{username}/{id}/c/{cid}', 'CommentController@show'); From 985938b6621d0920bbea4de9cc9464782b5d9e04 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 13 Aug 2018 18:17:50 -0600 Subject: [PATCH 2/3] Update AP ProfileOutbox transformer --- app/Transformer/ActivityPub/ProfileOutbox.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Transformer/ActivityPub/ProfileOutbox.php b/app/Transformer/ActivityPub/ProfileOutbox.php index 9d3b487cb..6a0e7cacc 100644 --- a/app/Transformer/ActivityPub/ProfileOutbox.php +++ b/app/Transformer/ActivityPub/ProfileOutbox.php @@ -13,7 +13,7 @@ class ProfileOutbox extends Fractal\TransformerAbstract $count = $profile->statuses()->count(); $statuses = $profile->statuses()->has('media')->orderBy('id','desc')->take(20)->get()->map(function($i, $k) { $item = [ - 'id' => $i->url(), + 'id' => $i->permalink(), // TODO: handle other types 'type' => 'Create', 'actor' => $i->profile->url(), @@ -47,7 +47,7 @@ class ProfileOutbox extends Fractal\TransformerAbstract // TODO: add cc's //"{$notice->getProfile()->getUrl()}/subscribers", ], - 'sensitive' => null, + 'sensitive' => (bool) $i->is_nsfw, 'atomUri' => $i->url(), 'inReplyToAtomUri' => null, 'conversation' => $i->url(), From 7f789ad5083314394516e427fb2f826eed281809 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 13 Aug 2018 18:18:20 -0600 Subject: [PATCH 3/3] Update AP ProfileTransformer --- .../ActivityPub/ProfileTransformer.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Transformer/ActivityPub/ProfileTransformer.php b/app/Transformer/ActivityPub/ProfileTransformer.php index f3b1b84b9..286a74b41 100644 --- a/app/Transformer/ActivityPub/ProfileTransformer.php +++ b/app/Transformer/ActivityPub/ProfileTransformer.php @@ -11,7 +11,14 @@ class ProfileTransformer extends Fractal\TransformerAbstract public function transform(Profile $profile) { return [ - '@context' => 'https://www.w3.org/ns/activitystreams', + '@context' => [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1', + [ + "manuallyApprovesFollowers" => "as:manuallyApprovesFollowers", + "featured" => 'https://pixelfed.org/ns/featured', + ] + ], 'id' => $profile->permalink(), 'type' => 'Person', 'following' => $profile->permalink('/following'), @@ -23,9 +30,9 @@ class ProfileTransformer extends Fractal\TransformerAbstract 'name' => $profile->name, 'summary' => $profile->bio, 'url' => $profile->url(), - 'manuallyApprovesFollowers' => $profile->is_private, - 'follower_count' => $profile->followers()->count(), - 'following_count' => $profile->following()->count(), + 'manuallyApprovesFollowers' => (bool) $profile->is_private, + // 'follower_count' => $profile->followers()->count(), + // 'following_count' => $profile->following()->count(), 'publicKey' => [ 'id' => $profile->permalink() . '#main-key', 'owner' => $profile->permalink(),