Skip to content

Commit 7bb83c7

Browse files
committed
feat(glide): return 404 if file could not be found
1 parent 57a98d4 commit 7bb83c7

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

config/attachment-library.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return [
4+
45
/**
56
* Default disk to use for storing attachments.
67
*
@@ -92,4 +93,5 @@
9293
],
9394
],
9495
],
96+
9597
];

config/glide.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return [
4+
45
'driver' => env('GLIDE_DRIVER', 'gd'),
56
'source' => storage_path('app/public'),
67
/**
@@ -54,4 +55,5 @@
5455
* Example: With [ 'webp' , 'jpg' ] browsers will attempt to load webp before jpg.
5556
*/
5657
'formats' => ['webp', 'jpg'],
58+
5759
];

src/Http/Controllers/GlideController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Http\Request;
66
use Illuminate\Routing\Controllers\HasMiddleware;
77
use Illuminate\Routing\Middleware\ValidateSignature;
8+
use League\Glide\Filesystem\FileNotFoundException;
89
use League\Glide\Server;
910
use Symfony\Component\HttpFoundation\Response;
1011
use VanOns\LaravelAttachmentLibrary\Glide\OptionsParser;
@@ -19,10 +20,14 @@ class GlideController implements HasMiddleware
1920
*/
2021
public function __invoke(Request $request, string $options, string $path, OptionsParser $parser): Response
2122
{
22-
return app(Server::class)->getImageResponse(
23-
$path,
24-
$parser->toArray($options)
25-
);
23+
try {
24+
return app(Server::class)->getImageResponse(
25+
$path,
26+
$parser->toArray($options)
27+
);
28+
} catch (FileNotFoundException) {
29+
abort(404);
30+
}
2631
}
2732

2833
/**

0 commit comments

Comments
 (0)