Update app/Providers/AppServiceProvider.php
This commit is contained in:
parent
e840ecb915
commit
1a0be9b68e
1 changed files with 168 additions and 28 deletions
|
@ -1,18 +1,30 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Pterodactyl\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Pterodactyl\Models;
|
use App\Extensions\Themes\Theme;
|
||||||
use Illuminate\Support\Str;
|
use App\Models;
|
||||||
use Illuminate\Support\Facades\URL;
|
use App\Models\ApiKey;
|
||||||
use Illuminate\Pagination\Paginator;
|
use App\Models\Node;
|
||||||
use Illuminate\Support\Facades\View;
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Dedoc\Scramble\Scramble;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
||||||
use Pterodactyl\Extensions\Themes\Theme;
|
use Filament\Support\Colors\Color;
|
||||||
|
use Filament\Support\Facades\FilamentColor;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Pterodactyl\Providers\Blueprint\RouteServiceProvider;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Pagination\Paginator;
|
||||||
|
use Illuminate\Support\Facades\Broadcast;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
@ -55,24 +67,7 @@ class AppServiceProvider extends ServiceProvider
|
||||||
/**
|
/**
|
||||||
* Register application service providers.
|
* Register application service providers.
|
||||||
*/
|
*/
|
||||||
public function register(): void
|
|
||||||
{
|
|
||||||
// Merge Blueprint configurations with existing configurations.
|
|
||||||
$this->mergeConfigFrom(base_path('config/ExtensionFS.php'), 'filesystems');
|
|
||||||
|
|
||||||
// Load Blueprint's route service provider.
|
|
||||||
$this->app->register(RouteServiceProvider::class);
|
|
||||||
|
|
||||||
// Only load the settings service provider if the environment
|
|
||||||
// is configured to allow it.
|
|
||||||
if (!config('pterodactyl.load_environment_only', false) && $this->app->environment() !== 'testing') {
|
|
||||||
$this->app->register(SettingsServiceProvider::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->app->singleton('extensions.themes', function () {
|
|
||||||
return new Theme();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return version information for the footer.
|
* Return version information for the footer.
|
||||||
|
@ -102,3 +97,148 @@ class AppServiceProvider extends ServiceProvider
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Extensions\Themes\Theme;
|
||||||
|
use App\Models;
|
||||||
|
use App\Models\ApiKey;
|
||||||
|
use App\Models\Node;
|
||||||
|
use App\Models\User;
|
||||||
|
use Dedoc\Scramble\Scramble;
|
||||||
|
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||||
|
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
||||||
|
use Filament\Support\Colors\Color;
|
||||||
|
use Filament\Support\Facades\FilamentColor;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Pagination\Paginator;
|
||||||
|
use Illuminate\Support\Facades\Broadcast;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
|
||||||
|
use App\Providers\Blueprint\RouteServiceProvider;
|
||||||
|
|
||||||
|
class AppServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap any application services.
|
||||||
|
*/
|
||||||
|
public function boot(Application $app): void
|
||||||
|
{
|
||||||
|
// TODO: remove when old admin area gets yeeted
|
||||||
|
View::share('appVersion', config('app.version'));
|
||||||
|
View::share('appIsGit', false);
|
||||||
|
|
||||||
|
Paginator::useBootstrap();
|
||||||
|
|
||||||
|
// If the APP_URL value is set with https:// make sure we force it here. Theoretically
|
||||||
|
// this should just work with the proxy logic, but there are a lot of cases where it
|
||||||
|
// doesn't, and it triggers a lot of support requests, so lets just head it off here.
|
||||||
|
if (Str::startsWith(config('app.url') ?? '', 'https://')) {
|
||||||
|
URL::forceScheme('https');
|
||||||
|
}
|
||||||
|
|
||||||
|
Relation::enforceMorphMap([
|
||||||
|
'allocation' => Models\Allocation::class,
|
||||||
|
'api_key' => Models\ApiKey::class,
|
||||||
|
'backup' => Models\Backup::class,
|
||||||
|
'database' => Models\Database::class,
|
||||||
|
'egg' => Models\Egg::class,
|
||||||
|
'egg_variable' => Models\EggVariable::class,
|
||||||
|
'schedule' => Models\Schedule::class,
|
||||||
|
'server' => Models\Server::class,
|
||||||
|
'ssh_key' => Models\UserSSHKey::class,
|
||||||
|
'task' => Models\Task::class,
|
||||||
|
'user' => Models\User::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Http::macro(
|
||||||
|
'daemon',
|
||||||
|
fn (Node $node, array $headers = []) => Http::acceptJson()
|
||||||
|
->asJson()
|
||||||
|
->withToken($node->daemon_token)
|
||||||
|
->withHeaders($headers)
|
||||||
|
->withOptions(['verify' => (bool) $app->environment('production')])
|
||||||
|
->timeout(config('panel.guzzle.timeout'))
|
||||||
|
->connectTimeout(config('panel.guzzle.connect_timeout'))
|
||||||
|
->baseUrl($node->getConnectionAddress())
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->bootAuth();
|
||||||
|
$this->bootBroadcast();
|
||||||
|
|
||||||
|
$bearerTokens = fn (OpenApi $openApi) => $openApi->secure(SecurityScheme::http('bearer'));
|
||||||
|
Gate::define('viewApiDocs', fn () => true);
|
||||||
|
Scramble::registerApi('application', ['api_path' => 'api/application', 'info' => ['version' => '1.0']]);
|
||||||
|
Scramble::registerApi('client', ['api_path' => 'api/client', 'info' => ['version' => '1.0']])->afterOpenApiGenerated($bearerTokens);
|
||||||
|
Scramble::registerApi('remote', ['api_path' => 'api/remote', 'info' => ['version' => '1.0']])->afterOpenApiGenerated($bearerTokens);
|
||||||
|
|
||||||
|
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
||||||
|
$event->extendSocialite('discord', \SocialiteProviders\Discord\Provider::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
FilamentColor::register([
|
||||||
|
'danger' => Color::Red,
|
||||||
|
'gray' => Color::Zinc,
|
||||||
|
'info' => Color::Sky,
|
||||||
|
'primary' => Color::Blue,
|
||||||
|
'success' => Color::Green,
|
||||||
|
'warning' => Color::Amber,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Gate::before(function (User $user, $ability) {
|
||||||
|
return $user->isRootAdmin() ? true : null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register application service providers.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
$this->mergeConfigFrom(base_path('config/ExtensionFS.php'), 'filesystems');
|
||||||
|
|
||||||
|
// Load Blueprint's route service provider.
|
||||||
|
$this->app->register(RouteServiceProvider::class);
|
||||||
|
|
||||||
|
// Only load the settings service provider if the environment
|
||||||
|
// is configured to allow it.
|
||||||
|
if (!config('pelican.load_environment_only', false) && $this->app->environment() !== 'testing') {
|
||||||
|
$this->app->register(SettingsServiceProvider::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->app->singleton('extensions.themes', function () {
|
||||||
|
return new Theme();
|
||||||
|
});
|
||||||
|
|
||||||
|
Scramble::extendOpenApi(fn (OpenApi $openApi) => $openApi->secure(SecurityScheme::http('bearer')));
|
||||||
|
Scramble::ignoreDefaultRoutes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bootAuth(): void
|
||||||
|
{
|
||||||
|
Sanctum::usePersonalAccessTokenModel(ApiKey::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function bootBroadcast(): void
|
||||||
|
{
|
||||||
|
Broadcast::routes();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Authenticate the user's personal channel...
|
||||||
|
*/
|
||||||
|
Broadcast::channel('App.User.*', function ($user, $userId) {
|
||||||
|
return (int) $user->id === (int) $userId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue