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.
- package/LICENSE +1 -1
- package/README.md +57 -55
- package/dist/index.js +223 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +227 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -17
- package/src/components/EditThumbnailDialog.tsx +122 -0
- package/src/components/PlayerActionsMenu.tsx +13 -0
- package/src/components/Uploader.tsx +21 -15
- package/src/components/VideoPlayer.tsx +66 -49
- package/src/components/VideoThumbnail.tsx +15 -8
- package/src/context/DialogStateContext.tsx +36 -0
- package/src/hooks/useAssets.ts +29 -23
- package/src/util/createUrlParamsObject.ts +25 -0
- package/src/util/formatSeconds.ts +28 -1
- package/src/util/getAnimatedPosterSrc.ts +5 -13
- package/src/util/getPosterSrc.ts +10 -15
- package/src/util/getVideoMetadata.ts +1 -1
- package/src/util/types.ts +4 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type {SanityClient} from 'sanity'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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:
|
|
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
|
-
|
|
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
|
}
|
package/src/util/getPosterSrc.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type {SanityClient} from 'sanity'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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:
|
|
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,
|
|
22
|
-
|
|
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
|
}
|
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 {
|