Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

refactor(s3): improve S3 bucket endpoint formatting

peaklabs-devd5504ea546d8
diff --git a/app/Livewire/Storage/Create.php b/app/Livewire/Storage/Create.php
index d0fdbcdf7d..1d60d6ac5f 100644
--- a/app/Livewire/Storage/Create.php
+++ b/app/Livewire/Storage/Create.php
@@ -3,6 +3,7 @@
namespace App\Livewire\Storage;
use App\Models\S3Storage;
+use Illuminate\Support\Uri;
use Livewire\Component;
class Create extends Component
@@ -45,9 +46,24 @@ class Create extends Component
public function updatedEndpoint($value)
{
- if (! str($value)->startsWith('https://') && ! str($value)->startsWith('http://')) {
- $this->endpoint = 'https://'.$value;
- $value = $this->endpoint;
+ try {
+ if (empty($value)) {
+ return;
+ }
+ if (str($value)->contains('digitaloceanspaces.com')) {
+ $uri = Uri::of($value);
+ $host = $uri->host();
+
+ if (preg_match('/^(.+)\.([^.]+\.digitaloceanspaces\.com)$/', $host, $matches)) {
+ $host = $matches[2];
+ $value = "https://{$host}";
+ }
+ }
+ } finally {
+ if (! str($value)->startsWith('https://') && ! str($value)->startsWith('http://')) {
+ $value = 'https://'.$value;
+ }
+ $this->endpoint = $value;
}
}