From 7767bb29ec7fb5e039bd0c8ba2d1d97837a33a7b Mon Sep 17 00:00:00 2001 From: Robert Lyons Date: Thu, 12 Dec 2024 11:31:14 +0000 Subject: [PATCH 1/5] Allow for specifying file upload values in .env --- config/zeus-bolt.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/zeus-bolt.php b/config/zeus-bolt.php index b27c0320..fb3139d5 100644 --- a/config/zeus-bolt.php +++ b/config/zeus-bolt.php @@ -53,11 +53,11 @@ 'defaultMailable' => \LaraZeus\Bolt\Mail\FormSubmission::class, - 'uploadDisk' => 'public', + 'uploadDisk' => env('BOLT_FILESYSTEM_DISK', 'public'), - 'uploadDirectory' => 'forms', + 'uploadDirectory' => env('BOLT_FILESYSTEM_PREFIX', 'forms'), - 'uploadVisibility' => 'public', + 'uploadVisibility' => env('BOLT_FILESYSTEM_VISIBILITY', 'public'), 'show_presets' => false, From 6af58e927e970634031d6b502156ac19310b5e1e Mon Sep 17 00:00:00 2001 From: Robert Lyons Date: Thu, 12 Dec 2024 11:34:28 +0000 Subject: [PATCH 2/5] check for upload visibility when generating file urls --- resources/views/filament/fields/file-upload.blade.php | 8 ++++++-- src/Fields/Classes/FileUpload.php | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/resources/views/filament/fields/file-upload.blade.php b/resources/views/filament/fields/file-upload.blade.php index 7f04faee..1afb6dd3 100644 --- a/resources/views/filament/fields/file-upload.blade.php +++ b/resources/views/filament/fields/file-upload.blade.php @@ -6,7 +6,11 @@ target="_blank" size="sm" outlined - href="{{ Storage::disk(config('zeus-bolt.uploadDisk'))->url($file) }}" + @if(config('zeus-bolt.uploadVisibility') === 'private') + href="{{ $disk->temporaryUrl($file, now()->addMinute()) }}" + @else + href="{{ $disk->url($file) }}" + @endif > {{ __('view file') .': '. $loop->iteration }} @@ -15,4 +19,4 @@ @else {{ __('no file uploaded') }} @endif - \ No newline at end of file + diff --git a/src/Fields/Classes/FileUpload.php b/src/Fields/Classes/FileUpload.php index 804b7e39..d1a09471 100644 --- a/src/Fields/Classes/FileUpload.php +++ b/src/Fields/Classes/FileUpload.php @@ -3,6 +3,7 @@ namespace LaraZeus\Bolt\Fields\Classes; use Filament\Forms\Components\Hidden; +use Illuminate\Support\Facades\Storage; use LaraZeus\Accordion\Forms\Accordion; use LaraZeus\Accordion\Forms\Accordions; use LaraZeus\Bolt\Facades\Bolt; @@ -68,11 +69,13 @@ public static function getOptionsHidden(): array public function getResponse(Field $field, FieldResponse $resp): string { $responseValue = filled($resp->response) ? Bolt::isJson($resp->response) ? json_decode($resp->response) : [$resp->response] : []; + $disk = Storage::disk(config('zeus-bolt.uploadDisk')); return view('zeus::filament.fields.file-upload') ->with('resp', $resp) ->with('responseValue', $responseValue) ->with('field', $field) + ->with('disk', $disk) ->render(); } From c9c2741f27b3c0457e94964c4777510496644ad2 Mon Sep 17 00:00:00 2001 From: Robert Lyons Date: Thu, 12 Dec 2024 12:06:55 +0000 Subject: [PATCH 3/5] don't use directive as this breaks, use closure instead --- resources/views/filament/fields/file-upload.blade.php | 6 +----- src/Fields/Classes/FileUpload.php | 7 ++++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/resources/views/filament/fields/file-upload.blade.php b/resources/views/filament/fields/file-upload.blade.php index 1afb6dd3..aabf3ef0 100644 --- a/resources/views/filament/fields/file-upload.blade.php +++ b/resources/views/filament/fields/file-upload.blade.php @@ -6,11 +6,7 @@ target="_blank" size="sm" outlined - @if(config('zeus-bolt.uploadVisibility') === 'private') - href="{{ $disk->temporaryUrl($file, now()->addMinute()) }}" - @else - href="{{ $disk->url($file) }}" - @endif + href="{{ $getUrl($file) }}" > {{ __('view file') .': '. $loop->iteration }} diff --git a/src/Fields/Classes/FileUpload.php b/src/Fields/Classes/FileUpload.php index d1a09471..cadb0130 100644 --- a/src/Fields/Classes/FileUpload.php +++ b/src/Fields/Classes/FileUpload.php @@ -69,13 +69,18 @@ public static function getOptionsHidden(): array public function getResponse(Field $field, FieldResponse $resp): string { $responseValue = filled($resp->response) ? Bolt::isJson($resp->response) ? json_decode($resp->response) : [$resp->response] : []; + $disk = Storage::disk(config('zeus-bolt.uploadDisk')); + $getUrl = fn($file) => config('zeus-bolt.uploadVisibility') === 'private' + ? $disk->temporaryUrl($file, now()->addMinute()) + : $disk->url($file); + return view('zeus::filament.fields.file-upload') ->with('resp', $resp) ->with('responseValue', $responseValue) ->with('field', $field) - ->with('disk', $disk) + ->with('getUrl', $getUrl) ->render(); } From 48d743661b4c49c449f6a582f813fce2261af732 Mon Sep 17 00:00:00 2001 From: Rob Lyons <39706150+aSeriousDeveloper@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:30:43 +0000 Subject: [PATCH 4/5] Increase time before url expiry to 1 day --- src/Fields/Classes/FileUpload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fields/Classes/FileUpload.php b/src/Fields/Classes/FileUpload.php index cadb0130..ec7c2d1e 100644 --- a/src/Fields/Classes/FileUpload.php +++ b/src/Fields/Classes/FileUpload.php @@ -73,7 +73,7 @@ public function getResponse(Field $field, FieldResponse $resp): string $disk = Storage::disk(config('zeus-bolt.uploadDisk')); $getUrl = fn($file) => config('zeus-bolt.uploadVisibility') === 'private' - ? $disk->temporaryUrl($file, now()->addMinute()) + ? $disk->temporaryUrl($file, now()->addDay()) : $disk->url($file); return view('zeus::filament.fields.file-upload') From 6b886307d108cdd3b9702ff113ab3149e5faa63d Mon Sep 17 00:00:00 2001 From: Rob Lyons <39706150+aSeriousDeveloper@users.noreply.github.com> Date: Mon, 23 Dec 2024 12:57:26 +0000 Subject: [PATCH 5/5] Update zeus-bolt.php Change .env convar to DIRECTORY instead of PREFIX --- config/zeus-bolt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/zeus-bolt.php b/config/zeus-bolt.php index fb3139d5..cca2730a 100644 --- a/config/zeus-bolt.php +++ b/config/zeus-bolt.php @@ -55,7 +55,7 @@ 'uploadDisk' => env('BOLT_FILESYSTEM_DISK', 'public'), - 'uploadDirectory' => env('BOLT_FILESYSTEM_PREFIX', 'forms'), + 'uploadDirectory' => env('BOLT_FILESYSTEM_DIRECTORY', 'forms'), 'uploadVisibility' => env('BOLT_FILESYSTEM_VISIBILITY', 'public'),