31
31
use Zhiyi \Plus \FileStorage \FileMetaInterface ;
32
32
use Zhiyi \Plus \FileStorage \ResourceInterface ;
33
33
use Symfony \Component \HttpFoundation \Response ;
34
+ use Symfony \Component \HttpFoundation \BinaryFileResponse ;
34
35
use Illuminate \Contracts \Filesystem \Filesystem as FilesystemContract ;
35
36
36
37
class LocalFilesystem implements FilesystemInterface
@@ -81,6 +82,7 @@ public function meta(ResourceInterface $resource): FileMetaInterface
81
82
*/
82
83
public function response (ResourceInterface $ resource , ?string $ rule = null ): Response
83
84
{
85
+ $ realPath = $ this ->filesystem ->path ($ resource ->getPath ());
84
86
if ($ this ->meta ($ resource )->hasImage ()) {
85
87
$ rule = new Local \RuleParser ($ rule );
86
88
if (
@@ -93,13 +95,12 @@ public function response(ResourceInterface $resource, ?string $rule = null): Res
93
95
return $ this ->filesystem ->response ($ resource ->getPath ());
94
96
}
95
97
96
- $ pathinfo = \League \Flysystem \Util::pathinfo ($ resource -> getPath () );
98
+ $ pathinfo = \League \Flysystem \Util::pathinfo ($ realPath );
97
99
$ cachePath = sprintf ('%s/%s/%s.%s ' , $ pathinfo ['dirname ' ], $ pathinfo ['filename ' ], $ rule ->getFilename (), $ pathinfo ['extension ' ]);
98
100
if ($ this ->filesystem ->has ($ cachePath )) {
99
101
return $ this ->filesystem ->response ($ cachePath );
100
102
}
101
103
102
- $ realPath = $ this ->filesystem ->path ($ resource ->getPath ());
103
104
$ image = Image::make ($ realPath );
104
105
$ image ->blur ($ rule ->getBlur ());
105
106
if (($ image ->width () > $ rule ->getWidth () || $ image ->height () > $ rule ->getHeight ()) && ($ rule ->getWidth () || $ rule ->getHeight ())) {
@@ -114,7 +115,7 @@ public function response(ResourceInterface $resource, ?string $rule = null): Res
114
115
return $ image ->response ();
115
116
}
116
117
117
- return $ this -> filesystem -> response ( $ resource -> getPath () );
118
+ return new BinaryFileResponse ( $ realPath );
118
119
}
119
120
120
121
/**
0 commit comments