@cliff-studio/sanity-plugin-bunny-input 1.0.7 → 1.0.9

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.9",
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,18 @@ 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 {string} availableResolutions - Comma-separated string (e.g. "360p,480p,240p")
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
+ // Parse to numbers so we can pick the highest; URL format requires "480p" etc.
53
+ const parsedResolutions = (availableResolutions || '')
54
+ .split(',')
55
+ .map((s) => Number.parseInt(String(s.trim()).replace(/p$/i, ''), 10))
56
+ .filter((n) => Number.isFinite(n))
57
+
58
+ const bestResolution = parsedResolutions.length ? Math.max(...parsedResolutions) : 720
59
+ return `https://${cdnHostname}/${videoId}/play_${bestResolution}p.mp4`
53
60
  }
54
61
 
55
62
  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
  }