Bläddra i källkod

Update web routes for AP actor object

Daniel Supernault 7 år sedan
förälder
incheckning
0462b0a364
2 ändrade filer med 18 tillägg och 3 borttagningar
  1. 17 0
      app/Http/Controllers/ProfileController.php
  2. 1 3
      routes/web.php

+ 17 - 0
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) {

+ 1 - 3
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');