Update nodeinfo

pull/4699/head
Daniel Supernault 2023-10-12 21:29:51 -06:00
rodzic b76ad7cfe0
commit 36df0d8373
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 23740873EE6F76A1
3 zmienionych plików z 89 dodań i 84 usunięć

Wyświetl plik

@ -34,6 +34,7 @@ use App\Transformer\Api\Mastodon\v1\{
use App\Transformer\Api\{ use App\Transformer\Api\{
RelationshipTransformer, RelationshipTransformer,
}; };
use App\Util\Site\Nodeinfo;
class ApiV2Controller extends Controller class ApiV2Controller extends Controller
{ {
@ -77,12 +78,7 @@ class ApiV2Controller extends Controller
'description' => config_cache('app.short_description'), 'description' => config_cache('app.short_description'),
'usage' => [ 'usage' => [
'users' => [ 'users' => [
'active_month' => (int) Cache::remember('api:nodeinfo:am', 172800, function() { 'active_month' => (int) Nodeinfo::activeUsersMonthly()
return User::select('last_active_at', 'created_at')
->where('last_active_at', '>', now()->subMonths(1))
->orWhere('created_at', '>', now()->subMonths(1))
->count();
})
] ]
], ],
'thumbnail' => [ 'thumbnail' => [

Wyświetl plik

@ -9,17 +9,13 @@ use Illuminate\Support\Facades\Redis;
use App\Status; use App\Status;
use App\User; use App\User;
use App\Services\AccountService; use App\Services\AccountService;
use App\Util\Site\Nodeinfo;
class LandingService class LandingService
{ {
public static function get($json = true) public static function get($json = true)
{ {
$activeMonth = Cache::remember('api:nodeinfo:am', 172800, function() { $activeMonth = Nodeinfo::activeUsersMonthly();
return User::select('last_active_at')
->where('last_active_at', '>', now()->subMonths(1))
->orWhere('created_at', '>', now()->subMonths(1))
->count();
});
$totalUsers = Cache::remember('api:nodeinfo:users', 43200, function() { $totalUsers = Cache::remember('api:nodeinfo:users', 43200, function() {
return User::count(); return User::count();

Wyświetl plik

@ -2,85 +2,98 @@
namespace App\Util\Site; namespace App\Util\Site;
use Cache; use Illuminate\Support\Facades\Cache;
use App\{Like, Profile, Status, User}; use App\Like;
use App\Profile;
use App\Status;
use App\User;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class Nodeinfo { class Nodeinfo
{
public static function get()
{
$res = Cache::remember('api:nodeinfo', 900, function () {
$activeHalfYear = self::activeUsersHalfYear();
$activeMonth = self::activeUsersMonthly();
public static function get() $users = Cache::remember('api:nodeinfo:users', 43200, function() {
{ return User::count();
$res = Cache::remember('api:nodeinfo', 300, function () { });
$activeHalfYear = Cache::remember('api:nodeinfo:ahy', 172800, function() {
return User::select('last_active_at')
->where('last_active_at', '>', now()->subMonths(6))
->orWhere('created_at', '>', now()->subMonths(6))
->count();
});
$activeMonth = Cache::remember('api:nodeinfo:am', 172800, function() { $statuses = Cache::remember('api:nodeinfo:statuses', 21600, function() {
return User::select('last_active_at') return Status::whereLocal(true)->count();
->where('last_active_at', '>', now()->subMonths(1)) });
->orWhere('created_at', '>', now()->subMonths(1))
->count();
});
$users = Cache::remember('api:nodeinfo:users', 43200, function() { $features = [ 'features' => \App\Util\Site\Config::get()['features'] ];
return User::count();
});
$statuses = Cache::remember('api:nodeinfo:statuses', 21600, function() { return [
return Status::whereLocal(true)->count(); 'metadata' => [
}); 'nodeName' => config_cache('app.name'),
'software' => [
'homepage' => 'https://pixelfed.org',
'repo' => 'https://github.com/pixelfed/pixelfed',
],
'config' => $features
],
'protocols' => [
'activitypub',
],
'services' => [
'inbound' => [],
'outbound' => [],
],
'software' => [
'name' => 'pixelfed',
'version' => config('pixelfed.version'),
],
'usage' => [
'localPosts' => (int) $statuses,
'localComments' => 0,
'users' => [
'total' => (int) $users,
'activeHalfyear' => (int) $activeHalfYear,
'activeMonth' => (int) $activeMonth,
],
],
'version' => '2.0',
];
});
$res['openRegistrations'] = (bool) config_cache('pixelfed.open_registration');
return $res;
}
$features = [ 'features' => \App\Util\Site\Config::get()['features'] ]; public static function wellKnown()
{
return [
'links' => [
[
'href' => config('pixelfed.nodeinfo.url'),
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
],
],
];
}
return [ public static function activeUsersMonthly()
'metadata' => [ {
'nodeName' => config_cache('app.name'), return Cache::remember('api:nodeinfo:active-users-monthly', 43200, function() {
'software' => [ return User::withTrashed()
'homepage' => 'https://pixelfed.org', ->select('last_active_at, updated_at')
'repo' => 'https://github.com/pixelfed/pixelfed', ->where('updated_at', '>', now()->subWeeks(5))
], ->orWhere('last_active_at', '>', now()->subWeeks(5))
'config' => $features ->count();
], });
'protocols' => [ }
'activitypub',
],
'services' => [
'inbound' => [],
'outbound' => [],
],
'software' => [
'name' => 'pixelfed',
'version' => config('pixelfed.version'),
],
'usage' => [
'localPosts' => (int) $statuses,
'localComments' => 0,
'users' => [
'total' => (int) $users,
'activeHalfyear' => (int) $activeHalfYear,
'activeMonth' => (int) $activeMonth,
],
],
'version' => '2.0',
];
});
$res['openRegistrations'] = (bool) config_cache('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',
],
],
];
}
public static function activeUsersHalfYear()
{
return Cache::remember('api:nodeinfo:active-users-half-year', 43200, function() {
return User::withTrashed()
->select('last_active_at, updated_at')
->where('last_active_at', '>', now()->subMonths(6))
->orWhere('updated_at', '>', now()->subMonths(6))
->count();
});
}
} }