2023-08-07 13:31:42 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Team\Storage;
|
2023-08-07 13:31:42 +00:00
|
|
|
|
|
|
|
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 = [
|
2023-10-10 11:10:43 +00:00
|
|
|
'storage.is_usable' => 'nullable|boolean',
|
2023-08-07 13:31:42 +00:00
|
|
|
'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 = [
|
2023-10-10 11:10:43 +00:00
|
|
|
'storage.is_usable' => 'Is Usable',
|
2023-08-07 13:31:42 +00:00
|
|
|
'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 {
|
2023-11-15 08:34:27 +00:00
|
|
|
$this->storage->testConnection(shouldSave: true);
|
2024-01-31 15:14:12 +00:00
|
|
|
return $this->dispatch('success', 'Connection is working.', 'Tested with "ListObjectsV2" action.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2024-01-31 15:14:12 +00:00
|
|
|
$this->dispatch('error', 'Failed to create storage.', $e->getMessage());
|
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();
|
2024-01-07 15:23:41 +00:00
|
|
|
return redirect()->route('team.storage.index');
|
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 {
|
2023-11-15 08:34:27 +00:00
|
|
|
$this->test_s3_connection();
|
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
|
|
|
}
|