From f2066b740179e6f00136f69970a0e0654527e8d6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 11 May 2021 22:07:55 -0600 Subject: [PATCH] Add admin config settings --- .../Admin/AdminSettingsController.php | 93 ++++++++-- app/Services/ConfigCacheService.php | 26 ++- resources/views/admin/settings/home.blade.php | 170 ++++++++++++++++-- 3 files changed, 255 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index f1dfea652..0dbf02e83 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -18,11 +18,20 @@ trait AdminSettingsController $name = ConfigCacheService::get('app.name'); $short_description = ConfigCacheService::get('app.short_description'); $description = ConfigCacheService::get('app.description'); + $types = explode(',', ConfigCacheService::get('pixelfed.media_types')); + $jpeg = in_array('image/jpg', $types) ? true : in_array('image/jpeg', $types); + $png = in_array('image/png', $types); + $gif = in_array('image/gif', $types); + $mp4 = in_array('video/mp4', $types); return view('admin.settings.home', compact( 'name', 'short_description', - 'description' + 'description', + 'jpeg', + 'png', + 'gif', + 'mp4' )); } @@ -31,27 +40,83 @@ trait AdminSettingsController $this->validate($request, [ 'name' => 'nullable|string', 'short_description' => 'nullable', - 'long_description' => 'nullable' + 'long_description' => 'nullable', + 'max_photo_size' => 'nullable|integer|min:1', + 'max_album_length' => 'nullable|integer|min:1|max:100', + 'image_quality' => 'nullable|integer|min:1|max:100', + 'type_jpeg' => 'nullable', + 'type_png' => 'nullable', + 'type_gif' => 'nullable', + 'type_mp4' => 'nullable', ]); - $cc = ConfigCache::whereK('app.name')->first(); - $val = $request->input('name'); - if($cc && $cc->v != $val) { - ConfigCacheService::put('app.name', $val); + $media_types = explode(',', config_cache('pixelfed.media_types')); + $media_types_original = $media_types; + + $mimes = [ + 'type_jpeg' => 'image/jpeg', + 'type_png' => 'image/png', + 'type_gif' => 'image/gif', + 'type_mp4' => 'video/mp4', + ]; + + foreach ($mimes as $key => $value) { + if($request->input($key) == 'on') { + if(!in_array($value, $media_types)) { + array_push($media_types, $value); + } + } else { + $media_types = array_diff($media_types, [$value]); + } } - $cc = ConfigCache::whereK('app.short_description')->first(); - $val = $request->input('short_description'); - if($cc && $cc->v != $val) { - ConfigCacheService::put('app.short_description', $val); + if($media_types !== $media_types_original) { + ConfigCacheService::put('pixelfed.media_types', implode(',', array_unique($media_types))); } - $cc = ConfigCache::whereK('app.description')->first(); - $val = $request->input('long_description'); - if($cc && $cc->v != $val) { - ConfigCacheService::put('app.description', $val); + $keys = [ + 'name' => 'app.name', + 'short_description' => 'app.short_description', + 'long_description' => 'app.description', + 'max_photo_size' => 'pixelfed.max_photo_size', + 'max_album_length' => 'pixelfed.max_album_length', + 'image_quality' => 'pixelfed.image_quality', + 'account_limit' => 'pixelfed.max_account_size', + 'custom_css' => 'uikit.custom.css', + 'custom_js' => 'uikit.custom.js' + ]; + + foreach ($keys as $key => $value) { + $cc = ConfigCache::whereK($value)->first(); + $val = $request->input($key); + if($cc && $cc->v != $val) { + ConfigCacheService::put($value, $val); + } } + $bools = [ + 'activitypub' => 'federation.activitypub.enabled', + 'open_registration' => 'pixelfed.open_registration', + 'mobile_apis' => 'pixelfed.oauth_enabled', + 'stories' => 'instance.stories.enabled', + 'ig_import' => 'pixelfed.import.instagram.enabled', + 'spam_detection' => 'pixelfed.bouncer.enabled', + 'require_email_verification' => 'pixelfed.enforce_email_verification', + 'enforce_account_limit' => 'pixelfed.enforce_account_limit', + 'show_custom_css' => 'uikit.show_custom.css', + 'show_custom_js' => 'uikit.show_custom.js', + ]; + + foreach ($bools as $key => $value) { + $active = $request->input($key) == 'on'; + + if(config_cache($value) !== $active) { + ConfigCacheService::put($value, (bool) $active); + } + } + + Cache::forget('api:site:configuration:_v0.2'); + return redirect('/i/admin/settings'); } diff --git a/app/Services/ConfigCacheService.php b/app/Services/ConfigCacheService.php index 9914100c5..4a871bcdc 100644 --- a/app/Services/ConfigCacheService.php +++ b/app/Services/ConfigCacheService.php @@ -21,7 +21,27 @@ class ConfigCacheService 'app.short_description', 'app.description', 'app.rules', - 'app.logo' + + 'pixelfed.max_photo_size', + 'pixelfed.max_album_length', + 'pixelfed.image_quality', + 'pixelfed.media_types', + + 'pixelfed.open_registration', + 'federation.activitypub.enabled', + 'pixelfed.oauth_enabled', + 'instance.stories.enabled', + 'pixelfed.import.instagram.enabled', + 'pixelfed.bouncer.enabled', + + 'pixelfed.enforce_email_verification', + 'pixelfed.max_account_size', + 'pixelfed.enforce_account_limit', + + 'uikit.custom.css', + 'uikit.custom.js', + 'uikit.show_custom.css', + 'uikit.show_custom.js' ]; if(!in_array($key, $allowed)) { @@ -32,7 +52,7 @@ class ConfigCacheService $c = ConfigCacheModel::where('k', $key)->first(); if($c) { - return $c->v; + return $c->v ?? config($key); } if(!$v) { @@ -64,6 +84,8 @@ class ConfigCacheService $cc->v = $val; $cc->save(); + Cache::forget(self::CACHE_KEY . $key); + return self::get($key); } } diff --git a/resources/views/admin/settings/home.blade.php b/resources/views/admin/settings/home.blade.php index fc0c2f345..2b1168699 100644 --- a/resources/views/admin/settings/home.blade.php +++ b/resources/views/admin/settings/home.blade.php @@ -5,32 +5,166 @@ @section('section')

Settings

-

Manage instance settings

+

Manage instance settings.

+

Warning: These settings will override .env variables

@csrf -
-
- - -

The instance name used in titles, metadata and apis.

+ +
+ +
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
-
-
-
- - -

Short description of instance used on various pages and apis.

+
+
+ + +

The instance name used in titles, metadata and apis.

+
-
-
-
- - -

Longer description of instance used on about page.

+
+
+ + +

Short description of instance used on various pages and apis.

+
+
+
+
+ + +

Longer description of instance used on about page.

+
+
+
+
+
+ + +
+
+
+
+
+
+ + +

Set a storage limit per user account.

+
+ + +

Account limit size in KB.

+

{{config_cache('pixelfed.max_account_size')}} KB = {{floor(config_cache('pixelfed.max_account_size') / 1024)}} MB

+
+
+
+ +
+
+
+ + +

Maximum file upload size in KB

+

{{config_cache('pixelfed.max_photo_size')}} KB = {{number_format(config_cache('pixelfed.max_photo_size') / 1024)}} MB

+
+
+
+
+ + +

The maximum number of photos or videos per album

+
+
+
+
+ + +

Image optimization quality from 0-100%. Set to 0 to disable image optimization.

+
+
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+

Allowed media types.

+
+
+
+ +
+
+
+ +
+ + +
+ +

Add custom CSS, will be used on all pages

+
+
+
+ +