1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Util/Site/Nodeinfo.php

100 lines
3.2 KiB
PHP
Raw Normal View History

2019-12-21 06:15:15 +00:00
<?php
namespace App\Util\Site;
2023-10-13 03:29:51 +00:00
use Illuminate\Support\Facades\Cache;
use App\Like;
use App\Profile;
use App\Status;
use App\User;
2019-12-21 06:15:15 +00:00
use Illuminate\Support\Str;
2023-10-13 03:29:51 +00:00
class Nodeinfo
{
public static function get()
{
$res = Cache::remember('api:nodeinfo', 900, function () {
$activeHalfYear = self::activeUsersHalfYear();
$activeMonth = self::activeUsersMonthly();
2019-12-21 06:15:15 +00:00
2023-10-13 03:29:51 +00:00
$users = Cache::remember('api:nodeinfo:users', 43200, function() {
return User::count();
});
2023-10-13 03:29:51 +00:00
$statuses = Cache::remember('api:nodeinfo:statuses', 21600, function() {
return Status::whereLocal(true)->count();
});
2023-10-13 03:29:51 +00:00
$features = [ 'features' => \App\Util\Site\Config::get()['features'] ];
2023-10-13 03:29:51 +00:00
return [
'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;
}
2023-10-13 03:29:51 +00:00
public static function wellKnown()
{
return [
'links' => [
[
'href' => config('pixelfed.nodeinfo.url'),
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
],
],
];
}
2022-04-06 04:12:13 +00:00
2023-10-13 03:29:51 +00:00
public static function activeUsersMonthly()
{
return Cache::remember('api:nodeinfo:active-users-monthly', 43200, function() {
return User::withTrashed()
->select('last_active_at, updated_at')
->where('updated_at', '>', now()->subWeeks(5))
->orWhere('last_active_at', '>', now()->subWeeks(5))
->count();
});
}
2019-12-21 06:15:15 +00:00
2023-10-13 03:29:51 +00:00
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();
});
}
2021-05-08 03:47:51 +00:00
}