sanity-plugin-mux-input 2.4.0 → 2.5.0

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.
@@ -1,12 +1,11 @@
1
1
  import type {SanityClient} from 'sanity'
2
2
 
3
- import {generateJwt} from './generateJwt'
4
- import {getPlaybackId} from './getPlaybackId'
5
- import {getPlaybackPolicy} from './getPlaybackPolicy'
6
- import type {AnimatedThumbnailOptions, MuxAnimatedThumbnailUrl, VideoAssetDocument} from './types'
3
+ import {createUrlParamsObject} from './createUrlParamsObject'
4
+ import type {AnimatedThumbnailOptions, MuxAnimatedThumbnailUrl} from './types'
5
+ import {AssetThumbnailOptions} from './types'
7
6
 
8
7
  export interface AnimatedPosterSrcOptions extends AnimatedThumbnailOptions {
9
- asset: Pick<VideoAssetDocument, 'playbackId' | 'data' | 'thumbTime'>
8
+ asset: AssetThumbnailOptions['asset']
10
9
  client: SanityClient
11
10
  }
12
11
 
@@ -20,15 +19,8 @@ export function getAnimatedPosterSrc({
20
19
  fps = 15,
21
20
  }: AnimatedPosterSrcOptions): MuxAnimatedThumbnailUrl {
22
21
  const params = {height, width, start, end, fps}
23
- const playbackId = getPlaybackId(asset)
24
22
 
25
- let searchParams = new URLSearchParams(
26
- JSON.parse(JSON.stringify(params, (_, v) => v ?? undefined))
27
- )
28
- if (getPlaybackPolicy(asset) === 'signed') {
29
- const token = generateJwt(client, playbackId, 'g', params)
30
- searchParams = new URLSearchParams({token})
31
- }
23
+ const {playbackId, searchParams} = createUrlParamsObject(client, asset, params, 'g')
32
24
 
33
25
  return `https://image.mux.com/${playbackId}/animated.gif?${searchParams}`
34
26
  }
@@ -1,12 +1,11 @@
1
1
  import type {SanityClient} from 'sanity'
2
2
 
3
- import {generateJwt} from './generateJwt'
4
- import {getPlaybackId} from './getPlaybackId'
5
- import {getPlaybackPolicy} from './getPlaybackPolicy'
6
- import type {MuxThumbnailUrl, ThumbnailOptions, VideoAssetDocument} from './types'
3
+ import {createUrlParamsObject} from './createUrlParamsObject'
4
+ import type {MuxThumbnailUrl, ThumbnailOptions} from './types'
5
+ import {AssetThumbnailOptions} from './types'
7
6
 
8
7
  export interface PosterSrcOptions extends ThumbnailOptions {
9
- asset: VideoAssetDocument
8
+ asset: AssetThumbnailOptions['asset']
10
9
  client: SanityClient
11
10
  }
12
11
 
@@ -15,19 +14,15 @@ export function getPosterSrc({
15
14
  client,
16
15
  fit_mode,
17
16
  height,
18
- time = asset.thumbTime,
17
+ time = asset.thumbTime ?? undefined,
19
18
  width,
20
19
  }: PosterSrcOptions): MuxThumbnailUrl {
21
- const params = {fit_mode, height, time, width}
22
- const playbackId = getPlaybackId(asset)
23
-
24
- let searchParams = new URLSearchParams(
25
- JSON.parse(JSON.stringify(params, (_, v) => v ?? undefined))
26
- )
27
- if (getPlaybackPolicy(asset) === 'signed') {
28
- const token = generateJwt(client, playbackId, 't', params)
29
- searchParams = new URLSearchParams({token})
20
+ const params = {fit_mode, height, width}
21
+ if (time) {
22
+ ;(params as any).time = time
30
23
  }
31
24
 
25
+ const {playbackId, searchParams} = createUrlParamsObject(client, asset, params, 't')
26
+
32
27
  return `https://image.mux.com/${playbackId}/thumbnail.png?${searchParams}`
33
28
  }
@@ -1,4 +1,4 @@
1
- import formatSeconds from './formatSeconds'
1
+ import {formatSeconds} from './formatSeconds'
2
2
  import {VideoAssetDocument} from './types'
3
3
 
4
4
  export default function getVideoMetadata(doc: VideoAssetDocument) {
package/src/util/types.ts CHANGED
@@ -262,6 +262,10 @@ export interface AnimatedThumbnailOptions {
262
262
  fps?: number
263
263
  }
264
264
 
265
+ export interface AssetThumbnailOptions {
266
+ asset: Pick<VideoAssetDocument, 'playbackId' | 'data' | 'thumbTime' | 'filename' | 'assetId'>
267
+ }
268
+
265
269
  export type PlaybackPolicy = 'signed' | 'public'
266
270
 
267
271
  export interface MuxErrors {