@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cliff-studio/sanity-plugin-bunny-input",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Sanity Studio plugin for uploading videos to Bunny Stream",
5
5
  "license": "MIT",
6
6
  "author": "Cliff Studio",
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} resolution
48
+ * @param {Array<number|string>} availableResolutions
49
49
  * @returns {string}
50
50
  */
51
- export function getMp4Url(cdnHostname, videoId, resolution = '720p') {
52
- return `https://${cdnHostname}/${videoId}/play_${resolution}.mp4`
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(config.cdnHostname, value.videoId),
63
+ mp4Url: getMp4Url(
64
+ config.cdnHostname,
65
+ value.videoId,
66
+ videoData.availableResolutions
67
+ ),
56
68
  })
57
69
  )
58
70
  }