Skip to content

Commit

Permalink
Merge pull request #334 from aSeriousDeveloper/private-uploads
Browse files Browse the repository at this point in the history
Support for  downloading File Uploads to Private Filedisks
  • Loading branch information
atmonshi authored Dec 24, 2024
2 parents d71bdcb + 6b88630 commit 1e1e334
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions config/zeus-bolt.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@

'defaultMailable' => \LaraZeus\Bolt\Mail\FormSubmission::class,

'uploadDisk' => 'public',
'uploadDisk' => env('BOLT_FILESYSTEM_DISK', 'public'),

'uploadDirectory' => 'forms',
'uploadDirectory' => env('BOLT_FILESYSTEM_DIRECTORY', 'forms'),

'uploadVisibility' => 'public',
'uploadVisibility' => env('BOLT_FILESYSTEM_VISIBILITY', 'public'),

'show_presets' => false,

Expand Down
4 changes: 2 additions & 2 deletions resources/views/filament/fields/file-upload.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
target="_blank"
size="sm"
outlined
href="{{ Storage::disk(config('zeus-bolt.uploadDisk'))->url($file) }}"
href="{{ $getUrl($file) }}"
>
{{ __('view file') .': '. $loop->iteration }}
</x-filament::link>
Expand All @@ -15,4 +15,4 @@
@else
<span class="text-gray-500">{{ __('no file uploaded') }}</span>
@endif
</div>
</div>
8 changes: 8 additions & 0 deletions src/Fields/Classes/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,10 +70,17 @@ 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()->addDay())
: $disk->url($file);

return view('zeus::filament.fields.file-upload')
->with('resp', $resp)
->with('responseValue', $responseValue)
->with('field', $field)
->with('getUrl', $getUrl)
->render();
}

Expand Down

0 comments on commit 1e1e334

Please sign in to comment.