Skip to content

Commit

Permalink
feat: make some changes in database and blueprint settings
Browse files Browse the repository at this point in the history
  • Loading branch information
prplwtf committed Dec 21, 2024
1 parent 0ac727f commit bc05337
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function notifyNow($text): void
*/
public function importStylesheet(string $url): string
{
$cache = $this->dbGet('blueprint', 'cache', 0);
$cache = $this->dbGet('blueprint', 'internal:cache', 0);

return "<link rel=\"stylesheet\" href=\"$url?v=$cache\">";
}
Expand All @@ -81,7 +81,7 @@ public function importStylesheet(string $url): string
*/
public function importScript(string $url): string
{
$cache = $this->dbGet('blueprint', 'cache', 0);
$cache = $this->dbGet('blueprint', 'internal:cache', 0);

return "<script src=\"$url?v=$cache\"></script>";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BlueprintClientLibrary extends BlueprintBaseLibrary
*/
public function importStylesheet(string $url): string
{
$cache = $this->dbGet('blueprint', 'cache', 0);
$cache = $this->dbGet('blueprint', 'internal:cache', 0);

return "<link rel=\"stylesheet\" href=\"$url?v=$cache\">";
}
Expand All @@ -43,7 +43,7 @@ public function importStylesheet(string $url): string
*/
public function importScript(string $url): string
{
$cache = $this->dbGet('blueprint', 'cache', 0);
$cache = $this->dbGet('blueprint', 'internal:cache', 0);

return "<script src=\"$url?v=$cache\"></script>";
}
Expand Down
3 changes: 1 addition & 2 deletions app/Console/Commands/BlueprintFramework/DeveloperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function __construct(
*/
public function handle()
{
$developer = $this->blueprint->dbGet('blueprint', 'developer', 'false') === 'true';
if ($developer) {
if ($this->blueprint->dbGet('blueprint', 'flags:is_developer', 0)) {
echo ("true");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function handle()
$data = json_decode($cleaned_response, true);
if (isset($data['name'])) {
$latest_version = $data['name'];
$this->blueprint->dbSet('blueprint', 'version:latest', $latest_version);
$this->blueprint->dbSet('blueprint', 'internal:version:latest', $latest_version);
return true;
} else {
echo "Error: Unable to fetch the latest release version.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function __construct(
*/
public function handle()
{
$latest = $this->blueprint->dbGet('blueprint', 'version:latest');
$latest = $this->blueprint->dbGet('blueprint', 'internal:version:latest');
if ($latest == "") {
$this->call('bp:version:cache');
$latest = $this->blueprint->dbGet('blueprint', 'version:latest');
$latest = $this->blueprint->dbGet('blueprint', 'internal:version:latest');
}

echo ($latest);
Expand Down
4 changes: 3 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Pterodactyl\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
use Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
use Pterodactyl\Services\Telemetry\RegisterBlueprintTelemetry;
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Console\BlueprintConsoleLibrary as BlueprintExtensionLibrary;

class Kernel extends ConsoleKernel
{
Expand Down Expand Up @@ -52,7 +53,8 @@ protected function schedule(Schedule $schedule): void
}

// Blueprint telemetry
if (config('blueprint.telemetry')) {
$blueprint = app()->make(BlueprintExtensionLibrary::class);
if ($blueprint->dbGet('blueprint', 'flags:telemetry_enabled', 0)) {
$registerBlueprintTelemetry = app()->make(RegisterBlueprintTelemetry::class);
$registerBlueprintTelemetry->register($schedule);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace Pterodactyl\Http\Controllers\Admin\Extensions\Blueprint;

use Illuminate\View\View;
use Illuminate\View\Factory as ViewFactory;
use Pterodactyl\Http\Controllers\Controller;
use Pterodactyl\BlueprintFramework\Services\PlaceholderService\BlueprintPlaceholderService;
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;
use Illuminate\Http\RedirectResponse;
use Pterodactyl\Http\Requests\Admin\AdminFormRequest;
Expand All @@ -18,32 +14,10 @@ class BlueprintExtensionController extends Controller
* BlueprintExtensionController constructor.
*/
public function __construct(
private BlueprintExtensionLibrary $ExtensionLibrary,
private BlueprintPlaceholderService $PlaceholderService,

private ViewFactory $view,
private SettingsRepositoryInterface $settings,
) {
}

/**
* Return the admin index view.
*/
public function index(): View
{
$LatestVersion = $this->ExtensionLibrary->dbGet('blueprint', 'version:latest');
return $this->view->make(
'admin.extensions.blueprint.index',
[
'ExtensionLibrary' => $this->ExtensionLibrary,
'PlaceholderService' => $this->PlaceholderService,
'LatestVersion' => $LatestVersion,

'root' => "/admin/extensions/blueprint",
]
);
}

/**
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
Expand All @@ -54,31 +28,17 @@ public function update(BlueprintAdminFormRequest $request): RedirectResponse
$this->settings->set('blueprint::' . $key, $value);
}

// Confirm that the database value changes have been applied.
$this->ExtensionLibrary->notify("Your changes have been saved.");
// Redirect back to the page the user was on.
return redirect()->route('admin.extensions.blueprint.index');
return redirect()->route('admin.extensions');
}
}

class BlueprintAdminFormRequest extends AdminFormRequest
{
// Form validation for settings on the Blueprint admin page.
// This is included in the controller directly as that
// simplifies my work.
public function rules(): array
{
return [
'placeholder' => 'string',
'developer' => 'string|in:true,false',
];
}

public function attributes(): array
{
return [
'placeholder' => 'Placeholder Value',
'developer' => 'Developer Mode',
'flags:is_developer' => 'boolean',
'flags:telemetry_enabled' => 'boolean',
];
}
}
3 changes: 3 additions & 0 deletions app/Http/Controllers/Admin/ExtensionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ public function __construct(
*/
public function index(): View
{
$configuration = $this->blueprint->dbGetMany('blueprint');

return $this->view->make('admin.extensions', [
'blueprint' => $this->blueprint,
'PlaceholderService' => $this->PlaceholderService,
'configuration' => $configuration,

'version' => $this->version,
'root' => "/admin/extensions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public function __invoke(): void
*/
public function collect(): array
{
$uuid = $this->blueprint->dbGet('blueprint', 'uuid');
$uuid = $this->blueprint->dbGet('blueprint', 'internal:uuid');
if (is_null($uuid)) {
$uuid = Uuid::uuid4()->toString();
$this->blueprint->dbSet('blueprint', 'uuid', $uuid);
$this->blueprint->dbSet('blueprint', 'internal:uuid', $uuid);
}

return [
Expand All @@ -53,7 +53,7 @@ public function collect(): array
'blueprint' => [
'version' => $this->placeholderService->version(),
'extensions' => $this->blueprint->extensions()->toArray(),
'developer' => $this->blueprint->dbGet('blueprint', 'developer', 'false') === "true",
'developer' => $this->blueprint->dbGet('blueprint', 'flags:is_developer', 'false') === "true",
'docker' => file_exists('/.dockerenv'),
],

Expand Down
4 changes: 2 additions & 2 deletions app/Services/Telemetry/RegisterBlueprintTelemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function register(Schedule $schedule): void
{
$blueprint = app()->make(BlueprintExtensionLibrary::class);

$uuid = $blueprint->dbGet('blueprint', 'uuid');
$uuid = $blueprint->dbGet('blueprint', 'internal:uuid');
if (is_null($uuid)) {
$uuid = Uuid::uuid4()->toString();
$blueprint->dbSet('blueprint', 'uuid', $uuid);
$blueprint->dbSet('blueprint', 'internal:uuid', $uuid);
}

// Calculate a fixed time to run the data push at, this will be the same time every day.
Expand Down
11 changes: 6 additions & 5 deletions blueprint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ if [[ $1 != "-bash" ]]; then
exit 2
else
# Only run if Blueprint is not in the process of upgrading.
if [[ $BLUEPRINT_ENVIRONMENT != "upgrade" ]]; then
if [[ ( $BLUEPRINT_ENVIRONMENT != "upgrade" ) && ( $1 != "--post-upgrade" ) ]]; then
# Print Blueprint icon with ascii characters.
C0="\x1b[0m"
C1="\x1b[31;43;1m"
Expand Down Expand Up @@ -303,14 +303,15 @@ if [[ $1 != "-bash" ]]; then
php artisan up &>> "$BLUEPRINT__DEBUG"
fi

# Let the panel know the user has finished installation.
dbAdd "blueprint.setupFinished"
sed -i "s~NOTINSTALLED~INSTALLED~g" "$FOLDER/app/BlueprintFramework/Services/PlaceholderService/BlueprintPlaceholderService.php"

# Finish installation
if [[ $BLUEPRINT_ENVIRONMENT != "upgrade" ]]; then
if [[ ( $BLUEPRINT_ENVIRONMENT != "upgrade" ) && ( $1 != "--post-upgrade" ) ]]; then
PRINT SUCCESS "Blueprint has completed its installation process."
fi

# Let the panel know the user has finished installation.
dbAdd "blueprint.setupFinished"
sed -i "s~NOTINSTALLED~INSTALLED~g" "$FOLDER/app/BlueprintFramework/Services/PlaceholderService/BlueprintPlaceholderService.php"
exit 0
fi
fi
Expand Down
26 changes: 26 additions & 0 deletions blueprint/design/schema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
blueprint
internal
seed true boolean
uuid * string
cache * integer
version
latest * string
flags
is_developer false boolean
telemetry_enabled true boolean
notification
text - string




* indicates a value is dynamically changed and
isn't a static value
- indicates an empty value

structure:
record | default | type

purpose of this file:
internal overview of database records managed
and used for blueprint
Loading

0 comments on commit bc05337

Please sign in to comment.