@cliff-studio/sanity-plugin-bunny-input 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-es/index.js +10 -4
- package/dist/_chunks-es/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api.js +8 -3
- package/src/components/BunnyInput.jsx +13 -1
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -45,11 +45,16 @@ export function getPlaybackUrl(cdnHostname, videoId) {
|
|
|
45
45
|
* Get the direct MP4 URL (if available)
|
|
46
46
|
* @param {string} cdnHostname - The CDN hostname (e.g., 'vz-fbd37838-a6a.b-cdn.net')
|
|
47
47
|
* @param {string} videoId
|
|
48
|
-
* @param {string}
|
|
48
|
+
* @param {Array<number|string>} availableResolutions
|
|
49
49
|
* @returns {string}
|
|
50
50
|
*/
|
|
51
|
-
export function getMp4Url(cdnHostname, videoId,
|
|
52
|
-
|
|
51
|
+
export function getMp4Url(cdnHostname, videoId, availableResolutions = []) {
|
|
52
|
+
const parsedResolutions = (Array.isArray(availableResolutions) ? availableResolutions : [])
|
|
53
|
+
.map((resolution) => Number.parseInt(String(resolution).replace(/p$/i, ''), 10))
|
|
54
|
+
.filter((resolution) => Number.isFinite(resolution))
|
|
55
|
+
|
|
56
|
+
const bestResolution = parsedResolutions.length ? Math.max(...parsedResolutions) : 720
|
|
57
|
+
return `https://${cdnHostname}/${videoId}/play_${bestResolution}p.mp4`
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
function createHeaders(config, includeJsonContentType = false, useDirectApi = false) {
|
|
@@ -41,6 +41,13 @@ export function BunnyInput(props) {
|
|
|
41
41
|
|
|
42
42
|
const hasDims = Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0
|
|
43
43
|
const ratio = hasDims ? Number((width / height).toFixed(6)) : null
|
|
44
|
+
const orientation = hasDims
|
|
45
|
+
? width > height
|
|
46
|
+
? 'landscape'
|
|
47
|
+
: width < height
|
|
48
|
+
? 'portrait'
|
|
49
|
+
: 'square'
|
|
50
|
+
: null
|
|
44
51
|
|
|
45
52
|
onChange(
|
|
46
53
|
set({
|
|
@@ -50,9 +57,14 @@ export function BunnyInput(props) {
|
|
|
50
57
|
height: hasDims ? height : null,
|
|
51
58
|
width: hasDims ? width : null,
|
|
52
59
|
ratio: ratio,
|
|
60
|
+
orientation: orientation,
|
|
53
61
|
thumbnailUrl: getThumbnailUrl(config.cdnHostname, value.videoId),
|
|
54
62
|
playbackUrl: getPlaybackUrl(config.cdnHostname, value.videoId),
|
|
55
|
-
mp4Url: getMp4Url(
|
|
63
|
+
mp4Url: getMp4Url(
|
|
64
|
+
config.cdnHostname,
|
|
65
|
+
value.videoId,
|
|
66
|
+
videoData.availableResolutions
|
|
67
|
+
),
|
|
56
68
|
})
|
|
57
69
|
)
|
|
58
70
|
}
|