From 2be2f0ac7900d4e8cc62a14e5009be3120afdd21 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 2 Oct 2024 10:25:45 +0200 Subject: [PATCH] feat: support Hetzner S3 --- app/Livewire/Storage/Create.php | 18 ++++++++++-------- bootstrap/helpers/s3.php | 3 ++- .../views/livewire/storage/create.blade.php | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/Livewire/Storage/Create.php b/app/Livewire/Storage/Create.php index a05834ecc..c5250e1e3 100644 --- a/app/Livewire/Storage/Create.php +++ b/app/Livewire/Storage/Create.php @@ -43,15 +43,17 @@ class Create extends Component 'endpoint' => 'Endpoint', ]; - public function mount() + public function updatedEndpoint($value) { - if (isDev()) { - $this->name = 'Local MinIO'; - $this->description = 'Local MinIO'; - $this->key = 'minioadmin'; - $this->secret = 'minioadmin'; - $this->bucket = 'local'; - $this->endpoint = 'http://coolify-minio:9000'; + if (! str($value)->startsWith('https://') && ! str($value)->startsWith('http://')) { + $this->endpoint = 'https://'.$value; + $value = $this->endpoint; + } + + if (str($value)->contains('your-objectstorage.com') && ! isset($this->bucket)) { + $this->bucket = str($value)->after('//')->before('.'); + } elseif (str($value)->contains('your-objectstorage.com')) { + $this->bucket = $this->bucket ?: str($value)->after('//')->before('.'); } } diff --git a/bootstrap/helpers/s3.php b/bootstrap/helpers/s3.php index 4a2252016..e4469cd6b 100644 --- a/bootstrap/helpers/s3.php +++ b/bootstrap/helpers/s3.php @@ -8,6 +8,7 @@ function set_s3_target(S3Storage $s3) $is_digital_ocean = false; if ($s3->endpoint) { $is_digital_ocean = Str::contains($s3->endpoint, 'digitaloceanspaces.com'); + $is_hetzner = Str::contains($s3->endpoint, 'your-objectstorage.com'); } config()->set('filesystems.disks.custom-s3', [ 'driver' => 's3', @@ -17,7 +18,7 @@ function set_s3_target(S3Storage $s3) 'bucket' => $s3['bucket'], 'endpoint' => $s3['endpoint'], 'use_path_style_endpoint' => true, - 'bucket_endpoint' => $is_digital_ocean, + 'bucket_endpoint' => $is_digital_ocean || $is_hetzner, 'aws_url' => $s3->awsUrl(), ]); } diff --git a/resources/views/livewire/storage/create.blade.php b/resources/views/livewire/storage/create.blade.php index 107bec296..41d09e679 100644 --- a/resources/views/livewire/storage/create.blade.php +++ b/resources/views/livewire/storage/create.blade.php @@ -4,7 +4,7 @@ - +