mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-23 21:43:17 +00:00
Merge pull request #1374 from pixelfed/frontend-ui-refactor
Move federation configuration into its own file
This commit is contained in:
commit
4281064fab
11 changed files with 83 additions and 41 deletions
|
@ -39,8 +39,8 @@ class ApiController extends BaseApiController
|
||||||
],
|
],
|
||||||
|
|
||||||
'activitypub' => [
|
'activitypub' => [
|
||||||
'enabled' => config('pixelfed.activitypub_enabled'),
|
'enabled' => config('federation.activitypub.enabled'),
|
||||||
'remote_follow' => config('pixelfed.remote_follow_enabled')
|
'remote_follow' => config('federation.activitypub.remoteFollow')
|
||||||
],
|
],
|
||||||
|
|
||||||
'ab' => [
|
'ab' => [
|
||||||
|
|
|
@ -26,9 +26,7 @@ class FederationController extends Controller
|
||||||
{
|
{
|
||||||
public function authCheck()
|
public function authCheck()
|
||||||
{
|
{
|
||||||
if (!Auth::check()) {
|
abort_if(!Auth::check(), 403);
|
||||||
return abort(403);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authorizeFollow(Request $request)
|
public function authorizeFollow(Request $request)
|
||||||
|
@ -52,14 +50,14 @@ class FederationController extends Controller
|
||||||
|
|
||||||
public function remoteFollowStore(Request $request)
|
public function remoteFollowStore(Request $request)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
|
||||||
$this->authCheck();
|
$this->authCheck();
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'url' => 'required|string',
|
'url' => 'required|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (config('pixelfed.remote_follow_enabled') !== true) {
|
abort_if(!config('federation.activitypub.remoteFollow'), 403);
|
||||||
abort(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
$follower = Auth::user()->profile;
|
$follower = Auth::user()->profile;
|
||||||
$url = $request->input('url');
|
$url = $request->input('url');
|
||||||
|
@ -76,6 +74,8 @@ class FederationController extends Controller
|
||||||
|
|
||||||
public function nodeinfoWellKnown()
|
public function nodeinfoWellKnown()
|
||||||
{
|
{
|
||||||
|
abort_if(!config('federation.nodeinfo.enabled'), 404);
|
||||||
|
|
||||||
$res = [
|
$res = [
|
||||||
'links' => [
|
'links' => [
|
||||||
[
|
[
|
||||||
|
@ -90,6 +90,8 @@ class FederationController extends Controller
|
||||||
|
|
||||||
public function nodeinfo()
|
public function nodeinfo()
|
||||||
{
|
{
|
||||||
|
abort_if(!config('federation.nodeinfo.enabled'), 404);
|
||||||
|
|
||||||
$res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () {
|
$res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () {
|
||||||
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() {
|
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() {
|
||||||
$count = collect([]);
|
$count = collect([]);
|
||||||
|
@ -150,6 +152,8 @@ class FederationController extends Controller
|
||||||
|
|
||||||
public function webfinger(Request $request)
|
public function webfinger(Request $request)
|
||||||
{
|
{
|
||||||
|
abort_if(!config('federation.webfinger.enabled'), 404);
|
||||||
|
|
||||||
$this->validate($request, ['resource'=>'required|string|min:3|max:255']);
|
$this->validate($request, ['resource'=>'required|string|min:3|max:255']);
|
||||||
|
|
||||||
$resource = $request->input('resource');
|
$resource = $request->input('resource');
|
||||||
|
@ -167,22 +171,18 @@ class FederationController extends Controller
|
||||||
|
|
||||||
public function hostMeta(Request $request)
|
public function hostMeta(Request $request)
|
||||||
{
|
{
|
||||||
|
abort_if(!config('federation.webfinger.enabled'), 404);
|
||||||
|
|
||||||
$path = route('well-known.webfinger');
|
$path = route('well-known.webfinger');
|
||||||
$xml = <<<XML
|
$xml = '<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" type="application/xrd+xml" template="{$path}?resource={uri}"/></XRD>';
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
|
||||||
<Link rel="lrdd" type="application/xrd+xml" template="{$path}?resource={uri}"/>
|
|
||||||
</XRD>
|
|
||||||
XML;
|
|
||||||
|
|
||||||
return response($xml)->header('Content-Type', 'application/xrd+xml');
|
return response($xml)->header('Content-Type', 'application/xrd+xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function userOutbox(Request $request, $username)
|
public function userOutbox(Request $request, $username)
|
||||||
{
|
{
|
||||||
if (config('pixelfed.activitypub_enabled') == false) {
|
abort_if(!config('federation.activitypub.enabled'), 404);
|
||||||
abort(403);
|
abort_if(!config('federation.activitypub.outbox'), 404);
|
||||||
}
|
|
||||||
|
|
||||||
$profile = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail();
|
$profile = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail();
|
||||||
if($profile->status != null) {
|
if($profile->status != null) {
|
||||||
|
@ -201,9 +201,8 @@ XML;
|
||||||
|
|
||||||
public function userInbox(Request $request, $username)
|
public function userInbox(Request $request, $username)
|
||||||
{
|
{
|
||||||
if (config('pixelfed.activitypub_enabled') == false) {
|
abort_if(!config('federation.activitypub.enabled'), 404);
|
||||||
abort(403);
|
abort_if(!config('federation.activitypub.inbox'), 404);
|
||||||
}
|
|
||||||
|
|
||||||
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||||
if($profile->status != null) {
|
if($profile->status != null) {
|
||||||
|
@ -300,15 +299,14 @@ XML;
|
||||||
|
|
||||||
public function userFollowing(Request $request, $username)
|
public function userFollowing(Request $request, $username)
|
||||||
{
|
{
|
||||||
if (config('pixelfed.activitypub_enabled') == false) {
|
abort_if(!config('federation.activitypub.enabled'), 404);
|
||||||
abort(403);
|
|
||||||
}
|
|
||||||
$profile = Profile::whereNull('remote_url')
|
$profile = Profile::whereNull('remote_url')
|
||||||
->whereUsername($username)
|
->whereUsername($username)
|
||||||
->whereIsPrivate(false)
|
->whereIsPrivate(false)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
if($profile->status != null) {
|
if($profile->status != null) {
|
||||||
return ProfileController::accountCheck($profile);
|
return [];
|
||||||
}
|
}
|
||||||
$obj = [
|
$obj = [
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
|
@ -324,15 +322,14 @@ XML;
|
||||||
|
|
||||||
public function userFollowers(Request $request, $username)
|
public function userFollowers(Request $request, $username)
|
||||||
{
|
{
|
||||||
if (config('pixelfed.activitypub_enabled') == false) {
|
abort_if(!config('federation.activitypub.enabled'), 404);
|
||||||
abort(403);
|
|
||||||
}
|
|
||||||
$profile = Profile::whereNull('remote_url')
|
$profile = Profile::whereNull('remote_url')
|
||||||
->whereUsername($username)
|
->whereUsername($username)
|
||||||
->whereIsPrivate(false)
|
->whereIsPrivate(false)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
if($profile->status != null) {
|
if($profile->status != null) {
|
||||||
return ProfileController::accountCheck($profile);
|
return [];
|
||||||
}
|
}
|
||||||
$obj = [
|
$obj = [
|
||||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||||
|
|
|
@ -51,7 +51,7 @@ class ProfileController extends Controller
|
||||||
$settings = $user->user->settings;
|
$settings = $user->user->settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) {
|
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
|
||||||
return $this->showActivityPub($request, $user);
|
return $this->showActivityPub($request, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class ProfileController extends Controller
|
||||||
$user = Profile::whereUsername($username)->firstOrFail();
|
$user = Profile::whereUsername($username)->firstOrFail();
|
||||||
$settings = User::whereUsername($username)->firstOrFail()->settings;
|
$settings = User::whereUsername($username)->firstOrFail()->settings;
|
||||||
|
|
||||||
if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) {
|
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
|
||||||
return $this->showActivityPub($request, $user);
|
return $this->showActivityPub($request, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +150,8 @@ class ProfileController extends Controller
|
||||||
|
|
||||||
public function showActivityPub(Request $request, $user)
|
public function showActivityPub(Request $request, $user)
|
||||||
{
|
{
|
||||||
|
abort_if(!config('federation.activitypub.enabled'), 404);
|
||||||
|
|
||||||
if($user->status != null) {
|
if($user->status != null) {
|
||||||
return ProfileController::accountCheck($user);
|
return ProfileController::accountCheck($user);
|
||||||
}
|
}
|
||||||
|
@ -161,6 +163,8 @@ class ProfileController extends Controller
|
||||||
|
|
||||||
public function showAtomFeed(Request $request, $user)
|
public function showAtomFeed(Request $request, $user)
|
||||||
{
|
{
|
||||||
|
abort_if(!config('federation.atom.enabled'), 404);
|
||||||
|
|
||||||
$profile = $user = Profile::whereNull('status')->whereNull('domain')->whereUsername($user)->whereIsPrivate(false)->firstOrFail();
|
$profile = $user = Profile::whereNull('status')->whereNull('domain')->whereUsername($user)->whereIsPrivate(false)->firstOrFail();
|
||||||
if($profile->status != null) {
|
if($profile->status != null) {
|
||||||
return $this->accountCheck($profile);
|
return $this->accountCheck($profile);
|
||||||
|
|
|
@ -36,7 +36,7 @@ class SearchController extends Controller
|
||||||
$hash = hash('sha256', $tag);
|
$hash = hash('sha256', $tag);
|
||||||
$tokens = Cache::remember('api:search:tag:'.$hash, now()->addMinutes(5), function () use ($tag) {
|
$tokens = Cache::remember('api:search:tag:'.$hash, now()->addMinutes(5), function () use ($tag) {
|
||||||
$tokens = [];
|
$tokens = [];
|
||||||
if(Helpers::validateUrl($tag) != false && config('pixelfed.activitypub_enabled') == true && config('pixelfed.remote_follow_enabled') == true) {
|
if(Helpers::validateUrl($tag) != false && config('federation.activitypub.enabled') == true && config('federation.activitypub.remoteFollow') == true) {
|
||||||
$remote = Helpers::fetchFromUrl($tag);
|
$remote = Helpers::fetchFromUrl($tag);
|
||||||
if(isset($remote['type']) && in_array($remote['type'], ['Create', 'Person']) == true) {
|
if(isset($remote['type']) && in_array($remote['type'], ['Create', 'Person']) == true) {
|
||||||
$type = $remote['type'];
|
$type = $remote['type'];
|
||||||
|
|
|
@ -51,7 +51,7 @@ class StatusController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) {
|
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
|
||||||
return $this->showActivityPub($request, $status);
|
return $this->showActivityPub($request, $status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class StatusActivityPubDeliver implements ShouldQueue
|
||||||
$payload = json_encode($activity);
|
$payload = json_encode($activity);
|
||||||
|
|
||||||
$client = new Client([
|
$client = new Client([
|
||||||
'timeout' => config('pixelfed.ap_delivery_timeout')
|
'timeout' => config('federation.activitypub.delivery.timeout')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$requests = function($audience) use ($client, $activity, $profile, $payload) {
|
$requests = function($audience) use ($client, $activity, $profile, $payload) {
|
||||||
|
@ -90,7 +90,7 @@ class StatusActivityPubDeliver implements ShouldQueue
|
||||||
};
|
};
|
||||||
|
|
||||||
$pool = new Pool($client, $requests($audience), [
|
$pool = new Pool($client, $requests($audience), [
|
||||||
'concurrency' => config('pixelfed.ap_delivery_concurrency'),
|
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||||
'fulfilled' => function ($response, $index) {
|
'fulfilled' => function ($response, $index) {
|
||||||
},
|
},
|
||||||
'rejected' => function ($reason, $index) {
|
'rejected' => function ($reason, $index) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ class StatusDelete implements ShouldQueue
|
||||||
{
|
{
|
||||||
$status = $this->status;
|
$status = $this->status;
|
||||||
|
|
||||||
if(config('pixelfed.activitypub_enabled') == true) {
|
if(config('federation.activitypub.enabled') == true) {
|
||||||
$this->fanoutDelete($status);
|
$this->fanoutDelete($status);
|
||||||
} else {
|
} else {
|
||||||
$this->unlinkRemoveMedia($status);
|
$this->unlinkRemoveMedia($status);
|
||||||
|
@ -125,7 +125,7 @@ class StatusDelete implements ShouldQueue
|
||||||
$payload = json_encode($activity);
|
$payload = json_encode($activity);
|
||||||
|
|
||||||
$client = new Client([
|
$client = new Client([
|
||||||
'timeout' => config('pixelfed.ap_delivery_timeout')
|
'timeout' => config('federation.activitypub.delivery.timeout')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$requests = function($audience) use ($client, $activity, $profile, $payload) {
|
$requests = function($audience) use ($client, $activity, $profile, $payload) {
|
||||||
|
@ -144,7 +144,7 @@ class StatusDelete implements ShouldQueue
|
||||||
};
|
};
|
||||||
|
|
||||||
$pool = new Pool($client, $requests($audience), [
|
$pool = new Pool($client, $requests($audience), [
|
||||||
'concurrency' => config('pixelfed.ap_delivery_concurrency'),
|
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||||
'fulfilled' => function ($response, $index) {
|
'fulfilled' => function ($response, $index) {
|
||||||
},
|
},
|
||||||
'rejected' => function ($reason, $index) {
|
'rejected' => function ($reason, $index) {
|
||||||
|
|
|
@ -112,7 +112,7 @@ class StatusEntityLexer implements ShouldQueue
|
||||||
$status = $this->status;
|
$status = $this->status;
|
||||||
|
|
||||||
foreach ($mentions as $mention) {
|
foreach ($mentions as $mention) {
|
||||||
$mentioned = Profile::whereNull('domain')->whereUsername($mention)->firstOrFail();
|
$mentioned = Profile::whereUsername($mention)->first();
|
||||||
|
|
||||||
if (empty($mentioned) || !isset($mentioned->id)) {
|
if (empty($mentioned) || !isset($mentioned->id)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -132,7 +132,7 @@ class StatusEntityLexer implements ShouldQueue
|
||||||
|
|
||||||
public function deliver()
|
public function deliver()
|
||||||
{
|
{
|
||||||
if(config('pixelfed.activitypub_enabled') == true) {
|
if(config('federation.activitypub.enabled') == true) {
|
||||||
StatusActivityPubDeliver::dispatch($this->status);
|
StatusActivityPubDeliver::dispatch($this->status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,6 +357,7 @@ class Helpers {
|
||||||
$fdata = new File($file);
|
$fdata = new File($file);
|
||||||
$path = Storage::putFile($storagePath, $fdata, 'public');
|
$path = Storage::putFile($storagePath, $fdata, 'public');
|
||||||
$media = new Media();
|
$media = new Media();
|
||||||
|
$media->remote_media = true;
|
||||||
$media->status_id = $status->id;
|
$media->status_id = $status->id;
|
||||||
$media->profile_id = $status->profile_id;
|
$media->profile_id = $status->profile_id;
|
||||||
$media->user_id = null;
|
$media->user_id = null;
|
||||||
|
|
40
config/federation.php
Normal file
40
config/federation.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| ActivityPub
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| ActivityPub configuration
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'activitypub' => [
|
||||||
|
'enabled' => env('ACTIVITY_PUB', false),
|
||||||
|
'outbox' => env('AP_OUTBOX', true),
|
||||||
|
'inbox' => env('AP_INBOX', true),
|
||||||
|
'sharedInbox' => env('AP_SHAREDINBOX', false),
|
||||||
|
|
||||||
|
'remoteFollow' => false,
|
||||||
|
|
||||||
|
'delivery' => [
|
||||||
|
'timeout' => env('ACTIVITYPUB_DELIVERY_TIMEOUT', 2.0),
|
||||||
|
'concurrency' => env('ACTIVITYPUB_DELIVERY_CONCURRENCY', 10)
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
'atom' => [
|
||||||
|
'enabled' => env('ATOM_FEEDS', true),
|
||||||
|
],
|
||||||
|
|
||||||
|
'nodeinfo' => [
|
||||||
|
'enabled' => env('NODEINFO', true),
|
||||||
|
],
|
||||||
|
|
||||||
|
'webfinger' => [
|
||||||
|
'enabled' => env('WEBFINGER', true)
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
|
@ -28,9 +28,9 @@
|
||||||
<label for="app_url" class="col-sm-3 col-form-label font-weight-bold text-right">ActivityPub</label>
|
<label for="app_url" class="col-sm-3 col-form-label font-weight-bold text-right">ActivityPub</label>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<div class="form-check pb-2">
|
<div class="form-check pb-2">
|
||||||
<input class="form-check-input" type="checkbox" id="activitypub_enabled" name="activitypub_enabled" {{config('pixelfed.activitypub_enabled') === true ? 'checked=""' : '' }}>
|
<input class="form-check-input" type="checkbox" id="activitypub_enabled" name="activitypub_enabled" {{config('federation.activitypub.enabled') === true ? 'checked=""' : '' }}>
|
||||||
<label class="form-check-label font-weight-bold" for="activitypub_enabled">
|
<label class="form-check-label font-weight-bold" for="activitypub_enabled">
|
||||||
{{config('pixelfed.activitypub_enabled') === true ? 'Enabled' : 'Disabled' }}
|
{{config('federation.activitypub.enabled') === true ? 'Enabled' : 'Disabled' }}
|
||||||
</label>
|
</label>
|
||||||
<p class="text-muted small help-text font-weight-bold">Enable for federation support.</p>
|
<p class="text-muted small help-text font-weight-bold">Enable for federation support.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue