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;
|
namespace App\Livewire\Storage;
|
||||||
|
|
||||||
use App\Models\S3Storage;
|
use App\Models\S3Storage;
|
||||||
|
use Illuminate\Support\Uri;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Create extends Component
|
class Create extends Component
|
||||||
@@ -45,9 +46,24 @@ class Create extends Component
|
|||||||
|
|
||||||
public function updatedEndpoint($value)
|
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://')) {
|
if (! str($value)->startsWith('https://') && ! str($value)->startsWith('http://')) {
|
||||||
$this->endpoint = 'https://'.$value;
|
$value = 'https://'.$value;
|
||||||
$value = $this->endpoint;
|
}
|
||||||
|
$this->endpoint = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user