From 41792eea56d2ef19de84e95a7235624b074c3b24 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 May 2021 22:45:04 -0600 Subject: [PATCH 1/3] Update config() to config_cache() --- app/Http/Controllers/ComposeController.php | 2 +- app/Jobs/AvatarPipeline/RemoteAvatarFetch.php | 6 +++--- app/Jobs/MediaPipeline/MediaDeletePipeline.php | 6 +++--- app/Services/MediaStorageService.php | 2 +- app/Util/ActivityPub/Helpers.php | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index ee317ad2c..5058a786d 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -646,7 +646,7 @@ class ComposeController extends Controller case 'image/jpeg': case 'image/png': case 'video/mp4': - $finished = config('pixelfed.cloud_storage') ? (bool) $media->cdn_url : (bool) $media->processed_at; + $finished = config_cache('pixelfed.cloud_storage') ? (bool) $media->cdn_url : (bool) $media->processed_at; break; default: diff --git a/app/Jobs/AvatarPipeline/RemoteAvatarFetch.php b/app/Jobs/AvatarPipeline/RemoteAvatarFetch.php index d324a51a4..6817ac55b 100644 --- a/app/Jobs/AvatarPipeline/RemoteAvatarFetch.php +++ b/app/Jobs/AvatarPipeline/RemoteAvatarFetch.php @@ -51,7 +51,7 @@ class RemoteAvatarFetch implements ShouldQueue { $profile = $this->profile; - if(config('pixelfed.cloud_storage') !== true) { + if(config_cache('pixelfed.cloud_storage') !== true) { return 1; } @@ -75,7 +75,7 @@ class RemoteAvatarFetch implements ShouldQueue return 1; } - if( !isset($person['icon']) || + if( !isset($person['icon']) || !isset($person['icon']['type']) || !isset($person['icon']['url']) ) { @@ -99,4 +99,4 @@ class RemoteAvatarFetch implements ShouldQueue return 1; } -} \ No newline at end of file +} diff --git a/app/Jobs/MediaPipeline/MediaDeletePipeline.php b/app/Jobs/MediaPipeline/MediaDeletePipeline.php index 9d89f9449..f44d080ce 100644 --- a/app/Jobs/MediaPipeline/MediaDeletePipeline.php +++ b/app/Jobs/MediaPipeline/MediaDeletePipeline.php @@ -27,7 +27,7 @@ class MediaDeletePipeline implements ShouldQueue $media = $this->media; $path = $media->media_path; $thumb = $media->thumbnail_path; - + if(!$path) { return 1; } @@ -36,7 +36,7 @@ class MediaDeletePipeline implements ShouldQueue array_pop($e); $i = implode('/', $e); - if(config('pixelfed.cloud_storage') == true) { + if(config_cache('pixelfed.cloud_storage') == true) { $disk = Storage::disk(config('filesystems.cloud')); if($disk->exists($path)) { $disk->delete($path); @@ -64,4 +64,4 @@ class MediaDeletePipeline implements ShouldQueue return 1; } -} \ No newline at end of file +} diff --git a/app/Services/MediaStorageService.php b/app/Services/MediaStorageService.php index 17e866da6..2c44c4ca3 100644 --- a/app/Services/MediaStorageService.php +++ b/app/Services/MediaStorageService.php @@ -20,7 +20,7 @@ class MediaStorageService { public static function store(Media $media) { - if(config('pixelfed.cloud_storage') == true) { + if(config_cache('pixelfed.cloud_storage') == true) { (new self())->cloudStore($media); } diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index c5c176fc3..34bb889c6 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -441,7 +441,7 @@ class Helpers { $media->version = 3; $media->save(); - if(config('pixelfed.cloud_storage') == true) { + if(config_cache('pixelfed.cloud_storage') == true) { MediaStoragePipeline::dispatch($media); } } @@ -511,7 +511,7 @@ class Helpers { $profile->webfinger = Purify::clean($webfinger); $profile->last_fetched_at = now(); $profile->save(); - if(config('pixelfed.cloud_storage') == true) { + if(config_cache('pixelfed.cloud_storage') == true) { RemoteAvatarFetch::dispatch($profile); } return $profile; @@ -528,7 +528,7 @@ class Helpers { $profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) && Helpers::validateUrl($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null; $profile->save(); } - if(config('pixelfed.cloud_storage') == true) { + if(config_cache('pixelfed.cloud_storage') == true) { RemoteAvatarFetch::dispatch($profile); } } From 24e77f647d81334f30b42ecfe3c1354e937e6b21 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 19 May 2021 02:01:33 -0600 Subject: [PATCH 2/3] Update admin settings --- .../Admin/AdminSettingsController.php | 67 +++++----- app/Util/Site/Config.php | 4 +- resources/views/admin/settings/home.blade.php | 124 ++++++++++++++++-- 3 files changed, 149 insertions(+), 46 deletions(-) diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index 138a32f7f..055fec353 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -5,19 +5,20 @@ namespace App\Http\Controllers\Admin; use Artisan, Cache, DB; use Illuminate\Http\Request; use Carbon\Carbon; -use App\{Comment, Like, Media, Page, Profile, Report, Status, User}; +use App\{Comment, InstanceActor, Like, Media, Page, Profile, Report, Status, User}; use App\Http\Controllers\Controller; use App\Util\Lexer\PrettyNumber; use App\Models\ConfigCache; use App\Services\ConfigCacheService; +use App\Util\Site\Config; trait AdminSettingsController { public function settings(Request $request) { - $name = ConfigCacheService::get('app.name'); - $short_description = ConfigCacheService::get('app.short_description'); - $description = ConfigCacheService::get('app.description'); + $cloud_storage = ConfigCacheService::get('pixelfed.cloud_storage'); + $cloud_disk = config('filesystems.cloud'); + $cloud_ready = !empty(config('filesystems.disks.' . $cloud_disk . '.key')) && !empty(config('filesystems.disks.' . $cloud_disk . '.secret')); $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); @@ -25,15 +26,23 @@ trait AdminSettingsController $gif = in_array('image/gif', $types); $mp4 = in_array('video/mp4', $types); + // $system = [ + // 'permissions' => is_writable(base_path('storage')) && is_writable(base_path('bootstrap')), + // 'max_upload_size' => ini_get('post_max_size'), + // 'image_driver' => config('image.driver'), + // 'image_driver_loaded' => extension_loaded(config('image.driver')) + // ]; + return view('admin.settings.home', compact( - 'name', - 'short_description', - 'description', 'jpeg', 'png', 'gif', 'mp4', - 'rules' + 'rules', + 'cloud_storage', + 'cloud_disk', + 'cloud_ready', + // 'system' )); } @@ -98,7 +107,8 @@ trait AdminSettingsController 'image_quality' => 'pixelfed.image_quality', 'account_limit' => 'pixelfed.max_account_size', 'custom_css' => 'uikit.custom.css', - 'custom_js' => 'uikit.custom.js' + 'custom_js' => 'uikit.custom.js', + 'about_title' => 'about.title' ]; foreach ($keys as $key => $value) { @@ -120,11 +130,25 @@ trait AdminSettingsController 'enforce_account_limit' => 'pixelfed.enforce_account_limit', 'show_custom_css' => 'uikit.show_custom.css', 'show_custom_js' => 'uikit.show_custom.js', + 'cloud_storage' => 'pixelfed.cloud_storage' ]; foreach ($bools as $key => $value) { $active = $request->input($key) == 'on'; + if($key == 'activitypub' && $active && !InstanceActor::exists()) { + Artisan::call('instance:actor'); + } + + if( $key == 'mobile_apis' && + $active && + !file_exists(storage_path('oauth-public.key')) && + !file_exists(storage_path('oauth-private.key')) + ) { + Artisan::call('passport:keys'); + Artisan::call('route:cache'); + } + if(config_cache($value) !== $active) { ConfigCacheService::put($value, (bool) $active); } @@ -142,9 +166,9 @@ trait AdminSettingsController } } - Cache::forget('api:site:configuration:_v0.2'); + Cache::forget(Config::CACHE_KEY); - return redirect('/i/admin/settings'); + return redirect('/i/admin/settings')->with('status', 'Successfully updated settings!'); } public function settingsBackups(Request $request) @@ -167,19 +191,6 @@ trait AdminSettingsController if(config('pixelfed.admin.env_editor') !== true) { abort(400); } - $res = $request->input('res'); - - $old = file_get_contents(app()->environmentFilePath()); - if(empty($old) || $old != $res) { - $oldFile = fopen(app()->environmentFilePath().'.backup', 'w'); - fwrite($oldFile, $old); - fclose($oldFile); - } - - $file = fopen(app()->environmentFilePath(), 'w'); - fwrite($file, $res); - fclose($file); - Artisan::call('config:cache'); return ['msg' => 200]; } @@ -188,14 +199,6 @@ trait AdminSettingsController if(config('pixelfed.admin.env_editor') !== true) { abort(400); } - $res = file_get_contents(app()->environmentFilePath().'.backup'); - if(empty($res)) { - abort(400, 'No backup exists.'); - } - $file = fopen(app()->environmentFilePath(), 'w'); - fwrite($file, $res); - fclose($file); - Artisan::call('config:cache'); return ['msg' => 200]; } diff --git a/app/Util/Site/Config.php b/app/Util/Site/Config.php index 117696c59..eb3dd725a 100644 --- a/app/Util/Site/Config.php +++ b/app/Util/Site/Config.php @@ -7,8 +7,10 @@ use Illuminate\Support\Str; class Config { + const CACHE_KEY = 'api:site:configuration:_v0.3'; + public static function get() { - return Cache::remember('api:site:configuration:_v0.3', now()->addMinutes(5), function() { + return Cache::remember(self::CACHE_KEY, now()->addMinutes(5), function() { return [ 'open_registration' => (bool) config_cache('pixelfed.open_registration'), 'uploader' => [ diff --git a/resources/views/admin/settings/home.blade.php b/resources/views/admin/settings/home.blade.php index 330b611ff..863ac3b21 100644 --- a/resources/views/admin/settings/home.blade.php +++ b/resources/views/admin/settings/home.blade.php @@ -6,23 +6,28 @@

Settings

@if(config('instance.enable_cc')) -

Manage instance settings.

-

Warning: These settings will override .env variables

+

Manage instance settings

@csrf