diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php index da9e9ca337..18a471af64 100644 --- a/app/Http/Controllers/PhotoController.php +++ b/app/Http/Controllers/PhotoController.php @@ -600,7 +600,7 @@ public function extract_names($photoID, $request) $kind = ''; break; case 'MEDIUM2X': - if (strpos($photo->type, 'video') !== 0) { + if ($this->photoFunctions->isVideo($photo)) { $fileName = $photo->url; } else { $fileName = $photo->thumbUrl; @@ -611,7 +611,7 @@ public function extract_names($photoID, $request) $kind = '-' . $photo->medium2x; break; case 'MEDIUM': - if (strpos($photo->type, 'video') !== 0) { + if ($this->photoFunctions->isVideo($photo)) { $path = 'medium/' . $photo->url; } else { $path = 'medium/' . $photo->thumbUrl; @@ -619,7 +619,7 @@ public function extract_names($photoID, $request) $kind = '-' . $photo->medium; break; case 'SMALL2X': - if (strpos($photo->type, 'video') !== 0) { + if ($this->photoFunctions->isVideo($photo)) { $fileName = $photo->url; } else { $fileName = $photo->thumbUrl; @@ -630,7 +630,7 @@ public function extract_names($photoID, $request) $kind = '-' . $photo->small2x; break; case 'SMALL': - if (strpos($photo->type, 'video') !== 0) { + if ($this->photoFunctions->isVideo($photo)) { $path = 'small/' . $photo->url; } else { $path = 'small/' . $photo->thumbUrl; diff --git a/app/Http/Controllers/PhotoEditorController.php b/app/Http/Controllers/PhotoEditorController.php index f9fd42a448..8fa9e0fce2 100644 --- a/app/Http/Controllers/PhotoEditorController.php +++ b/app/Http/Controllers/PhotoEditorController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; +use App\ModelFunctions\PhotoFunctions; use App\Models\Configs; use App\Models\Logs; use App\Models\Photo; @@ -12,8 +13,14 @@ class PhotoEditorController extends Controller { - public function __construct() + /** + * @var PhotoFuctions + */ + private $photoFunctions; + + public function __construct(PhotoFunctions $photoFunctions) { + $this->photoFunctions = $photoFunctions; } /** @@ -51,6 +58,12 @@ public function rotate(Request $request) return 'false'; } + if ($this->photoFunctions->isVideo($photo)) { + Logs::error(__METHOD__, __LINE__, 'Trying to rotate a video'); + + return 'false'; + } + // direction is valid? if (($direction != 1) && ($direction != -1)) { Logs::error(__METHOD__, __LINE__, 'Direction must be 1 or -1'); diff --git a/app/ModelFunctions/PhotoFunctions.php b/app/ModelFunctions/PhotoFunctions.php index 87110891cb..f25b49370a 100644 --- a/app/ModelFunctions/PhotoFunctions.php +++ b/app/ModelFunctions/PhotoFunctions.php @@ -892,6 +892,14 @@ public function getValidExtensions(): array return $this->validExtensions; } + /** + * Sometimes we just need to know if a Photo is a video. + */ + public function isVideo(Photo $photo): bool + { + return $this->isValidVideoType($photo->type); + } + /** * Central function for retrieving the metadata since this has to be called in more than one place. *