Config.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Util\Site;
  3. use Cache;
  4. use Illuminate\Support\Str;
  5. class Config
  6. {
  7. const CACHE_KEY = 'api:site:configuration:_v0.9';
  8. public static function get()
  9. {
  10. return Cache::remember(self::CACHE_KEY, 900, function () {
  11. $hls = [
  12. 'enabled' => config('media.hls.enabled'),
  13. ];
  14. if (config('media.hls.enabled')) {
  15. $hls = [
  16. 'enabled' => true,
  17. 'debug' => (bool) config('media.hls.debug'),
  18. 'p2p' => (bool) config('media.hls.p2p'),
  19. 'p2p_debug' => (bool) config('media.hls.p2p_debug'),
  20. 'tracker' => config('media.hls.tracker'),
  21. 'ice' => config('media.hls.ice'),
  22. ];
  23. }
  24. return [
  25. 'version' => config('pixelfed.version'),
  26. 'open_registration' => (bool) config_cache('pixelfed.open_registration'),
  27. 'show_legal_notice_link' => (bool) config('instance.has_legal_notice'),
  28. 'uploader' => [
  29. 'max_photo_size' => (int) config_cache('pixelfed.max_photo_size'),
  30. 'max_caption_length' => (int) config_cache('pixelfed.max_caption_length'),
  31. 'max_altext_length' => (int) config_cache('pixelfed.max_altext_length', 150),
  32. 'album_limit' => (int) config_cache('pixelfed.max_album_length'),
  33. 'image_quality' => (int) config_cache('pixelfed.image_quality'),
  34. 'max_collection_length' => (int) config_cache('pixelfed.max_collection_length', 18),
  35. 'optimize_image' => (bool) config_cache('pixelfed.optimize_image'),
  36. 'optimize_video' => (bool) config_cache('pixelfed.optimize_video'),
  37. 'media_types' => config_cache('pixelfed.media_types'),
  38. 'mime_types' => config_cache('pixelfed.media_types') ? explode(',', config_cache('pixelfed.media_types')) : [],
  39. 'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit'),
  40. ],
  41. 'activitypub' => [
  42. 'enabled' => (bool) config_cache('federation.activitypub.enabled'),
  43. 'remote_follow' => config('federation.activitypub.remoteFollow'),
  44. ],
  45. 'ab' => config('exp'),
  46. 'site' => [
  47. 'name' => config_cache('app.name'),
  48. 'domain' => config('pixelfed.domain.app'),
  49. 'url' => config('app.url'),
  50. 'description' => config_cache('app.short_description'),
  51. ],
  52. 'account' => [
  53. 'max_avatar_size' => config('pixelfed.max_avatar_size'),
  54. 'max_bio_length' => config('pixelfed.max_bio_length'),
  55. 'max_name_length' => config('pixelfed.max_name_length'),
  56. 'min_password_length' => config('pixelfed.min_password_length'),
  57. 'max_account_size' => config('pixelfed.max_account_size'),
  58. ],
  59. 'username' => [
  60. 'remote' => [
  61. 'formats' => config('instance.username.remote.formats'),
  62. 'format' => config('instance.username.remote.format'),
  63. 'custom' => config('instance.username.remote.custom'),
  64. ],
  65. ],
  66. 'features' => [
  67. 'timelines' => [
  68. 'local' => true,
  69. 'network' => (bool) config('federation.network_timeline'),
  70. ],
  71. 'mobile_apis' => (bool) config_cache('pixelfed.oauth_enabled'),
  72. 'mobile_registration' => config('auth.in_app_registration'),
  73. 'stories' => (bool) config_cache('instance.stories.enabled'),
  74. 'video' => Str::contains(config_cache('pixelfed.media_types'), 'video/mp4'),
  75. 'import' => [
  76. 'instagram' => (bool) config_cache('pixelfed.import.instagram.enabled'),
  77. 'mastodon' => false,
  78. 'pixelfed' => false,
  79. ],
  80. 'label' => [
  81. 'covid' => [
  82. 'enabled' => (bool) config('instance.label.covid.enabled'),
  83. 'org' => config('instance.label.covid.org'),
  84. 'url' => config('instance.label.covid.url'),
  85. ],
  86. ],
  87. 'hls' => $hls,
  88. 'groups' => (bool) config('groups.enabled'),
  89. ],
  90. ];
  91. });
  92. }
  93. public static function refresh()
  94. {
  95. Cache::forget(self::CACHE_KEY);
  96. return self::get();
  97. }
  98. public static function json()
  99. {
  100. return json_encode(self::get(), JSON_FORCE_OBJECT);
  101. }
  102. }