mirror of https://github.com/pixelfed/pixelfed
Update FederationController
parent
9def9d0801
commit
279c57d9a5
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Util\ActivityPub;
|
||||
|
||||
use App\Profile;
|
||||
use League\Fractal;
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use App\Transformer\ActivityPub\ProfileOutbox;
|
||||
|
||||
class Outbox {
|
||||
|
||||
public static function get($username)
|
||||
{
|
||||
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) {
|
||||
return ProfileController::accountCheck($profile);
|
||||
}
|
||||
if($profile->is_private) {
|
||||
return response()->json(['error'=>'403', 'msg' => 'private profile'], 403);
|
||||
}
|
||||
$timeline = $profile->statuses()->whereVisibility('public')->orderBy('created_at', 'desc')->paginate(10);
|
||||
$fractal = new Fractal\Manager();
|
||||
$resource = new Fractal\Resource\Item($profile, new ProfileOutbox());
|
||||
$res = $fractal->createData($resource)->toArray();
|
||||
|
||||
return $res['data'];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Util\Site;
|
||||
|
||||
use Cache;
|
||||
use App\{Like, Profile, Status, User};
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Nodeinfo {
|
||||
|
||||
public static function get()
|
||||
{
|
||||
$res = Cache::remember('api:nodeinfo', now()->addMinutes(15), function () {
|
||||
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', now()->addHours(12), function() {
|
||||
$count = collect([]);
|
||||
$likes = Like::select('profile_id')->with('actor')->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('profile_id')->get()->filter(function($like) {return $like->actor && $like->actor->domain == null;})->pluck('profile_id')->toArray();
|
||||
$count = $count->merge($likes);
|
||||
$statuses = Status::select('profile_id')->whereLocal(true)->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('profile_id')->pluck('profile_id')->toArray();
|
||||
$count = $count->merge($statuses);
|
||||
$profiles = Profile::select('id')->whereNull('domain')->where('created_at', '>', now()->subMonths(6)->toDateTimeString())->groupBy('id')->pluck('id')->toArray();
|
||||
$count = $count->merge($profiles);
|
||||
return $count->unique()->count();
|
||||
});
|
||||
$activeMonth = Cache::remember('api:nodeinfo:am', now()->addHours(12), function() {
|
||||
$count = collect([]);
|
||||
$likes = Like::select('profile_id')->where('created_at', '>', now()->subMonths(1)->toDateTimeString())->groupBy('profile_id')->get()->filter(function($like) {return $like->actor && $like->actor->domain == null;})->pluck('profile_id')->toArray();
|
||||
$count = $count->merge($likes);
|
||||
$statuses = Status::select('profile_id')->whereLocal(true)->where('created_at', '>', now()->subMonths(1)->toDateTimeString())->groupBy('profile_id')->pluck('profile_id')->toArray();
|
||||
$count = $count->merge($statuses);
|
||||
$profiles = Profile::select('id')->whereNull('domain')->where('created_at', '>', now()->subMonths(1)->toDateTimeString())->groupBy('id')->pluck('id')->toArray();
|
||||
$count = $count->merge($profiles);
|
||||
return $count->unique()->count();
|
||||
});
|
||||
return [
|
||||
'metadata' => [
|
||||
'nodeName' => config('pixelfed.domain.app'),
|
||||
'software' => [
|
||||
'homepage' => 'https://pixelfed.org',
|
||||
'repo' => 'https://github.com/pixelfed/pixelfed',
|
||||
],
|
||||
'config' => \App\Util\Site\Config::get()
|
||||
],
|
||||
'protocols' => [
|
||||
'activitypub',
|
||||
],
|
||||
'services' => [
|
||||
'inbound' => [],
|
||||
'outbound' => [],
|
||||
],
|
||||
'software' => [
|
||||
'name' => 'pixelfed',
|
||||
'version' => config('pixelfed.version'),
|
||||
],
|
||||
'usage' => [
|
||||
'localPosts' => Status::whereLocal(true)->count(),
|
||||
'localComments' => 0,
|
||||
'users' => [
|
||||
'total' => User::count(),
|
||||
'activeHalfyear' => (int) $activeHalfYear,
|
||||
'activeMonth' => (int) $activeMonth,
|
||||
],
|
||||
],
|
||||
'version' => '2.0',
|
||||
];
|
||||
});
|
||||
$res['openRegistrations'] = config('pixelfed.open_registration');
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function wellKnown()
|
||||
{
|
||||
return [
|
||||
'links' => [
|
||||
[
|
||||
'href' => config('pixelfed.nodeinfo.url'),
|
||||
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue