2023-08-07 13:31:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Team\Storage;
|
|
|
|
|
|
|
|
use App\Models\S3Storage;
|
2023-08-08 09:51:36 +00:00
|
|
|
use Livewire\Component;
|
2023-08-07 13:31:42 +00:00
|
|
|
|
|
|
|
class Form extends Component
|
|
|
|
{
|
|
|
|
public S3Storage $storage;
|
|
|
|
protected $rules = [
|
|
|
|
'storage.name' => 'nullable|min:3|max:255',
|
|
|
|
'storage.description' => 'nullable|min:3|max:255',
|
|
|
|
'storage.region' => 'required|max:255',
|
|
|
|
'storage.key' => 'required|max:255',
|
|
|
|
'storage.secret' => 'required|max:255',
|
|
|
|
'storage.bucket' => 'required|max:255',
|
|
|
|
'storage.endpoint' => 'required|url|max:255',
|
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
|
|
|
'storage.name' => 'Name',
|
|
|
|
'storage.description' => 'Description',
|
|
|
|
'storage.region' => 'Region',
|
|
|
|
'storage.key' => 'Key',
|
|
|
|
'storage.secret' => "Secret",
|
|
|
|
'storage.bucket' => 'Bucket',
|
|
|
|
'storage.endpoint' => 'Endpoint',
|
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function test_s3_connection()
|
|
|
|
{
|
2023-08-07 13:31:42 +00:00
|
|
|
try {
|
|
|
|
$this->storage->testConnection();
|
|
|
|
return $this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-08-07 13:31:42 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
2023-08-07 13:31:42 +00:00
|
|
|
try {
|
|
|
|
$this->storage->delete();
|
|
|
|
return redirect()->route('team.storages.all');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-08-07 13:31:42 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-08-07 13:31:42 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
try {
|
|
|
|
$this->storage->testConnection();
|
|
|
|
$this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.');
|
|
|
|
$this->storage->save();
|
|
|
|
$this->emit('success', 'Storage settings saved.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-08-07 13:31:42 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|