pixelfed/app/Util/Site/Nodeinfo.php

96 lines
3 KiB
PHP
Raw Permalink Normal View History

2019-12-21 06:15:15 +00:00
<?php
namespace App\Util\Site;
use App\Services\InstanceService;
2023-10-13 03:29:51 +00:00
use App\User;
use Illuminate\Support\Facades\Cache;
2019-12-21 06:15:15 +00:00
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
$users = Cache::remember('api:nodeinfo:users', 43200, function () {
2023-10-13 03:29:51 +00:00
return User::count();
});
$statuses = InstanceService::totalLocalStatuses();
$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',
2023-10-13 03:29:51 +00:00
],
'config' => $features,
2023-10-13 03:29:51 +00:00
],
'protocols' => [
2023-10-13 03:29:51 +00:00
'activitypub',
],
'services' => [
'inbound' => [],
2023-10-13 03:29:51 +00:00
'outbound' => [],
],
'software' => [
'name' => 'pixelfed',
'version' => config('pixelfed.version'),
2023-10-13 03:29:51 +00:00
],
'usage' => [
'localPosts' => (int) $statuses,
2023-10-13 03:29:51 +00:00
'localComments' => 0,
'users' => [
'total' => (int) $users,
2023-10-13 03:29:51 +00:00
'activeHalfyear' => (int) $activeHalfYear,
'activeMonth' => (int) $activeMonth,
2023-10-13 03:29:51 +00:00
],
],
'version' => '2.0',
];
});
$res['openRegistrations'] = (bool) config_cache('pixelfed.open_registration');
2023-10-13 03:29:51 +00:00
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',
2023-10-13 03:29:51 +00:00
],
],
];
}
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 () {
2023-10-13 03:29:51 +00:00
return User::withTrashed()
->select('last_active_at, updated_at')
->where('updated_at', '>', now()->subWeeks(5))
->orWhere('last_active_at', '>', now()->subWeeks(5))
->count();
2023-10-13 03:29:51 +00:00
});
}
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 () {
2023-10-13 03:29:51 +00:00
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
}