diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php new file mode 100644 index 0000000..9c5f058 --- /dev/null +++ b/app/Http/Controllers/SettingsController.php @@ -0,0 +1,23 @@ +json($settings); + } + + public function store(Request $request, GeneralSettings $settings) + { + foreach ($request->all() as $key => $value) { + $settings->$key = $value; + } + $settings->save(); + } +} diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index 1d53246..2f18ed4 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -2,6 +2,7 @@ namespace App\Http\Middleware; +use App\Settings\GeneralSettings; use Illuminate\Http\Request; use Inertia\Middleware; use Tightenco\Ziggy\Ziggy; @@ -38,6 +39,8 @@ public function share(Request $request): array 'originalFileName' => fn() => $request->session()->get('originalFileName'), 'tmpPath' => fn() => $request->session()->get('tmpPath') ], + 'settings' => ['sitename' => app(GeneralSettings::class)->site_name], + 'ziggy' => function () use ($request) { return array_merge((new Ziggy)->toArray(), [ 'location' => $request->url(), diff --git a/app/Settings/GeneralSettings.php b/app/Settings/GeneralSettings.php new file mode 100644 index 0000000..61f7a09 --- /dev/null +++ b/app/Settings/GeneralSettings.php @@ -0,0 +1,20 @@ + [ + GeneralSettings::class + ], + + /* + * The path where the settings classes will be created. + */ + 'setting_class_path' => app_path('Settings'), + + /* + * In these directories settings migrations will be stored and ran when migrating. A settings + * migration created via the make:settings-migration command will be stored in the first path or + * a custom defined path when running the command. + */ + 'migrations_paths' => [ + database_path('settings'), + ], + + /* + * When no repository was set for a settings class the following repository + * will be used for loading and saving settings. + */ + 'default_repository' => 'database', + + /* + * Settings will be stored and loaded from these repositories. + */ + 'repositories' => [ + 'database' => [ + 'type' => Spatie\LaravelSettings\SettingsRepositories\DatabaseSettingsRepository::class, + 'model' => null, + 'table' => null, + 'connection' => null, + ], + 'redis' => [ + 'type' => Spatie\LaravelSettings\SettingsRepositories\RedisSettingsRepository::class, + 'connection' => null, + 'prefix' => null, + ], + ], + + /* + * The contents of settings classes can be cached through your application, + * settings will be stored within a provided Laravel store and can have an + * additional prefix. + */ + 'cache' => [ + 'enabled' => env('SETTINGS_CACHE_ENABLED', false), + 'store' => null, + 'prefix' => null, + 'ttl' => null, + ], + + /* + * These global casts will be automatically used whenever a property within + * your settings class isn't a default PHP type. + */ + 'global_casts' => [ + DateTimeInterface::class => Spatie\LaravelSettings\SettingsCasts\DateTimeInterfaceCast::class, + DateTimeZone::class => Spatie\LaravelSettings\SettingsCasts\DateTimeZoneCast::class, +// Spatie\DataTransferObject\DataTransferObject::class => Spatie\LaravelSettings\SettingsCasts\DtoCast::class, + Spatie\LaravelData\Data::class => Spatie\LaravelSettings\SettingsCasts\DataCast::class, + ], + + /* + * The package will look for settings in these paths and automatically + * register them. + */ + 'auto_discover_settings' => [ + app_path('Settings'), + ], + + /* + * Automatically discovered settings classes can be cached, so they don't + * need to be searched each time the application boots up. + */ + 'discovered_settings_cache_path' => base_path('bootstrap/cache'), +]; diff --git a/database/migrations/2022_12_14_083707_create_settings_table.php b/database/migrations/2022_12_14_083707_create_settings_table.php new file mode 100644 index 0000000..9d690b6 --- /dev/null +++ b/database/migrations/2022_12_14_083707_create_settings_table.php @@ -0,0 +1,29 @@ +id(); + + $table->string('group'); + $table->string('name'); + $table->boolean('locked')->default(false); + $table->json('payload'); + + $table->timestamps(); + + $table->unique(['group', 'name']); + }); + } + + public function down() + { + Schema::dropIfExists('settings'); + } +}; diff --git a/database/settings/2023_07_11_194334_create_general_settings.php b/database/settings/2023_07_11_194334_create_general_settings.php new file mode 100644 index 0000000..c7fda77 --- /dev/null +++ b/database/settings/2023_07_11_194334_create_general_settings.php @@ -0,0 +1,20 @@ +migrator->add('general.site_name', 'Slipstream'); + $this->migrator->add('general.guests_can_see_video_info', true); + $this->migrator->add('general.streaming_bitrates', [ + 2160 => 4000, + 1440 => 3000, + 1080 => 2000, + 720 => 1000, + 480 => 750, + 360 => 500, + ] + ); + } +}; diff --git a/package-lock.json b/package-lock.json index 64712d6..9e570f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "Slipstream-Core", + "name": "slipstream-core", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/resources/js/Components/Settings/SettingsModal.vue b/resources/js/Components/Settings/SettingsModal.vue index f497da6..4b00ec1 100644 --- a/resources/js/Components/Settings/SettingsModal.vue +++ b/resources/js/Components/Settings/SettingsModal.vue @@ -1,9 +1,14 @@