Skip to content

Commit

Permalink
Simpler params handling for getMuxImageUrl and getMuxGifUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikkel committed Jun 21, 2023
1 parent 3d5cd75 commit 37e3f8b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 2 additions & 36 deletions src/helpers/MuxApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);

}

/**
Expand Down

0 comments on commit 37e3f8b

Please sign in to comment.