|
15 | 15 | use Craft; |
16 | 16 | use craft\base\Component; |
17 | 17 | use craft\elements\Asset; |
18 | | -use craft\events\GetAssetThumbUrlEvent; |
| 18 | +use craft\events\AssetThumbEvent; |
19 | 19 | use craft\volumes\Local; |
20 | 20 |
|
21 | 21 | use yii\base\Exception; |
@@ -204,13 +204,14 @@ public function getVideoUrl($filePath, $videoOptions): string |
204 | 204 | * @param array $thumbnailOptions of options for the thumbnail |
205 | 205 | * @param bool $generate whether the thumbnail should be |
206 | 206 | * generated if it doesn't exists |
| 207 | + * @param bool $asPath Whether we should return a path or not |
207 | 208 | * |
208 | | - * @return string URL of the video thumbnail |
| 209 | + * @return string|false|null URL or path of the video thumbnail |
209 | 210 | */ |
210 | | - public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = true): string |
| 211 | + public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = true, $asPath = false) |
211 | 212 | { |
212 | 213 |
|
213 | | - $result = ""; |
| 214 | + $result = null; |
214 | 215 | $settings = Transcoder::$plugin->getSettings(); |
215 | 216 | $filePath = $this->getAssetPath($filePath); |
216 | 217 |
|
@@ -256,10 +257,15 @@ public function getVideoThumbnailUrl($filePath, $thumbnailOptions, $generate = t |
256 | 257 | } else { |
257 | 258 | Craft::info('Thumbnail does not exist, but not asked to generate it: ' . $filePath, __METHOD__); |
258 | 259 | // The file doesn't exist, and we weren't asked to generate it |
259 | | - return ''; |
| 260 | + return false; |
260 | 261 | } |
261 | 262 | } |
262 | | - $result = Craft::getAlias($settings['transcoderUrl']) . $destThumbnailFile; |
| 263 | + // Return either a path or a URL |
| 264 | + if ($asPath) { |
| 265 | + $result = $destThumbnailPath; |
| 266 | + } else { |
| 267 | + $result = Craft::getAlias($settings['transcoderUrl']) . $destThumbnailFile; |
| 268 | + } |
263 | 269 | } |
264 | 270 |
|
265 | 271 | return $result; |
@@ -482,19 +488,19 @@ public function getAudioFilename($filePath, $audioOptions): string |
482 | 488 | /** |
483 | 489 | * Handle generated a thumbnail for the AdminCP |
484 | 490 | * |
485 | | - * @param GetAssetThumbUrlEvent $event |
| 491 | + * @param AssetThumbEvent $event |
486 | 492 | * |
487 | | - * @return null|string |
| 493 | + * @return null|false|string |
488 | 494 | */ |
489 | | - public function handleGetAssetThumbUrl(GetAssetThumbUrlEvent $event) |
| 495 | + public function handleGetAssetThumbPath(AssetThumbEvent $event) |
490 | 496 | { |
491 | 497 | $options = [ |
492 | 498 | "width" => $event->width, |
493 | 499 | "height" => $event->height, |
494 | 500 | ]; |
495 | | - $thumbUrl = $this->getVideoThumbnailUrl($event->asset, $options, $event->generate); |
| 501 | + $thumbPath = $this->getVideoThumbnailUrl($event->asset, $options, $event->generate, true); |
496 | 502 |
|
497 | | - return empty($thumbUrl) ? null : $thumbUrl; |
| 503 | + return $thumbPath; |
498 | 504 | } |
499 | 505 |
|
500 | 506 | // Protected Methods |
|
0 commit comments