|
6 | 6 |
|
7 | 7 | use AceOfAces\LaravelImageTransformUrl\Enums\AllowedMimeTypes;
|
8 | 8 | use AceOfAces\LaravelImageTransformUrl\Enums\AllowedOptions;
|
| 9 | +use AceOfAces\LaravelImageTransformUrl\Traits\ManagesImageCache; |
9 | 10 | use AceOfAces\LaravelImageTransformUrl\Traits\ResolvesOptions;
|
10 | 11 | use Illuminate\Http\Request;
|
11 | 12 | use Illuminate\Http\Response;
|
|
14 | 15 | use Illuminate\Support\Facades\Cache;
|
15 | 16 | use Illuminate\Support\Facades\File;
|
16 | 17 | use Illuminate\Support\Facades\RateLimiter;
|
17 |
| -use Illuminate\Support\Facades\Storage; |
18 | 18 | use Illuminate\Support\Str;
|
19 | 19 | use Intervention\Image\Drivers\Gd\Encoders\WebpEncoder;
|
20 | 20 | use Intervention\Image\Encoders\AutoEncoder;
|
|
25 | 25 |
|
26 | 26 | class ImageTransformerController extends \Illuminate\Routing\Controller
|
27 | 27 | {
|
28 |
| - use ResolvesOptions; |
| 28 | + use ManagesImageCache, ResolvesOptions; |
29 | 29 |
|
30 | 30 | public function transformWithPrefix(Request $request, string $pathPrefix, string $options, string $path)
|
31 | 31 | {
|
@@ -127,19 +127,7 @@ protected function handleTransform(Request $request, ?string $pathPrefix, string
|
127 | 127 |
|
128 | 128 | if (config()->boolean('image-transform-url.cache.enabled')) {
|
129 | 129 | defer(function () use ($pathPrefix, $path, $options, $encoded) {
|
130 |
| - |
131 |
| - $cachePath = $this->getCachePath($pathPrefix, $path, $options); |
132 |
| - |
133 |
| - $cacheDir = dirname($cachePath); |
134 |
| - |
135 |
| - File::ensureDirectoryExists($cacheDir); |
136 |
| - File::put($cachePath, $encoded->toString()); |
137 |
| - |
138 |
| - Cache::put( |
139 |
| - key: 'image-transform-url:'.$cachePath, |
140 |
| - value: true, |
141 |
| - ttl: config()->integer('image-transform-url.cache.lifetime'), |
142 |
| - ); |
| 130 | + $this->storeCachedImage($pathPrefix, $path, $options, $encoded); |
143 | 131 | });
|
144 | 132 | }
|
145 | 133 |
|
@@ -235,16 +223,6 @@ protected static function parseOptions(string $options): array
|
235 | 223 | })->toArray();
|
236 | 224 | }
|
237 | 225 |
|
238 |
| - /** |
239 |
| - * Get the cache path for the given path and options. |
240 |
| - */ |
241 |
| - protected static function getCachePath(string $pathPrefix, string $path, array $options): string |
242 |
| - { |
243 |
| - $optionsHash = md5(json_encode($options)); |
244 |
| - |
245 |
| - return Storage::disk(config()->string('image-transform-url.cache.disk'))->path('_cache/image-transform-url/'.$pathPrefix.'/'.$optionsHash.'_'.$path); |
246 |
| - } |
247 |
| - |
248 | 226 | /**
|
249 | 227 | * Respond with the image content.
|
250 | 228 | */
|
|
0 commit comments