forked from coollabsio/coolify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a7e7e9
commit f6e888e
Showing
24 changed files
with
916 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Models\S3Storage; | ||
use Illuminate\Support\Facades\Storage; | ||
use Livewire\WithFileUploads; | ||
use Livewire\Component; | ||
|
||
class S3Test extends Component | ||
{ | ||
use WithFileUploads; | ||
public $s3; | ||
public $file; | ||
public function mount() { | ||
$this->s3 = S3Storage::first(); | ||
ray($this->s3); | ||
} | ||
public function save() { | ||
try { | ||
$this->validate([ | ||
'file' => 'required|max:150', // 1MB Max | ||
]); | ||
set_s3_target($this->s3); | ||
$this->file->storeAs('files', $this->file->getClientOriginalName(),'custom-s3'); | ||
$this->emit('success', 'File uploaded successfully.'); | ||
} catch (\Throwable $th) { | ||
return general_error_handler($th, $this, false); | ||
} | ||
|
||
} | ||
public function get_files() | ||
{ | ||
set_s3_target($this->s3); | ||
dd(Storage::disk('custom-s3')->files('files')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Team\Storage; | ||
|
||
use Livewire\Component; | ||
use App\Models\S3Storage; | ||
|
||
class Create extends Component | ||
{ | ||
public string $name; | ||
public string $description; | ||
public string $region = 'us-east-1'; | ||
public string $key; | ||
public string $secret; | ||
public string $bucket; | ||
public string $endpoint; | ||
public S3Storage $storage; | ||
protected $rules = [ | ||
'name' => 'nullable|min:3|max:255', | ||
'description' => 'nullable|min:3|max:255', | ||
'region' => 'required|max:255', | ||
'key' => 'required|max:255', | ||
'secret' => 'required|max:255', | ||
'bucket' => 'required|max:255', | ||
'endpoint' => 'nullable|url|max:255', | ||
]; | ||
protected $validationAttributes = [ | ||
'name' => 'Name', | ||
'description' => 'Description', | ||
'region' => 'Region', | ||
'key' => 'Key', | ||
'secret' => "Secret", | ||
'bucket' => 'Bucket', | ||
'endpoint' => 'Endpoint', | ||
]; | ||
public function mount() { | ||
if (isDev()) { | ||
$this->name = 'Local MinIO'; | ||
$this->description = 'Local MinIO'; | ||
$this->key = 'minioadmin'; | ||
$this->secret = 'minioadmin'; | ||
$this->bucket = 'local'; | ||
$this->endpoint = 'http://coolify-minio:9000'; | ||
} | ||
} | ||
private function test_s3_connection() { | ||
try { | ||
$this->storage->testConnection(); | ||
return $this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.'); | ||
} catch(\Throwable $th) { | ||
return general_error_handler($th, $this); | ||
} | ||
} | ||
public function submit() { | ||
try { | ||
$this->validate(); | ||
$this->storage = new S3Storage(); | ||
$this->storage->name = $this->name; | ||
$this->storage->description = $this->description; | ||
$this->storage->region = $this->region; | ||
$this->storage->key = $this->key; | ||
$this->storage->secret = $this->secret; | ||
$this->storage->bucket = $this->bucket; | ||
if (empty($this->endpoint)) { | ||
$this->storage->endpoint = "https://s3.{$this->region}.amazonaws.com"; | ||
} else { | ||
$this->storage->endpoint = $this->endpoint; | ||
} | ||
$this->storage->team_id = auth()->user()->currentTeam()->id; | ||
$this->storage->testConnection(); | ||
$this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.'); | ||
$this->storage->save(); | ||
return redirect()->route('team.storages.show', $this->storage->uuid); | ||
} catch(\Throwable $th) { | ||
return general_error_handler($th, $this); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Team\Storage; | ||
|
||
use Livewire\Component; | ||
use App\Models\S3Storage; | ||
|
||
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', | ||
]; | ||
public function test_s3_connection() { | ||
try { | ||
$this->storage->testConnection(); | ||
return $this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.'); | ||
} catch(\Throwable $th) { | ||
return general_error_handler($th, $this); | ||
} | ||
} | ||
public function delete() { | ||
try { | ||
$this->storage->delete(); | ||
return redirect()->route('team.storages.all'); | ||
} catch(\Throwable $th) { | ||
return general_error_handler($th, $this); | ||
} | ||
} | ||
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.'); | ||
} catch (\Throwable $th) { | ||
return general_error_handler($th, $this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
|
||
class S3Storage extends BaseModel | ||
{ | ||
use HasFactory; | ||
protected $guarded = []; | ||
|
||
static public function ownedByCurrentTeam(array $select = ['*']) | ||
{ | ||
$selectArray = collect($select)->concat(['id']); | ||
return S3Storage::whereTeamId(session('currentTeam')->id)->select($selectArray->all())->orderBy('name'); | ||
} | ||
public function awsUrl() { | ||
return "{$this->endpoint}/{$this->bucket}"; | ||
} | ||
public function testConnection() { | ||
set_s3_target($this); | ||
return \Storage::disk('custom-s3')->files(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
use App\Models\S3Storage; | ||
use Illuminate\Support\Str; | ||
|
||
function set_s3_target(S3Storage $s3) { | ||
$is_digital_ocean = false; | ||
if ($s3->endpoint) { | ||
$is_digital_ocean = Str::contains($s3->endpoint,'digitaloceanspaces.com'); | ||
} | ||
config()->set('filesystems.disks.custom-s3', [ | ||
'driver' => 's3', | ||
'region' => $s3['region'], | ||
'key' => $s3['key'], | ||
'secret' => $s3['secret'], | ||
'bucket' => $s3['bucket'], | ||
'endpoint' => $s3['endpoint'], | ||
'use_path_style_endpoint' => true, | ||
'bucket_endpoint' => $is_digital_ocean, | ||
'aws_url' => $s3->awsUrl(), | ||
]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.