Nodeinfo.php 2.0 KB

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