Nodeinfo.php 3.2 KB

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