1
0

InstanceApiController.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\{Profile, Status, User};
  6. use Cache;
  7. class InstanceApiController extends Controller {
  8. protected function getData()
  9. {
  10. $contact = Cache::remember('api:v1:instance:contact', now()->addMinutes(1440), function() {
  11. $admin = User::whereIsAdmin(true)->first()->profile;
  12. return [
  13. 'id' => $admin->id,
  14. 'username' => $admin->username,
  15. 'acct' => $admin->username,
  16. 'display_name' => e($admin->name),
  17. 'locked' => (bool) $admin->is_private,
  18. 'created_at' => $admin->created_at->format('c'),
  19. 'note' => e($admin->bio),
  20. 'url' => $admin->url(),
  21. 'avatar' => $admin->avatarUrl(),
  22. 'avatar_static' => $admin->avatarUrl(),
  23. 'header' => null,
  24. 'header_static' => null,
  25. 'moved' => null,
  26. 'fields' => null,
  27. 'bot' => null,
  28. ];
  29. });
  30. $res = [
  31. 'uri' => config('pixelfed.domain.app'),
  32. 'title' => config_cache('app.name'),
  33. 'description' => '',
  34. 'version' => config('pixelfed.version'),
  35. 'urls' => [],
  36. 'stats' => [
  37. 'user_count' => User::count(),
  38. 'status_count' => Status::whereNull('uri')->count(),
  39. 'domain_count' => Profile::whereNotNull('domain')
  40. ->groupBy('domain')
  41. ->pluck('domain')
  42. ->count()
  43. ],
  44. 'thumbnail' => '',
  45. 'languages' => [],
  46. 'contact_account' => $contact
  47. ];
  48. return $res;
  49. }
  50. public function instance()
  51. {
  52. $res = Cache::remember('api:v1:instance', now()->addMinutes(60), function() {
  53. return json_encode($this->getData());
  54. });
  55. return response($res)->header('Content-Type', 'application/json');
  56. }
  57. }