LandingService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Services;
  3. use App\Util\ActivityPub\Helpers;
  4. use Illuminate\Support\Str;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Facades\Redis;
  7. use App\Status;
  8. use App\User;
  9. use App\Services\AccountService;
  10. use App\Util\Site\Nodeinfo;
  11. class LandingService
  12. {
  13. public static function get($json = true)
  14. {
  15. $activeMonth = Nodeinfo::activeUsersMonthly();
  16. $totalUsers = Cache::remember('api:nodeinfo:users', 43200, function() {
  17. return User::count();
  18. });
  19. $postCount = Cache::remember('api:nodeinfo:statuses', 21600, function() {
  20. return Status::whereLocal(true)->count();
  21. });
  22. $contactAccount = Cache::remember('api:v1:instance-data:contact', 604800, function () {
  23. if(config_cache('instance.admin.pid')) {
  24. return AccountService::getMastodon(config_cache('instance.admin.pid'), true);
  25. }
  26. $admin = User::whereIsAdmin(true)->first();
  27. return $admin && isset($admin->profile_id) ?
  28. AccountService::getMastodon($admin->profile_id, true) :
  29. null;
  30. });
  31. $rules = Cache::remember('api:v1:instance-data:rules', 604800, function () {
  32. return config_cache('app.rules') ?
  33. collect(json_decode(config_cache('app.rules'), true))
  34. ->map(function($rule, $key) {
  35. $id = $key + 1;
  36. return [
  37. 'id' => "{$id}",
  38. 'text' => $rule
  39. ];
  40. })
  41. ->toArray() : [];
  42. });
  43. $res = [
  44. 'name' => config_cache('app.name'),
  45. 'url' => config_cache('app.url'),
  46. 'domain' => config('pixelfed.domain.app'),
  47. 'show_directory' => config_cache('instance.landing.show_directory'),
  48. 'show_explore_feed' => config_cache('instance.landing.show_explore'),
  49. 'open_registration' => config_cache('pixelfed.open_registration') == 1,
  50. 'version' => config('pixelfed.version'),
  51. 'about' => [
  52. 'banner_image' => config_cache('app.banner_image') ?? url('/storage/headers/default.jpg'),
  53. 'short_description' => config_cache('app.short_description'),
  54. 'description' => config_cache('app.description'),
  55. ],
  56. 'stats' => [
  57. 'active_users' => (int) $activeMonth,
  58. 'posts_count' => (int) $postCount,
  59. 'total_users' => (int) $totalUsers
  60. ],
  61. 'contact' => [
  62. 'account' => $contactAccount,
  63. 'email' => config('instance.email')
  64. ],
  65. 'rules' => $rules,
  66. 'uploader' => [
  67. 'max_photo_size' => (int) (config('pixelfed.max_photo_size') * 1024),
  68. 'max_caption_length' => (int) config('pixelfed.max_caption_length'),
  69. 'max_altext_length' => (int) config('pixelfed.max_altext_length', 150),
  70. 'album_limit' => (int) config_cache('pixelfed.max_album_length'),
  71. 'image_quality' => (int) config_cache('pixelfed.image_quality'),
  72. 'max_collection_length' => (int) config('pixelfed.max_collection_length', 18),
  73. 'optimize_image' => (bool) config('pixelfed.optimize_image'),
  74. 'optimize_video' => (bool) config('pixelfed.optimize_video'),
  75. 'media_types' => config_cache('pixelfed.media_types'),
  76. ],
  77. 'features' => [
  78. 'federation' => config_cache('federation.activitypub.enabled'),
  79. 'timelines' => [
  80. 'local' => true,
  81. 'network' => (bool) config('federation.network_timeline'),
  82. ],
  83. 'mobile_apis' => (bool) config_cache('pixelfed.oauth_enabled'),
  84. 'stories' => (bool) config_cache('instance.stories.enabled'),
  85. 'video' => Str::contains(config_cache('pixelfed.media_types'), 'video/mp4'),
  86. ]
  87. ];
  88. if($json) {
  89. return json_encode($res);
  90. }
  91. return $res;
  92. }
  93. }