Nodeinfo.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Util\Site;
  3. use App\Services\InstanceService;
  4. use App\User;
  5. use Illuminate\Support\Facades\Cache;
  6. class Nodeinfo
  7. {
  8. public static function get()
  9. {
  10. $res = Cache::remember('api:nodeinfo', 900, function () {
  11. $activeHalfYear = self::activeUsersHalfYear();
  12. $activeMonth = self::activeUsersMonthly();
  13. $users = Cache::remember('api:nodeinfo:users', 43200, function () {
  14. return User::count();
  15. });
  16. $statuses = InstanceService::totalLocalStatuses();
  17. $features = ['features' => \App\Util\Site\Config::get()['features']];
  18. unset($features['features']['hls']);
  19. return [
  20. 'metadata' => [
  21. 'nodeName' => config_cache('app.name'),
  22. 'software' => [
  23. 'homepage' => 'https://pixelfed.org',
  24. 'repo' => 'https://github.com/pixelfed/pixelfed',
  25. ],
  26. 'config' => $features,
  27. ],
  28. 'protocols' => [
  29. 'activitypub',
  30. ],
  31. 'services' => [
  32. 'inbound' => [],
  33. 'outbound' => [],
  34. ],
  35. 'software' => [
  36. 'name' => 'pixelfed',
  37. 'version' => config('pixelfed.version'),
  38. ],
  39. 'usage' => [
  40. 'localPosts' => (int) $statuses,
  41. 'localComments' => 0,
  42. 'users' => [
  43. 'total' => (int) $users,
  44. 'activeHalfyear' => (int) $activeHalfYear,
  45. 'activeMonth' => (int) $activeMonth,
  46. ],
  47. ],
  48. 'version' => '2.0',
  49. ];
  50. });
  51. $res['openRegistrations'] = (bool) config_cache('pixelfed.open_registration');
  52. return $res;
  53. }
  54. public static function wellKnown()
  55. {
  56. return [
  57. 'links' => [
  58. [
  59. 'href' => config('pixelfed.nodeinfo.url'),
  60. 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
  61. ],
  62. ],
  63. ];
  64. }
  65. public static function activeUsersMonthly()
  66. {
  67. return Cache::remember('api:nodeinfo:active-users-monthly', 43200, function () {
  68. return User::withTrashed()
  69. ->select('last_active_at, updated_at')
  70. ->where('updated_at', '>', now()->subWeeks(5))
  71. ->orWhere('last_active_at', '>', now()->subWeeks(5))
  72. ->count();
  73. });
  74. }
  75. public static function activeUsersHalfYear()
  76. {
  77. return Cache::remember('api:nodeinfo:active-users-half-year', 43200, function () {
  78. return User::withTrashed()
  79. ->select('last_active_at, updated_at')
  80. ->where('last_active_at', '>', now()->subMonths(6))
  81. ->orWhere('updated_at', '>', now()->subMonths(6))
  82. ->count();
  83. });
  84. }
  85. }