Add admin config settings

This commit is contained in:
Daniel Supernault 2021-05-11 22:07:55 -06:00
parent 7895097fc1
commit f2066b7401
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 255 additions and 34 deletions

View file

@ -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');
}