coolify/app/Livewire/Storage/Form.php

62 lines
1.7 KiB
PHP
Raw Normal View History

2023-08-07 15:31:42 +02:00
<?php
2024-04-26 14:09:54 +02:00
namespace App\Livewire\Storage;
2023-08-07 15:31:42 +02:00
use App\Models\S3Storage;
use Livewire\Component;
2023-08-07 15:31:42 +02:00
class Form extends Component
{
public S3Storage $storage;
protected $rules = [
2023-10-10 13:10:43 +02:00
'storage.is_usable' => 'nullable|boolean',
2023-08-07 15:31:42 +02: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 13:10:43 +02:00
'storage.is_usable' => 'Is Usable',
2023-08-07 15:31:42 +02:00
'storage.name' => 'Name',
'storage.description' => 'Description',
'storage.region' => 'Region',
'storage.key' => 'Key',
'storage.secret' => "Secret",
'storage.bucket' => 'Bucket',
'storage.endpoint' => 'Endpoint',
];
public function test_s3_connection()
{
2023-08-07 15:31:42 +02:00
try {
$this->storage->testConnection(shouldSave: true);
2024-01-31 16:14:12 +01:00
return $this->dispatch('success', 'Connection is working.', 'Tested with "ListObjectsV2" action.');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
2024-01-31 16:14:12 +01:00
$this->dispatch('error', 'Failed to create storage.', $e->getMessage());
2023-08-07 15:31:42 +02:00
}
}
public function delete()
{
2023-08-07 15:31:42 +02:00
try {
$this->storage->delete();
2024-04-26 14:09:54 +02:00
return redirect()->route('storage.index');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-08-07 15:31:42 +02:00
}
}
2023-08-07 15:31:42 +02:00
public function submit()
{
$this->validate();
try {
$this->test_s3_connection();
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-08-07 15:31:42 +02:00
}
}
}