diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index 0dbf02e8..138a32f7 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -19,6 +19,7 @@ trait AdminSettingsController $short_description = ConfigCacheService::get('app.short_description'); $description = ConfigCacheService::get('app.description'); $types = explode(',', ConfigCacheService::get('pixelfed.media_types')); + $rules = ConfigCacheService::get('app.rules') ? json_decode(ConfigCacheService::get('app.rules'), true) : null; $jpeg = in_array('image/jpg', $types) ? true : in_array('image/jpeg', $types); $png = in_array('image/png', $types); $gif = in_array('image/gif', $types); @@ -31,7 +32,8 @@ trait AdminSettingsController 'jpeg', 'png', 'gif', - 'mp4' + 'mp4', + 'rules' )); } @@ -50,6 +52,19 @@ trait AdminSettingsController 'type_mp4' => 'nullable', ]); + if($request->filled('rule_delete')) { + $index = (int) $request->input('rule_delete'); + $rules = ConfigCacheService::get('app.rules'); + $json = json_decode($rules, true); + if(!$rules || empty($json)) { + return; + } + unset($json[$index]); + $json = json_encode(array_values($json)); + ConfigCacheService::put('app.rules', $json); + return 200; + } + $media_types = explode(',', config_cache('pixelfed.media_types')); $media_types_original = $media_types; @@ -115,6 +130,18 @@ trait AdminSettingsController } } + if($request->filled('new_rule')) { + $rules = ConfigCacheService::get('app.rules'); + $val = $request->input('new_rule'); + if(!$rules) { + ConfigCacheService::put('app.rules', json_encode([$val])); + } else { + $json = json_decode($rules, true); + $json[] = $val; + ConfigCacheService::put('app.rules', json_encode(array_values($json))); + } + } + Cache::forget('api:site:configuration:_v0.2'); return redirect('/i/admin/settings'); diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index ddc02cdc..8837e4f5 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -957,37 +957,49 @@ class ApiV1Controller extends Controller */ public function instance(Request $request) { - $res = [ - 'approval_required' => false, - 'contact_account' => null, - 'description' => config_cache('app.description'), - 'email' => config('instance.email'), - 'invites_enabled' => false, - 'rules' => [], - 'short_description' => 'Pixelfed - Photo sharing for everyone', - 'languages' => ['en'], - 'max_toot_chars' => (int) config('pixelfed.max_caption_length'), - 'registrations' => config_cache('pixelfed.open_registration'), - 'stats' => [ - 'user_count' => 0, - 'status_count' => 0, - 'domain_count' => 0 - ], - 'thumbnail' => config('app.url') . '/img/pixelfed-icon-color.png', - 'title' => config_cache('app.name'), - 'uri' => config('pixelfed.domain.app'), - 'urls' => [], - 'version' => '2.7.2 (compatible; Pixelfed ' . config('pixelfed.version') . ')', - 'environment' => [ - 'max_photo_size' => (int) config_cache('pixelfed.max_photo_size'), - 'max_avatar_size' => (int) config('pixelfed.max_avatar_size'), - 'max_caption_length' => (int) config('pixelfed.max_caption_length'), - 'max_bio_length' => (int) config('pixelfed.max_bio_length'), - 'max_album_length' => (int) config_cache('pixelfed.max_album_length'), - 'mobile_apis' => config_cache('pixelfed.oauth_enabled') + $res = Cache::remember('api:v1:instance-data', now()->addMinutes(15), function () { + $rules = config_cache('app.rules') ? collect(json_decode(config_cache('app.rules'), true)) + ->map(function($rule, $key) { + $id = $key + 1; + return [ + 'id' => "{$id}", + 'text' => $rule + ]; + }) + ->toArray() : []; + $res = [ + 'approval_required' => false, + 'contact_account' => null, + 'description' => config_cache('app.description'), + 'email' => config('instance.email'), + 'invites_enabled' => false, + 'rules' => $rules, + 'short_description' => 'Pixelfed - Photo sharing for everyone', + 'languages' => ['en'], + 'max_toot_chars' => (int) config('pixelfed.max_caption_length'), + 'registrations' => config_cache('pixelfed.open_registration'), + 'stats' => [ + 'user_count' => 0, + 'status_count' => 0, + 'domain_count' => 0 + ], + 'thumbnail' => config('app.url') . '/img/pixelfed-icon-color.png', + 'title' => config_cache('app.name'), + 'uri' => config('pixelfed.domain.app'), + 'urls' => [], + 'version' => '2.7.2 (compatible; Pixelfed ' . config('pixelfed.version') . ')', + 'environment' => [ + 'max_photo_size' => (int) config_cache('pixelfed.max_photo_size'), + 'max_avatar_size' => (int) config('pixelfed.max_avatar_size'), + 'max_caption_length' => (int) config('pixelfed.max_caption_length'), + 'max_bio_length' => (int) config('pixelfed.max_bio_length'), + 'max_album_length' => (int) config_cache('pixelfed.max_album_length'), + 'mobile_apis' => config_cache('pixelfed.oauth_enabled') - ] - ]; + ] + ]; + return $res; + }); return response()->json($res); } diff --git a/resources/views/admin/settings/home.blade.php b/resources/views/admin/settings/home.blade.php index 82a37e92..330b611f 100644 --- a/resources/views/admin/settings/home.blade.php +++ b/resources/views/admin/settings/home.blade.php @@ -21,6 +21,9 @@ + @@ -151,6 +154,35 @@ +
+
+

Add rules that explain what is acceptable use.

+
+
+

Active Rules

+
    + @if($rules) + @foreach($rules as $rule) +
  1. +

    + {{$rule}} +

    +

    + +

    +
  2. + @endforeach + @endif +
+
+
+
+ + +
+
+
+
@@ -181,3 +213,18 @@
@endif @endsection + +@push('scripts') + +@endpush