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

View File

@ -45,10 +45,10 @@ public function show()
public function new() public function new()
{ {
$services = Cache::get('services', []); $services = getServiceTemplates();
$type = Str::of(request()->query('type')); $type = Str::of(request()->query('type'));
$destination_uuid = request()->query('destination'); $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(); $project = currentTeam()->load(['projects'])->projects->where('uuid', request()->route('project_uuid'))->first();
if (!$project) { if (!$project) {
@ -66,9 +66,10 @@ public function new()
'database_uuid' => $standalone_postgresql->uuid, '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(); $oneClickServiceName = $type->after('one-click-service-')->value();
$oneClickService = data_get($services, "$oneClickServiceName.compose"); $oneClickService = data_get($services, "$oneClickServiceName.compose");
ray($oneClickServiceName);
$oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null); $oneClickDotEnvs = data_get($services, "$oneClickServiceName.envs", null);
if ($oneClickDotEnvs) { if ($oneClickDotEnvs) {
$oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/'); $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) { if ($forceReload) {
Cache::forget('services'); Cache::forget('services');
} }
if (isDev()) { $this->services = getServiceTemplates();
$cached = Cache::remember('services', 3600, function () { $this->emit('success', 'Successfully loaded services.');
$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;
} catch (\Throwable $e) { } catch (\Throwable $e) {
ray($e);
return handleError($e, $this); return handleError($e, $this);
} finally { } finally {
$this->loadingServices = false; $this->loadingServices = false;

View File

@ -406,3 +406,18 @@ function sslip(Server $server)
} }
return "{$server->ip}.sslip.io"; 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;
}