77use Illuminate \Contracts \Filesystem \Factory as FilesystemManager ;
88use Illuminate \Contracts \Filesystem \FileNotFoundException ;
99use Illuminate \Contracts \Filesystem \Filesystem ;
10- use Illuminate \Http \Request ;
1110use Illuminate \Http \Response ;
1211use Intervention \Image \Encoders \AutoEncoder ;
1312use Intervention \Image \Interfaces \ImageInterface ;
1918use ReliqArts \GuidedImage \Contract \ImageDispenser as ImageDispenserContract ;
2019use ReliqArts \GuidedImage \Contract \ImageManager ;
2120use ReliqArts \GuidedImage \Demand \Dummy ;
21+ use ReliqArts \GuidedImage \Demand \ExistingImage ;
2222use ReliqArts \GuidedImage \Demand \Resize ;
2323use ReliqArts \GuidedImage \Demand \Thumbnail ;
2424use RuntimeException ;
@@ -108,7 +108,7 @@ public function getResizedImage(Resize $demand)
108108 if ($ this ->cacheDisk ->exists ($ cacheFilePath )) {
109109 $ image = $ this ->makeImageWithEncoding ($ this ->cacheDisk ->path ($ cacheFilePath ));
110110 } else {
111- $ image = $ this ->makeImageWithEncoding ($ this ->getImageFullUrl ($ guidedImage ));
111+ $ image = $ this ->makeImageWithEncoding ($ this ->getImageFullPath ($ guidedImage ));
112112 $ sizingMethod = $ demand ->allowUpSizing () ? 'resize ' : 'resizeDown ' ;
113113 if ($ demand ->maintainAspectRatio ()) {
114114 $ sizingMethod = $ demand ->allowUpSizing () ? 'scale ' : 'scaleDown ' ;
@@ -125,7 +125,7 @@ public function getResizedImage(Resize $demand)
125125 return new Response (
126126 $ this ->cacheDisk ->get ($ cacheFilePath ),
127127 self ::RESPONSE_HTTP_OK ,
128- $ this ->getImageHeaders ($ cacheFilePath , $ demand-> getRequest () , $ image ) ?: []
128+ $ this ->getImageHeaders ($ cacheFilePath , $ demand , $ image ) ?: []
129129 );
130130 } catch (RuntimeException $ exception ) {
131131 return $ this ->handleRuntimeException ($ exception , $ guidedImage );
@@ -187,7 +187,7 @@ public function getImageThumbnail(Thumbnail $demand)
187187 } else {
188188 /** @var ImageInterface $image */
189189 $ image = $ this ->imageManager
190- ->read ($ this ->getImageFullUrl ($ guidedImage ))
190+ ->read ($ this ->getImageFullPath ($ guidedImage ))
191191 ->{$ method }(
192192 $ width ,
193193 $ height
@@ -203,7 +203,7 @@ public function getImageThumbnail(Thumbnail $demand)
203203 return new Response (
204204 $ this ->cacheDisk ->get ($ cacheFilePath ),
205205 self ::RESPONSE_HTTP_OK ,
206- $ this ->getImageHeaders ($ cacheFilePath , $ demand-> getRequest () , $ image ) ?: []
206+ $ this ->getImageHeaders ($ cacheFilePath , $ demand , $ image ) ?: []
207207 );
208208 } catch (RuntimeException $ exception ) {
209209 return $ this ->handleRuntimeException ($ exception , $ guidedImage );
@@ -235,13 +235,15 @@ public function emptyCache(): bool
235235 *
236236 * @return array image headers
237237 */
238- private function getImageHeaders (string $ cacheFilePath , Request $ request , ImageInterface $ image ): array
238+ private function getImageHeaders (string $ relativeCacheFilePath , ExistingImage $ demand , ImageInterface $ image ): array
239239 {
240- $ filePath = $ image ->origin ()->filePath ();
241- $ lastModified = $ this ->cacheDisk ->lastModified ($ cacheFilePath );
240+ $ request = $ demand ->getRequest ();
241+ $ fullCacheFilePath = $ this ->cacheDisk ->path ($ relativeCacheFilePath );
242+ $ lastModified = $ this ->cacheDisk ->lastModified ($ relativeCacheFilePath );
242243 $ modifiedSince = $ request ->header ('If-Modified-Since ' , '' );
243244 $ etagHeader = trim ($ request ->header ('If-None-Match ' , '' ));
244- $ etagFile = $ this ->fileHelper ->hashFile ($ filePath );
245+ $ etagFile = $ this ->fileHelper ->hashFile ($ fullCacheFilePath );
246+ $ originalImageRelativePath = $ demand ->getGuidedImage ()->getUrl (true );
245247
246248 // check if image hasn't changed
247249 if ($ etagFile === $ etagHeader || strtotime ($ modifiedSince ) === $ lastModified ) {
@@ -256,7 +258,7 @@ private function getImageHeaders(string $cacheFilePath, Request $request, ImageI
256258 $ this ->getDefaultHeaders (),
257259 [
258260 'Content-Type ' => $ image ->origin ()->mediaType (),
259- 'Content-Disposition ' => sprintf ('inline; filename=%s ' , basename ($ image -> origin ()-> filePath () )),
261+ 'Content-Disposition ' => sprintf ('inline; filename=%s ' , basename ($ originalImageRelativePath )),
260262 'Last-Modified ' => date (DATE_RFC822 , $ lastModified ),
261263 'Etag ' => $ etagFile ,
262264 ]
@@ -307,12 +309,9 @@ private function makeImageWithEncoding(mixed $data): ImageInterface
307309 return $ this ->imageManager ->read ($ encodedImage ->toFilePointer ());
308310 }
309311
310- /**
311- * @throws RuntimeException
312- */
313- private function getImageFullUrl (GuidedImage $ guidedImage ): string
312+ private function getImageFullPath (GuidedImage $ guidedImage ): string
314313 {
315- return $ this ->uploadDisk ->url ($ guidedImage ->getUrl (true ));
314+ return $ this ->uploadDisk ->path ($ guidedImage ->getUrl (true ));
316315 }
317316
318317 /**
@@ -322,8 +321,8 @@ private function handleRuntimeException(
322321 RuntimeException $ exception ,
323322 GuidedImage $ guidedImage
324323 ): BinaryFileResponse {
325- $ errorMessage = 'Intervention image creation failed with NotReadableException ; ' ;
326- $ context = ['imageUrl ' => $ this ->getImageFullUrl ($ guidedImage )];
324+ $ errorMessage = 'Intervention image creation failed with RuntimeException ; ' ;
325+ $ context = ['imageUrl ' => $ this ->getImageFullPath ($ guidedImage )];
327326
328327 if (! $ this ->configProvider ->isRawImageFallbackEnabled ()) {
329328 $ this ->logger ->error (
0 commit comments