From 37e3f8b2dd672c5d4394b34263d79e401f9baf21 Mon Sep 17 00:00:00 2001 From: Mats Mikkel Rummelhoff Date: Wed, 21 Jun 2023 20:49:56 +0200 Subject: [PATCH] Simpler params handling for getMuxImageUrl and getMuxGifUrl --- CHANGELOG.md | 6 +++++- composer.json | 2 +- src/helpers/MuxApiHelper.php | 38 ++---------------------------------- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0099012..b35ddcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # MuxMate Changelog +## 1.1.2 - 2023-06-21 +### Fixed +- Fixed an issue where not all params passed to `getMuxImageUrl()` would make it + ## 1.1.1 - 2023-06-21 -### Added +### Fixed - Fixed a PHP exception due to a typing error ## 1.1.0 - 2023-06-21 diff --git a/composer.json b/composer.json index e95908b..9df774f 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "vaersaagod/muxmate", "description": "Mux ado about streaming, mate!", "type": "craft-plugin", - "version": "1.1.1", + "version": "1.1.2", "require": { "php": ">=8.1", "craftcms/cms": "^4.4.0", diff --git a/src/helpers/MuxApiHelper.php b/src/helpers/MuxApiHelper.php index 57f4bd7..6e3a204 100644 --- a/src/helpers/MuxApiHelper.php +++ b/src/helpers/MuxApiHelper.php @@ -107,24 +107,6 @@ public static function getMp4Url(string $muxPlaybackId, ?string $quality = 'medi public static function getImageUrl(string $muxPlaybackId, array $params = []): string { - $params = \array_reduce(\array_keys($params), function (array $carry, string $key) use ($params,) { - $valuesMap = [ - 'fit' => 'preserve', - ]; - $paramsMap = [ - 'w' => 'width', - 'h' => 'height', - 'fit' => 'fit_mode', - 'mode' => 'fit_mode', - ]; - $value = $valuesMap[$params[$key]] ?? $params[$key]; - if (!$value) { - return $carry; - } - $carry[$paramsMap[$key] ?? $key] = $value; - return $carry; - }, []); - if (!isset($params['fit_mode'])) { if (($params['width'] ?? null) && ($params['height'])) { $params['fit_mode'] = 'smartcrop'; @@ -138,29 +120,13 @@ public static function getImageUrl(string $muxPlaybackId, array $params = []): s } /** - * @param string|null $muxPlaybackId + * @param string $muxPlaybackId * @param array $params * @return string|null */ - public static function getGifUrl(?string $muxPlaybackId, array $params = []): ?string + public static function getGifUrl(string $muxPlaybackId, array $params = []): ?string { - - if (!$muxPlaybackId) { - return null; - } - - $paramsMap = [ - 'w' => 'width', - 'h' => 'height', - ]; - - $params = \array_reduce(\array_keys($params), function (array $carry, string $key) use ($params, $paramsMap) { - $carry[$paramsMap[$key] ?? $key] = $params[$key]; - return $carry; - }, []); - return UrlHelper::url(static::MUX_IMAGE_DOMAIN . '/' . $muxPlaybackId . "/animated.gif", $params); - } /**