InstanceApiController.php 1.7 KB

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