sanity-plugin-mux-input 2.14.0 → 2.16.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.
Files changed (55) hide show
  1. package/README.md +25 -24
  2. package/dist/index.d.mts +13 -1
  3. package/dist/index.d.ts +13 -1
  4. package/dist/index.js +1057 -470
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1059 -472
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +1 -1
  9. package/src/_exports/index.ts +1 -0
  10. package/src/actions/secrets.ts +6 -1
  11. package/src/actions/upload.ts +1 -1
  12. package/src/components/ConfigureApi.tsx +51 -5
  13. package/src/components/EditCaptionDialog.tsx +2 -2
  14. package/src/components/InputBrowser.tsx +8 -2
  15. package/src/components/PageSelector.tsx +4 -7
  16. package/src/components/Player.styled.tsx +7 -2
  17. package/src/components/PlayerActionsMenu.tsx +15 -1
  18. package/src/components/ResyncMetadata.tsx +152 -73
  19. package/src/components/SelectAsset.tsx +9 -3
  20. package/src/components/StudioTool.tsx +2 -2
  21. package/src/components/TextTracksManager.tsx +11 -55
  22. package/src/components/UploadConfiguration.tsx +104 -343
  23. package/src/components/Uploader.tsx +18 -7
  24. package/src/components/VideoDetails/VideoDetails.tsx +55 -19
  25. package/src/components/VideoDetails/useVideoDetails.ts +15 -1
  26. package/src/components/VideoInBrowser.tsx +53 -6
  27. package/src/components/VideoPlayer.tsx +120 -47
  28. package/src/components/VideoThumbnail.tsx +84 -72
  29. package/src/components/VideosBrowser.tsx +7 -5
  30. package/src/components/uploadConfiguration/PlaybackPolicy.tsx +95 -6
  31. package/src/components/uploadConfiguration/PlaybackPolicyOption.tsx +26 -10
  32. package/src/components/uploadConfiguration/ResolutionTierSelector.tsx +71 -0
  33. package/src/components/uploadConfiguration/StaticRenditionSelector.tsx +179 -0
  34. package/src/context/DrmPlaybackWarningContext.tsx +93 -0
  35. package/src/hooks/useFetchFileSize.ts +54 -0
  36. package/src/hooks/useMediaMetadata.ts +100 -0
  37. package/src/hooks/useResyncAsset.ts +110 -0
  38. package/src/hooks/useResyncMuxMetadata.ts +33 -0
  39. package/src/hooks/useSaveSecrets.ts +10 -3
  40. package/src/hooks/useSecretsDocumentValues.ts +9 -1
  41. package/src/hooks/useSecretsFormState.ts +6 -3
  42. package/src/schema.ts +5 -0
  43. package/src/util/addKeysToMuxData.ts +30 -0
  44. package/src/util/asserters.ts +14 -0
  45. package/src/util/createUrlParamsObject.ts +7 -3
  46. package/src/util/generateJwt.ts +11 -2
  47. package/src/util/getPlaybackPolicy.ts +63 -4
  48. package/src/util/getStoryboardSrc.ts +7 -3
  49. package/src/util/getVideoMetadata.ts +1 -0
  50. package/src/util/getVideoSrc.ts +9 -9
  51. package/src/util/readSecrets.ts +3 -1
  52. package/src/util/textTracks.ts +6 -3
  53. package/src/util/tryWithSuspend.ts +22 -0
  54. package/src/util/types.ts +27 -2
  55. package/src/util/getPlaybackId.ts +0 -9
@@ -10,8 +10,9 @@ import {
10
10
  import {Box, Button, Card, Dialog, Flex, Heading, Spinner, Stack, Text, useToast} from '@sanity/ui'
11
11
  import {useEffect, useId, useMemo, useState} from 'react'
12
12
 
13
- import {deleteTextTrack, getAsset} from '../actions/assets'
13
+ import {deleteTextTrack} from '../actions/assets'
14
14
  import {useClient} from '../hooks/useClient'
15
+ import {useResyncAsset} from '../hooks/useResyncAsset'
15
16
  import {downloadVttFile} from '../util/textTracks'
16
17
  import type {MuxTextTrack, VideoAssetDocument} from '../util/types'
17
18
  import AddCaptionDialog from './AddCaptionDialog'
@@ -203,6 +204,7 @@ export default function TextTracksManager({
203
204
  const client = useClient()
204
205
  const toast = useToast()
205
206
  const dialogId = `DeleteCaptionDialog${useId()}`
207
+ const {resyncAsset} = useResyncAsset()
206
208
  const [downloadingTrackId, setDownloadingTrackId] = useState<string | null>(null)
207
209
  const [deletingTrackId, setDeletingTrackId] = useState<string | null>(null)
208
210
  const [addedTracks, setAddedTracks] = useState<MuxTextTrack[]>([])
@@ -216,27 +218,6 @@ export default function TextTracksManager({
216
218
 
217
219
  const MAX_VISIBLE_TRACKS = 4
218
220
 
219
- useEffect(() => {
220
- if (!asset.assetId || !asset._id) return
221
-
222
- const assetId = asset.assetId
223
- const documentId = asset._id
224
-
225
- const refreshAsset = async () => {
226
- try {
227
- const response = await getAsset(client, assetId)
228
- await client
229
- .patch(documentId)
230
- .set({data: response.data, status: response.data.status})
231
- .commit()
232
- } catch (error) {
233
- console.error('Failed to refresh asset data:', error)
234
- }
235
- }
236
-
237
- refreshAsset()
238
- }, [asset.assetId, asset._id, client])
239
-
240
221
  const realTracks: MuxTextTrack[] = propTracks
241
222
  ? propTracks
242
223
  : asset.data?.tracks?.filter((track): track is MuxTextTrack => track.type === 'text') || []
@@ -344,20 +325,13 @@ export default function TextTracksManager({
344
325
  return undefined
345
326
  }
346
327
 
347
- const assetId = asset.assetId
348
- const documentId = asset._id
349
-
350
328
  const interval = setInterval(async () => {
351
329
  try {
352
- const response = await getAsset(client, assetId)
353
- await client
354
- .patch(documentId)
355
- .set({data: response.data, status: response.data.status})
356
- .commit()
330
+ const muxData = await resyncAsset(asset)
331
+ if (!muxData) return
357
332
 
358
333
  const fetchedTracks =
359
- response.data.tracks?.filter((track): track is MuxTextTrack => track.type === 'text') ||
360
- []
334
+ muxData.tracks?.filter((track): track is MuxTextTrack => track.type === 'text') || []
361
335
 
362
336
  const isMockTrackReplaced = (
363
337
  mockTrack: MuxTextTrack,
@@ -444,7 +418,7 @@ export default function TextTracksManager({
444
418
  }, 3000) // Poll every 3 seconds
445
419
 
446
420
  return () => clearInterval(interval)
447
- }, [allTracks, asset.assetId, asset._id, client])
421
+ }, [allTracks, asset, resyncAsset])
448
422
 
449
423
  const visibleTracks = allTracks
450
424
  .filter(
@@ -506,17 +480,8 @@ export default function TextTracksManager({
506
480
  }
507
481
  await deleteTextTrack(client, asset.assetId, track.id)
508
482
 
509
- if (asset._id) {
510
- try {
511
- const response = await getAsset(client, asset.assetId)
512
- await client
513
- .patch(asset._id)
514
- .set({data: response.data, status: response.data.status})
515
- .commit()
516
- } catch (refreshError) {
517
- console.error('Failed to refresh asset data:', refreshError)
518
- }
519
- }
483
+ // Refresh asset data after deletion
484
+ await resyncAsset(asset)
520
485
 
521
486
  toast.push({
522
487
  title: 'Successfully deleted caption track',
@@ -600,17 +565,8 @@ export default function TextTracksManager({
600
565
 
601
566
  setTrackToEdit(null)
602
567
 
603
- if (asset._id && asset.assetId) {
604
- try {
605
- const response = await getAsset(client, asset.assetId)
606
- await client
607
- .patch(asset._id)
608
- .set({data: response.data, status: response.data.status})
609
- .commit()
610
- } catch (refreshError) {
611
- console.error('Failed to refresh asset data:', refreshError)
612
- }
613
- }
568
+ // Refresh asset data after update
569
+ await resyncAsset(asset)
614
570
  }
615
571
 
616
572
  const getTrackSourceLabel = (track: MuxTextTrack) => {