diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index 138a32f7f..f6fce8a52 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -6,18 +6,20 @@ use Artisan, Cache, DB; use Illuminate\Http\Request; use Carbon\Carbon; use App\{Comment, Like, Media, Page, Profile, Report, Status, User}; +use App\Models\InstanceActor; 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 +27,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 +108,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 +131,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 +167,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 +192,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 +200,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/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/ConfigCacheService.php b/app/Services/ConfigCacheService.php index 7c1f0c9ab..18ccab050 100644 --- a/app/Services/ConfigCacheService.php +++ b/app/Services/ConfigCacheService.php @@ -8,12 +8,13 @@ use App\Models\ConfigCache as ConfigCacheModel; class ConfigCacheService { - const CACHE_KEY = 'config_cache:_key:'; + const CACHE_KEY = 'config_cache:_v0-key:'; public static function get($key) { - $cacheKey = "config_cache:_key:{$key}"; + $cacheKey = self::CACHE_KEY . $key; $ttl = now()->addHours(12); + return Cache::remember($cacheKey, $ttl, function() use($key) { $allowed = [ @@ -29,8 +30,8 @@ class ConfigCacheService 'pixelfed.open_registration', 'federation.activitypub.enabled', - 'pixelfed.oauth_enabled', 'instance.stories.enabled', + 'pixelfed.oauth_enabled', 'pixelfed.import.instagram.enabled', 'pixelfed.bouncer.enabled', @@ -41,7 +42,10 @@ class ConfigCacheService 'uikit.custom.css', 'uikit.custom.js', 'uikit.show_custom.css', - 'uikit.show_custom.js' + 'uikit.show_custom.js', + 'about.title', + + 'pixelfed.cloud_storage' ]; if(!config('instance.enable_cc')) { @@ -79,7 +83,7 @@ class ConfigCacheService if($exists) { $exists->v = $val; $exists->save(); - Cache::forget(self::CACHE_KEY . $key); + Cache::put(self::CACHE_KEY . $key, $val, now()->addHours(12)); return self::get($key); } @@ -88,7 +92,7 @@ class ConfigCacheService $cc->v = $val; $cc->save(); - Cache::forget(self::CACHE_KEY . $key); + Cache::put(self::CACHE_KEY . $key, $val, now()->addHours(12)); return self::get($key); } 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); } } 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,24 +6,29 @@
Manage instance settings.
-Warning: These settings will override .env variables
+Manage instance settings