FederationController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Auth;
  4. use App\Profile;
  5. use League\Fractal;
  6. use Illuminate\Http\Request;
  7. use App\Util\Lexer\Nickname;
  8. use App\Util\Webfinger\Webfinger;
  9. use App\Transformer\ActivityPub\{
  10. ProfileOutbox,
  11. ProfileTransformer
  12. };
  13. use App\Jobs\RemoteFollowPipeline\RemoteFollowPipeline;
  14. class FederationController extends Controller
  15. {
  16. public function authCheck()
  17. {
  18. if(!Auth::check()) {
  19. abort(403);
  20. }
  21. return;
  22. }
  23. public function remoteFollow()
  24. {
  25. $this->authCheck();
  26. return view('federation.remotefollow');
  27. }
  28. public function remoteFollowStore(Request $request)
  29. {
  30. $this->authCheck();
  31. $this->validate($request, [
  32. 'url' => 'required|string'
  33. ]);
  34. if(config('pixelfed.remote_follow_enabled') !== true) {
  35. abort(403);
  36. }
  37. $follower = Auth::user()->profile;
  38. $url = $request->input('url');
  39. RemoteFollowPipeline::dispatch($follower, $url);
  40. return redirect()->back();
  41. }
  42. public function nodeinfoWellKnown()
  43. {
  44. $res = [
  45. 'links' => [
  46. [
  47. 'href' => config('pixelfed.nodeinfo.url'),
  48. 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0'
  49. ]
  50. ]
  51. ];
  52. return response()->json($res);
  53. }
  54. public function nodeinfo()
  55. {
  56. $res = [
  57. 'metadata' => [
  58. 'nodeName' => config('app.name'),
  59. 'software' => [
  60. 'homepage' => 'https://pixelfed.org',
  61. 'github' => 'https://github.com/pixelfed',
  62. 'follow' => 'https://mastodon.social/@pixelfed'
  63. ],
  64. /*
  65. TODO: Custom Features for Trending
  66. 'customFeatures' => [
  67. 'trending' => [
  68. 'description' => 'Trending API for federated discovery',
  69. 'api' => [
  70. 'url' => null,
  71. 'docs' => null
  72. ],
  73. ],
  74. ],
  75. */
  76. ],
  77. 'openRegistrations' => config('pixelfed.open_registration'),
  78. 'protocols' => [
  79. 'activitypub'
  80. ],
  81. 'services' => [
  82. 'inbound' => [],
  83. 'outbound' => []
  84. ],
  85. 'software' => [
  86. 'name' => 'pixelfed',
  87. 'version' => config('pixelfed.version')
  88. ],
  89. 'usage' => [
  90. 'localPosts' => \App\Status::whereLocal(true)->count(),
  91. 'users' => [
  92. 'total' => \App\User::count()
  93. ]
  94. ],
  95. 'version' => '2.0'
  96. ];
  97. return response()->json($res);
  98. }
  99. public function webfinger(Request $request)
  100. {
  101. $this->validate($request, ['resource'=>'required']);
  102. $resource = $request->input('resource');
  103. $parsed = Nickname::normalizeProfileUrl($resource);
  104. $username = $parsed['username'];
  105. $user = Profile::whereUsername($username)->firstOrFail();
  106. $webfinger = (new Webfinger($user))->generate();
  107. return response()->json($webfinger);
  108. }
  109. public function userOutbox(Request $request, $username)
  110. {
  111. if(config('pixelfed.activitypub_enabled') == false) {
  112. abort(403);
  113. }
  114. $user = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail();
  115. $timeline = $user->statuses()->orderBy('created_at','desc')->paginate(10);
  116. $fractal = new Fractal\Manager();
  117. $resource = new Fractal\Resource\Item($user, new ProfileOutbox);
  118. $res = $fractal->createData($resource)->toArray();
  119. return response()->json($res['data']);
  120. }
  121. }