refactor(s3): improve S3 bucket endpoint formatting
- remove the bucket name from the DigitalOcean endpoint - always add https in front if it is not http or already https
This commit is contained in:
@@ -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)
|
||||
{
|
||||
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://')) {
|
||||
$this->endpoint = 'https://'.$value;
|
||||
$value = $this->endpoint;
|
||||
$value = 'https://'.$value;
|
||||
}
|
||||
$this->endpoint = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user