Update app/Http/Controllers/Admin/Extensions/Blueprint/BlueprintExtensionController.php

This commit is contained in:
denis 2024-11-03 04:10:51 -05:00
parent 391a7e6ebb
commit e840ecb915

View file

@ -1,92 +1,92 @@
<?php <?php
namespace Pterodactyl\Http\Controllers\Admin\Extensions\Blueprint; namespace App\Http\Controllers\Admin\Extensions\Blueprint;
use Artisan; use Artisan;
use Illuminate\View\View; use Illuminate\View\View;
use Illuminate\View\Factory as ViewFactory; use Illuminate\View\Factory as ViewFactory;
use Pterodactyl\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Pterodactyl\BlueprintFramework\Services\PlaceholderService\BlueprintPlaceholderService; use App\BlueprintFramework\Services\PlaceholderService\BlueprintPlaceholderService;
use Pterodactyl\BlueprintFramework\Services\ConfigService\BlueprintConfigService; use App\BlueprintFramework\Services\ConfigService\BlueprintConfigService;
use Pterodactyl\BlueprintFramework\Services\TelemetryService\BlueprintTelemetryService; use App\BlueprintFramework\Services\TelemetryService\BlueprintTelemetryService;
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary; use App\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface; use App\Contracts\Repository\SettingsRepositoryInterface;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest; use App\Http\Requests\Admin\AdminFormRequest;
class BlueprintExtensionController extends Controller class BlueprintExtensionController extends Controller
{ {
/** /**
* BlueprintExtensionController constructor. * BlueprintExtensionController constructor.
*/ */
public function __construct( public function __construct(
private BlueprintTelemetryService $TelemetryService, private BlueprintTelemetryService $TelemetryService,
private BlueprintExtensionLibrary $ExtensionLibrary, private BlueprintExtensionLibrary $ExtensionLibrary,
private BlueprintPlaceholderService $PlaceholderService, private BlueprintPlaceholderService $PlaceholderService,
private BlueprintConfigService $ConfigService, private BlueprintConfigService $ConfigService,
private ViewFactory $view, private ViewFactory $view,
private SettingsRepositoryInterface $settings, private SettingsRepositoryInterface $settings,
) { ) {
} }
/** /**
* Return the admin index view. * Return the admin index view.
*/ */
public function index(): View public function index(): View
{ {
$LatestVersion = $this->ConfigService->latest(); $LatestVersion = $this->ConfigService->latest();
return $this->view->make( return $this->view->make(
'admin.extensions.blueprint.index', [ 'admin.extensions.blueprint.index', [
'ExtensionLibrary' => $this->ExtensionLibrary, 'ExtensionLibrary' => $this->ExtensionLibrary,
'TelemetryService' => $this->TelemetryService, 'TelemetryService' => $this->TelemetryService,
'PlaceholderService' => $this->PlaceholderService, 'PlaceholderService' => $this->PlaceholderService,
'ConfigService' => $this->ConfigService, 'ConfigService' => $this->ConfigService,
'LatestVersion' => $LatestVersion, 'LatestVersion' => $LatestVersion,
'root' => "/admin/extensions/blueprint", 'root' => "/admin/extensions/blueprint",
] ]
); );
} }
/** /**
* @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/ */
public function update(BlueprintAdminFormRequest $request): RedirectResponse public function update(BlueprintAdminFormRequest $request): RedirectResponse
{ {
foreach ($request->normalize() as $key => $value) { foreach ($request->normalize() as $key => $value) {
$this->settings->set('blueprint::' . $key, $value); $this->settings->set('blueprint::' . $key, $value);
} }
// Confirm that the database value changes have been applied. // Confirm that the database value changes have been applied.
$this->ExtensionLibrary->notify("Your changes have been saved."); $this->ExtensionLibrary->notify("Your changes have been saved.");
// Sync database values with the bash side of Blueprint. // Sync database values with the bash side of Blueprint.
Artisan::call("bp:sync"); Artisan::call("bp:sync");
// Redirect back to the page the user was on. // Redirect back to the page the user was on.
return redirect()->route('admin.extensions.blueprint.index'); return redirect()->route('admin.extensions.blueprint.index');
} }
} }
class BlueprintAdminFormRequest extends AdminFormRequest class BlueprintAdminFormRequest extends AdminFormRequest
{ {
// Form validation for settings on the Blueprint admin page. // Form validation for settings on the Blueprint admin page.
// This is included in the controller directly as that // This is included in the controller directly as that
// simplifies my work. // simplifies my work.
public function rules(): array { public function rules(): array {
return [ return [
'placeholder' => 'string', 'placeholder' => 'string',
'developer' => 'string|in:true,false', 'developer' => 'string|in:true,false',
'telemetry' => 'string|in:true,false', 'telemetry' => 'string|in:true,false',
]; ];
} }
public function attributes(): array { public function attributes(): array {
return [ return [
'placeholder' => 'Placeholder Value', 'placeholder' => 'Placeholder Value',
'developer' => 'Developer Mode', 'developer' => 'Developer Mode',
'telemetry' => 'Telemetry', 'telemetry' => 'Telemetry',
]; ];
} }
} }