File tree Expand file tree Collapse file tree 3 files changed +27
-11
lines changed Expand file tree Collapse file tree 3 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 11<?php
2-
32declare (strict_types=1 );
43
54use Illuminate \Support \Facades \Route ;
65use Imahmood \FileStorage \Controllers \DownloadController ;
76
8- Route::get ('/media/public/{mediaId}/{fileName} ' , DownloadController::class)
9- ->name ('file-storage:public ' );
10-
11- Route::get ('/media/{mediaId}/{fileName} ' , DownloadController::class)
7+ Route::get ('/assets/{disk}/{path} ' , DownloadController::class)
128 ->middleware ('signed ' )
9+ ->where ('path ' , '.* ' )
1310 ->name ('file-storage:private ' );
Original file line number Diff line number Diff line change 55
66use Illuminate \Routing \Controller ;
77use Illuminate \Support \Facades \Storage ;
8- use Imahmood \FileStorage \Config \Configuration ;
98use Imahmood \FileStorage \Exceptions \FileNotFoundException ;
109use Symfony \Component \HttpFoundation \BinaryFileResponse ;
1110
@@ -14,16 +13,14 @@ class DownloadController extends Controller
1413 /**
1514 * @throws \Imahmood\FileStorage\Exceptions\FileNotFoundException
1615 */
17- public function __invoke (Configuration $ config , int $ mediaId , string $ fileName ): BinaryFileResponse
16+ public function __invoke (string $ disk , string $ path ): BinaryFileResponse
1817 {
19- $ path = $ mediaId .DIRECTORY_SEPARATOR .$ fileName ;
20-
21- if (! Storage::disk ($ config ->diskName )->exists ($ path )) {
18+ if (! Storage::disk ($ disk )->exists ($ path )) {
2219 throw new FileNotFoundException ();
2320 }
2421
2522 return response ()->file (
26- Storage::disk ($ config -> diskName )->path ($ path )
23+ Storage::disk ($ disk )->path ($ path )
2724 );
2825 }
2926}
Original file line number Diff line number Diff line change 33
44namespace Imahmood \FileStorage ;
55
6+ use DateTimeInterface ;
7+ use Illuminate \Support \Facades \Storage ;
8+ use Illuminate \Support \Facades \URL ;
69use Illuminate \Support \ServiceProvider ;
710use Imahmood \FileStorage \Config \Configuration ;
811use Imahmood \FileStorage \Config \ConfigurationFactory ;
@@ -33,5 +36,24 @@ public function boot(): void
3336 $ this ->publishes ([
3437 __DIR__ .'/../config/file-storage.php ' => config_path ('file-storage.php ' ),
3538 ]);
39+
40+ $ this ->registerTemporaryUrlCallbacks ();
41+ }
42+
43+ protected function registerTemporaryUrlCallbacks (): void
44+ {
45+ foreach (config ('filesystems.disks ' ) as $ disk => $ options ) {
46+ if ($ options ['driver ' ] !== 'local ' ) {
47+ continue ;
48+ }
49+
50+ Storage::disk ($ disk )->buildTemporaryUrlsUsing (
51+ fn (string $ path , DateTimeInterface $ expiration ) => URL ::signedRoute (
52+ name: 'file-storage:private ' ,
53+ parameters: [$ disk , $ path ],
54+ expiration: $ expiration ,
55+ ),
56+ );
57+ }
3658 }
3759}
You can’t perform that action at this time.
0 commit comments