sanity-plugin-mux-input 2.15.0 → 2.17.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/dist/index.js +1150 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1151 -178
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/actions/upload.ts +42 -4
- package/src/components/DraggableWatermark.tsx +877 -0
- package/src/components/PlayerActionsMenu.tsx +14 -0
- package/src/components/ResyncMetadata.tsx +152 -73
- package/src/components/TextTracksManager.tsx +11 -55
- package/src/components/UploadConfiguration.tsx +259 -59
- package/src/components/Uploader.tsx +7 -1
- package/src/components/VideoDetails/VideoDetails.tsx +27 -11
- package/src/components/VideoDetails/useVideoDetails.ts +15 -1
- package/src/components/VideoPlayer.tsx +2 -0
- package/src/hooks/useMediaMetadata.ts +3 -0
- package/src/hooks/useResyncAsset.ts +110 -0
- package/src/hooks/useResyncMuxMetadata.ts +33 -0
- package/src/schema.ts +5 -0
- package/src/util/addKeysToMuxData.ts +30 -0
- package/src/util/convertWatermarkToMux.ts +160 -0
- package/src/util/roundPxString.ts +16 -0
- package/src/util/types.ts +43 -1
package/package.json
CHANGED
package/src/actions/upload.ts
CHANGED
|
@@ -4,10 +4,38 @@ import {catchError, mergeMap, mergeMapTo, switchMap} from 'rxjs/operators'
|
|
|
4
4
|
import type {SanityClient} from 'sanity'
|
|
5
5
|
|
|
6
6
|
import {createUpChunkObservable} from '../clients/upChunkObservable'
|
|
7
|
-
import
|
|
7
|
+
import {roundPxString} from '../util/roundPxString'
|
|
8
|
+
import type {MuxAsset, MuxNewAssetSettings, WatermarkConfig} from '../util/types'
|
|
8
9
|
import {getAsset} from './assets'
|
|
9
10
|
import {testSecretsObservable} from './secrets'
|
|
10
11
|
|
|
12
|
+
function sanitizeOverlaySettingsInPlace(settings: MuxNewAssetSettings) {
|
|
13
|
+
const inputs = settings.input
|
|
14
|
+
if (!inputs) return
|
|
15
|
+
for (const input of inputs) {
|
|
16
|
+
const overlay = (input as {overlay_settings?: Record<string, unknown>}).overlay_settings
|
|
17
|
+
if (!overlay) continue
|
|
18
|
+
|
|
19
|
+
const hm = roundPxString(overlay.horizontal_margin)
|
|
20
|
+
const vm = roundPxString(overlay.vertical_margin)
|
|
21
|
+
const w = roundPxString(overlay.width)
|
|
22
|
+
|
|
23
|
+
if (hm) overlay.horizontal_margin = hm
|
|
24
|
+
if (vm) overlay.vertical_margin = vm
|
|
25
|
+
if (w) overlay.width = w
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function sanitizePxStringsInJson(json: string): string {
|
|
30
|
+
return json.replace(/"(-?\d+(?:\.\d+)?)px"/g, (_match, num) => {
|
|
31
|
+
const n = Number(num)
|
|
32
|
+
if (!Number.isFinite(n)) return _match
|
|
33
|
+
let rounded = Math.round(n)
|
|
34
|
+
if (rounded === 0) rounded = n < 0 ? -1 : 1
|
|
35
|
+
return `"${rounded}px"`
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
11
39
|
export function cancelUpload(client: SanityClient, uuid: string) {
|
|
12
40
|
return client.observable.request({
|
|
13
41
|
url: `/addons/mux/uploads/${client.config().dataset}/${uuid}`,
|
|
@@ -20,10 +48,12 @@ export function uploadUrl({
|
|
|
20
48
|
url,
|
|
21
49
|
settings,
|
|
22
50
|
client,
|
|
51
|
+
watermark,
|
|
23
52
|
}: {
|
|
24
53
|
url: string
|
|
25
54
|
settings: MuxNewAssetSettings
|
|
26
55
|
client: SanityClient
|
|
56
|
+
watermark?: WatermarkConfig
|
|
27
57
|
}) {
|
|
28
58
|
return testUrl(url).pipe(
|
|
29
59
|
switchMap((validUrl) => {
|
|
@@ -38,9 +68,10 @@ export function uploadUrl({
|
|
|
38
68
|
const muxBody = settings
|
|
39
69
|
if (!muxBody.input) muxBody.input = [{type: 'video'}]
|
|
40
70
|
muxBody.input[0].url = validUrl
|
|
71
|
+
sanitizeOverlaySettingsInPlace(muxBody)
|
|
41
72
|
|
|
42
73
|
const query = {
|
|
43
|
-
muxBody: JSON.stringify(muxBody),
|
|
74
|
+
muxBody: sanitizePxStringsInJson(JSON.stringify(muxBody)),
|
|
44
75
|
filename: validUrl.split('/').slice(-1)[0],
|
|
45
76
|
}
|
|
46
77
|
|
|
@@ -79,10 +110,12 @@ export function uploadFile({
|
|
|
79
110
|
settings,
|
|
80
111
|
client,
|
|
81
112
|
file,
|
|
113
|
+
watermark,
|
|
82
114
|
}: {
|
|
83
115
|
settings: MuxNewAssetSettings
|
|
84
116
|
client: SanityClient
|
|
85
117
|
file: File
|
|
118
|
+
watermark?: WatermarkConfig
|
|
86
119
|
}) {
|
|
87
120
|
return testFile(file).pipe(
|
|
88
121
|
switchMap((fileOptions) => {
|
|
@@ -95,6 +128,7 @@ export function uploadFile({
|
|
|
95
128
|
}
|
|
96
129
|
const uuid = generateUuid()
|
|
97
130
|
const body = settings
|
|
131
|
+
sanitizeOverlaySettingsInPlace(body)
|
|
98
132
|
|
|
99
133
|
return concat(
|
|
100
134
|
of({type: 'uuid' as const, uuid}),
|
|
@@ -129,7 +163,7 @@ export function uploadFile({
|
|
|
129
163
|
if (event.type !== 'success') {
|
|
130
164
|
return of(event)
|
|
131
165
|
}
|
|
132
|
-
return from(updateAssetDocumentFromUpload(client, uuid)).pipe(
|
|
166
|
+
return from(updateAssetDocumentFromUpload(client, uuid, watermark)).pipe(
|
|
133
167
|
// eslint-disable-next-line max-nested-callbacks
|
|
134
168
|
mergeMap((doc) => of({...event, asset: doc}))
|
|
135
169
|
)
|
|
@@ -201,7 +235,11 @@ function pollUpload(client: SanityClient, uuid: string): Promise<UploadResponse>
|
|
|
201
235
|
})
|
|
202
236
|
}
|
|
203
237
|
|
|
204
|
-
async function updateAssetDocumentFromUpload(
|
|
238
|
+
async function updateAssetDocumentFromUpload(
|
|
239
|
+
client: SanityClient,
|
|
240
|
+
uuid: string,
|
|
241
|
+
_watermark?: WatermarkConfig
|
|
242
|
+
) {
|
|
205
243
|
let upload: UploadResponse
|
|
206
244
|
let asset: {data: MuxAsset}
|
|
207
245
|
try {
|