From 14d1408f46c58b845516d8b91f3f2feb84ac5382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20J=C3=B8nsson?= Date: Wed, 20 Apr 2022 10:13:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Setup=20config=20for=20storage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/SyncFilesToOtherDisk.php | 38 +++++++++++++++++++ app/Models/File.php | 25 ++++++++++++ config/filepond.php | 2 +- config/filesystems.php | 1 + 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/SyncFilesToOtherDisk.php create mode 100644 app/Models/File.php diff --git a/app/Console/Commands/SyncFilesToOtherDisk.php b/app/Console/Commands/SyncFilesToOtherDisk.php new file mode 100644 index 0000000..23e1879 --- /dev/null +++ b/app/Console/Commands/SyncFilesToOtherDisk.php @@ -0,0 +1,38 @@ +each(function(File $file) use ($newDisk) { + if(!$file->file_exists) { + return; + } + + $stored = Storage::disk($newDisk)->put($file->path, $file->content); + + if($stored) { + $file->disk = $newDisk; + $file->save(); + } + }); + } +} diff --git a/app/Models/File.php b/app/Models/File.php new file mode 100644 index 0000000..a1c2940 --- /dev/null +++ b/app/Models/File.php @@ -0,0 +1,25 @@ +disk === 's3') { + return $this->storage->temporaryUrl($this->path, now()->addMinute()); + } + + return $this->storage->url($this->path); + } +} + diff --git a/config/filepond.php b/config/filepond.php index 9dfd0f0..e347375 100644 --- a/config/filepond.php +++ b/config/filepond.php @@ -20,7 +20,7 @@ | Here you may specify the filesystem disk that should be used. | */ - 'disk' => 'uploads', + 'disk' => env('FILEPOND_DISK', 'uploads'), /* |-------------------------------------------------------------------------- diff --git a/config/filesystems.php b/config/filesystems.php index 6b4e20c..98f5e1f 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -67,6 +67,7 @@ 'region' => env('AWS_DEFAULT_REGION'), 'bucket' => env('AWS_BUCKET'), 'url' => env('AWS_URL'), + 'endpoint' => env('AWS_URL'), ], 'uploads' => [