Merge pull request #1374 from pixelfed/frontend-ui-refactor

Move federation configuration into its own file
This commit is contained in:
daniel 2019-06-09 17:53:24 -06:00 committed by GitHub
commit 4281064fab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 83 additions and 41 deletions

View file

@ -39,8 +39,8 @@ class ApiController extends BaseApiController
],
'activitypub' => [
'enabled' => config('pixelfed.activitypub_enabled'),
'remote_follow' => config('pixelfed.remote_follow_enabled')
'enabled' => config('federation.activitypub.enabled'),
'remote_follow' => config('federation.activitypub.remoteFollow')
],
'ab' => [

View file

@ -26,9 +26,7 @@ class FederationController extends Controller
{
public function authCheck()
{
if (!Auth::check()) {
return abort(403);
}
abort_if(!Auth::check(), 403);
}
public function authorizeFollow(Request $request)
@ -52,14 +50,14 @@ class FederationController extends Controller
public function remoteFollowStore(Request $request)
{
return;
$this->authCheck();
$this->validate($request, [
'url' => 'required|string',
]);
if (config('pixelfed.remote_follow_enabled') !== true) {
abort(403);
}
abort_if(!config('federation.activitypub.remoteFollow'), 403);
$follower = Auth::user()->profile;
$url = $request->input('url');
@ -76,6 +74,8 @@ class FederationController extends Controller
public function nodeinfoWellKnown()
{
abort_if(!config('federation.nodeinfo.enabled'), 404);
$res = [
'links' => [
[
@ -90,6 +90,8 @@ class FederationController extends Controller
public function nodeinfo()
{
abort_if(!config('federation.nodeinfo.enabled'), 404);
$res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () {
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() {
$count = collect([]);
@ -150,6 +152,8 @@ class FederationController extends Controller
public function webfinger(Request $request)
{
abort_if(!config('federation.webfinger.enabled'), 404);
$this->validate($request, ['resource'=>'required|string|min:3|max:255']);
$resource = $request->input('resource');
@ -167,22 +171,18 @@ class FederationController extends Controller
public function hostMeta(Request $request)
{
abort_if(!config('federation.webfinger.enabled'), 404);
$path = route('well-known.webfinger');
$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;
$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>';
return response($xml)->header('Content-Type', 'application/xrd+xml');
}
public function userOutbox(Request $request, $username)
{
if (config('pixelfed.activitypub_enabled') == false) {
abort(403);
}
abort_if(!config('federation.activitypub.enabled'), 404);
abort_if(!config('federation.activitypub.outbox'), 404);
$profile = Profile::whereNull('remote_url')->whereUsername($username)->firstOrFail();
if($profile->status != null) {
@ -201,9 +201,8 @@ XML;
public function userInbox(Request $request, $username)
{
if (config('pixelfed.activitypub_enabled') == false) {
abort(403);
}
abort_if(!config('federation.activitypub.enabled'), 404);
abort_if(!config('federation.activitypub.inbox'), 404);
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
if($profile->status != null) {
@ -300,15 +299,14 @@ XML;
public function userFollowing(Request $request, $username)
{
if (config('pixelfed.activitypub_enabled') == false) {
abort(403);
}
abort_if(!config('federation.activitypub.enabled'), 404);
$profile = Profile::whereNull('remote_url')
->whereUsername($username)
->whereIsPrivate(false)
->firstOrFail();
if($profile->status != null) {
return ProfileController::accountCheck($profile);
return [];
}
$obj = [
'@context' => 'https://www.w3.org/ns/activitystreams',
@ -324,15 +322,14 @@ XML;
public function userFollowers(Request $request, $username)
{
if (config('pixelfed.activitypub_enabled') == false) {
abort(403);
}
abort_if(!config('federation.activitypub.enabled'), 404);
$profile = Profile::whereNull('remote_url')
->whereUsername($username)
->whereIsPrivate(false)
->firstOrFail();
if($profile->status != null) {
return ProfileController::accountCheck($profile);
return [];
}
$obj = [
'@context' => 'https://www.w3.org/ns/activitystreams',

View file

@ -51,7 +51,7 @@ class ProfileController extends Controller
$settings = $user->user->settings;
}
if ($request->wantsJson() && config('pixelfed.activitypub_enabled')) {
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
return $this->showActivityPub($request, $user);
}
@ -90,7 +90,7 @@ class ProfileController extends Controller
$user = Profile::whereUsername($username)->firstOrFail();
$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);
}
@ -150,6 +150,8 @@ class ProfileController extends Controller
public function showActivityPub(Request $request, $user)
{
abort_if(!config('federation.activitypub.enabled'), 404);
if($user->status != null) {
return ProfileController::accountCheck($user);
}
@ -161,6 +163,8 @@ class ProfileController extends Controller
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();
if($profile->status != null) {
return $this->accountCheck($profile);

View file

@ -36,7 +36,7 @@ class SearchController extends Controller
$hash = hash('sha256', $tag);
$tokens = Cache::remember('api:search:tag:'.$hash, now()->addMinutes(5), function () use ($tag) {
$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);
if(isset($remote['type']) && in_array($remote['type'], ['Create', 'Person']) == true) {
$type = $remote['type'];

View file

@ -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);
}

View file

@ -71,7 +71,7 @@ class StatusActivityPubDeliver implements ShouldQueue
$payload = json_encode($activity);
$client = new Client([
'timeout' => config('pixelfed.ap_delivery_timeout')
'timeout' => config('federation.activitypub.delivery.timeout')
]);
$requests = function($audience) use ($client, $activity, $profile, $payload) {
@ -90,7 +90,7 @@ class StatusActivityPubDeliver implements ShouldQueue
};
$pool = new Pool($client, $requests($audience), [
'concurrency' => config('pixelfed.ap_delivery_concurrency'),
'concurrency' => config('federation.activitypub.delivery.concurrency'),
'fulfilled' => function ($response, $index) {
},
'rejected' => function ($reason, $index) {

View file

@ -55,7 +55,7 @@ class StatusDelete implements ShouldQueue
{
$status = $this->status;
if(config('pixelfed.activitypub_enabled') == true) {
if(config('federation.activitypub.enabled') == true) {
$this->fanoutDelete($status);
} else {
$this->unlinkRemoveMedia($status);
@ -125,7 +125,7 @@ class StatusDelete implements ShouldQueue
$payload = json_encode($activity);
$client = new Client([
'timeout' => config('pixelfed.ap_delivery_timeout')
'timeout' => config('federation.activitypub.delivery.timeout')
]);
$requests = function($audience) use ($client, $activity, $profile, $payload) {
@ -144,7 +144,7 @@ class StatusDelete implements ShouldQueue
};
$pool = new Pool($client, $requests($audience), [
'concurrency' => config('pixelfed.ap_delivery_concurrency'),
'concurrency' => config('federation.activitypub.delivery.concurrency'),
'fulfilled' => function ($response, $index) {
},
'rejected' => function ($reason, $index) {

View file

@ -112,7 +112,7 @@ class StatusEntityLexer implements ShouldQueue
$status = $this->status;
foreach ($mentions as $mention) {
$mentioned = Profile::whereNull('domain')->whereUsername($mention)->firstOrFail();
$mentioned = Profile::whereUsername($mention)->first();
if (empty($mentioned) || !isset($mentioned->id)) {
continue;
@ -132,7 +132,7 @@ class StatusEntityLexer implements ShouldQueue
public function deliver()
{
if(config('pixelfed.activitypub_enabled') == true) {
if(config('federation.activitypub.enabled') == true) {
StatusActivityPubDeliver::dispatch($this->status);
}
}

View file

@ -357,6 +357,7 @@ class Helpers {
$fdata = new File($file);
$path = Storage::putFile($storagePath, $fdata, 'public');
$media = new Media();
$media->remote_media = true;
$media->status_id = $status->id;
$media->profile_id = $status->profile_id;
$media->user_id = null;

40
config/federation.php Normal file
View 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)
],
];

View file

@ -28,9 +28,9 @@
<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="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">
{{config('pixelfed.activitypub_enabled') === true ? 'Enabled' : 'Disabled' }}
{{config('federation.activitypub.enabled') === true ? 'Enabled' : 'Disabled' }}
</label>
<p class="text-muted small help-text font-weight-bold">Enable for federation support.</p>
</div>