fix: service templates

This commit is contained in:
Andras Bacsai 2023-09-28 22:20:49 +02:00
parent 91e1eb7664
commit 38a22dcf4d
4 changed files with 25 additions and 28 deletions

View File

@ -48,15 +48,15 @@ public function handle()
$versions = "versions.json";
PendingRequest::macro('storage', function ($fileName) use($that) {
PendingRequest::macro('storage', function ($file) use($that) {
$headers = [
'AccessKey' => env('BUNNY_STORAGE_API_KEY'),
'Accept' => 'application/json',
'Content-Type' => 'application/octet-stream'
];
$fileStream = fopen($fileName, "r");
$file = fread($fileStream, filesize($fileName));
$that->info('Uploading: ' . $fileName);
$fileStream = fopen($file, "r");
$file = fread($fileStream, filesize($file));
$that->info('Uploading: ' . $file);
return PendingRequest::baseUrl('https://storage.bunnycdn.com')->withHeaders($headers)->withBody($file)->throw();
});
PendingRequest::macro('purge', function ($url) use ($that) {

View File

@ -45,10 +45,10 @@ public function show()
public function new()
{
$services = Cache::get('services', []);
$services = getServiceTemplates();
$type = Str::of(request()->query('type'));
$destination_uuid = request()->query('destination');
$server_id = request()->query('server');
$server_id = request()->query('server_id');
$project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) {
@ -66,9 +66,10 @@ public function new()
'database_uuid' => $standalone_postgresql->uuid,
]);
}
if ($type->startsWith('one-click-service-')) {
if ($type->startsWith('one-click-service-') && !is_null( (int)$server_id)) {
$oneClickServiceName = $type->after('one-click-service-')->value();
$oneClickService = data_get($services, "$oneClickServiceName.compose");
ray($oneClickServiceName);
$oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null);
if ($oneClickDotEnvs) {
$oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/');

View File

@ -60,28 +60,9 @@ public function loadServices(bool $forceReload = false)
if ($forceReload) {
Cache::forget('services');
}
if (isDev()) {
$cached = Cache::remember('services', 3600, function () {
$services = File::get(base_path('templates/service-templates.json'));
$services = collect(json_decode($services))->sortKeys();
$this->emit('success', 'Successfully reloaded services from filesystem (development mode).');
return $services;
});
} else {
$cached = Cache::remember('services', 3600, function () {
$services = Http::get(config('constants.services.official'));
if ($services->failed()) {
throw new \Exception($services->body());
}
$services = collect($services->json())->sortKeys();
$this->emit('success', 'Successfully reloaded services from the internet.');
return $services;
});
}
$this->services = $cached;
$this->services = getServiceTemplates();
$this->emit('success', 'Successfully loaded services.');
} catch (\Throwable $e) {
ray($e);
return handleError($e, $this);
} finally {
$this->loadingServices = false;

View File

@ -406,3 +406,18 @@ function sslip(Server $server)
}
return "{$server->ip}.sslip.io";
}
function getServiceTemplates()
{
if (isDev()) {
$services = File::get(base_path('templates/service-templates.json'));
$services = collect(json_decode($services))->sortKeys();
} else {
$services = Http::get(config('constants.services.official'));
if ($services->failed()) {
throw new \Exception($services->body());
}
$services = collect($services->json())->sortKeys();
}
return $services;
}