sanity-plugin-mux-input 2.17.0 → 2.19.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 +80 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/actions/assets.ts +7 -1
- package/src/actions/secrets.ts +6 -0
- package/src/actions/upload.ts +10 -4
- package/src/components/AddCaptionDialog.tsx +28 -9
- package/src/components/EditCaptionDialog.tsx +4 -2
- package/src/hooks/useMuxPolling.ts +2 -0
- package/src/util/formatDriveShareLink.ts +64 -0
- package/src/util/pluginVersion.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -146,6 +146,7 @@ function useAssets() {
|
|
|
146
146
|
function useDialogState() {
|
|
147
147
|
return useState(!1);
|
|
148
148
|
}
|
|
149
|
+
const PLUGIN_VERSION_QUERY = { sanityVersion: "2.19.0" };
|
|
149
150
|
function saveSecrets(client, token, secretKey, enableSignedUrls, signingKeyId, signingKeyPrivate, drmConfigId) {
|
|
150
151
|
const doc = {
|
|
151
152
|
_id: "secrets.mux",
|
|
@@ -165,7 +166,8 @@ async function createSigningKeys(client) {
|
|
|
165
166
|
return await client.request({
|
|
166
167
|
url: `/addons/mux/signing-keys/${dataset}`,
|
|
167
168
|
withCredentials: !0,
|
|
168
|
-
method: "POST"
|
|
169
|
+
method: "POST",
|
|
170
|
+
query: PLUGIN_VERSION_QUERY
|
|
169
171
|
});
|
|
170
172
|
} catch (error) {
|
|
171
173
|
console.error("Error creating signing keys", error);
|
|
@@ -178,7 +180,8 @@ function testSecrets(client) {
|
|
|
178
180
|
return client.request({
|
|
179
181
|
url: `/addons/mux/secrets/${dataset}/test`,
|
|
180
182
|
withCredentials: !0,
|
|
181
|
-
method: "GET"
|
|
183
|
+
method: "GET",
|
|
184
|
+
query: PLUGIN_VERSION_QUERY
|
|
182
185
|
});
|
|
183
186
|
}
|
|
184
187
|
async function haveValidSigningKeys(client, signingKeyId, signingKeyPrivate) {
|
|
@@ -189,7 +192,8 @@ async function haveValidSigningKeys(client, signingKeyId, signingKeyPrivate) {
|
|
|
189
192
|
const res = await client.request({
|
|
190
193
|
url: `/addons/mux/signing-keys/${dataset}/${signingKeyId}`,
|
|
191
194
|
withCredentials: !0,
|
|
192
|
-
method: "GET"
|
|
195
|
+
method: "GET",
|
|
196
|
+
query: PLUGIN_VERSION_QUERY
|
|
193
197
|
});
|
|
194
198
|
return !!(res.data && res.data.id);
|
|
195
199
|
} catch {
|
|
@@ -202,7 +206,8 @@ function testSecretsObservable(client) {
|
|
|
202
206
|
() => client.observable.request({
|
|
203
207
|
url: `/addons/mux/secrets/${dataset}/test`,
|
|
204
208
|
withCredentials: !0,
|
|
205
|
-
method: "GET"
|
|
209
|
+
method: "GET",
|
|
210
|
+
query: PLUGIN_VERSION_QUERY
|
|
206
211
|
})
|
|
207
212
|
);
|
|
208
213
|
}
|
|
@@ -629,7 +634,8 @@ function deleteAssetOnMux(client, assetId) {
|
|
|
629
634
|
return client.request({
|
|
630
635
|
url: `/addons/mux/assets/${dataset}/${assetId}`,
|
|
631
636
|
withCredentials: !0,
|
|
632
|
-
method: "DELETE"
|
|
637
|
+
method: "DELETE",
|
|
638
|
+
query: PLUGIN_VERSION_QUERY
|
|
633
639
|
});
|
|
634
640
|
}
|
|
635
641
|
async function deleteAsset({
|
|
@@ -656,7 +662,8 @@ function getAsset(client, assetId) {
|
|
|
656
662
|
return client.request({
|
|
657
663
|
url: `/addons/mux/assets/${dataset}/data/${assetId}`,
|
|
658
664
|
withCredentials: !0,
|
|
659
|
-
method: "GET"
|
|
665
|
+
method: "GET",
|
|
666
|
+
query: PLUGIN_VERSION_QUERY
|
|
660
667
|
});
|
|
661
668
|
}
|
|
662
669
|
function listAssets(client, options) {
|
|
@@ -665,7 +672,7 @@ function listAssets(client, options) {
|
|
|
665
672
|
url: `/addons/mux/assets/${dataset}/data/list`,
|
|
666
673
|
withCredentials: !0,
|
|
667
674
|
method: "GET",
|
|
668
|
-
query
|
|
675
|
+
query: { ...query, ...PLUGIN_VERSION_QUERY }
|
|
669
676
|
});
|
|
670
677
|
}
|
|
671
678
|
function addTextTrackFromUrl(client, assetId, vttUrl, options) {
|
|
@@ -683,7 +690,8 @@ function addTextTrackFromUrl(client, assetId, vttUrl, options) {
|
|
|
683
690
|
},
|
|
684
691
|
headers: {
|
|
685
692
|
"Content-Type": "application/json"
|
|
686
|
-
}
|
|
693
|
+
},
|
|
694
|
+
query: PLUGIN_VERSION_QUERY
|
|
687
695
|
});
|
|
688
696
|
}
|
|
689
697
|
function generateSubtitles(client, assetId, audioTrackId, options) {
|
|
@@ -702,7 +710,8 @@ function generateSubtitles(client, assetId, audioTrackId, options) {
|
|
|
702
710
|
},
|
|
703
711
|
headers: {
|
|
704
712
|
"Content-Type": "application/json"
|
|
705
|
-
}
|
|
713
|
+
},
|
|
714
|
+
query: PLUGIN_VERSION_QUERY
|
|
706
715
|
});
|
|
707
716
|
}
|
|
708
717
|
function deleteTextTrack(client, assetId, trackId) {
|
|
@@ -710,7 +719,8 @@ function deleteTextTrack(client, assetId, trackId) {
|
|
|
710
719
|
return client.request({
|
|
711
720
|
url: `/addons/mux/assets/${dataset}/${assetId}/tracks/${trackId}`,
|
|
712
721
|
withCredentials: !0,
|
|
713
|
-
method: "DELETE"
|
|
722
|
+
method: "DELETE",
|
|
723
|
+
query: PLUGIN_VERSION_QUERY
|
|
714
724
|
});
|
|
715
725
|
}
|
|
716
726
|
const ASSETS_PER_PAGE = 100;
|
|
@@ -1887,7 +1897,15 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
1887
1897
|
null
|
|
1888
1898
|
), [name2, setName] = useState(""), [isSubmitting, setIsSubmitting] = useState(!1), [selectedFile, setSelectedFile] = useState(null), fileInputRef = useRef(null), uploadVttFile = async (file) => (await client.assets.upload("file", file, {
|
|
1889
1899
|
filename: file.name
|
|
1890
|
-
})).url,
|
|
1900
|
+
})).url, refreshAssetData = async () => {
|
|
1901
|
+
if (!(!asset._id || !asset.assetId))
|
|
1902
|
+
try {
|
|
1903
|
+
const latestAssetData = await getAsset(client, asset.assetId), dataWithKeys = addKeysToMuxData(latestAssetData.data);
|
|
1904
|
+
await client.patch(asset._id).set({ data: dataWithKeys, status: latestAssetData.data.status }).commit({ returnDocuments: !1 });
|
|
1905
|
+
} catch (refreshError) {
|
|
1906
|
+
console.error("Failed to refresh asset data:", refreshError);
|
|
1907
|
+
}
|
|
1908
|
+
}, handleAddTrackFromUrl = async () => {
|
|
1891
1909
|
if (!asset.assetId)
|
|
1892
1910
|
throw new Error("Asset ID is required");
|
|
1893
1911
|
const trimmedName = name2.trim(), trimmedLanguageCode = languageCode.trim();
|
|
@@ -1897,9 +1915,9 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
1897
1915
|
vttUrlToUse = await uploadVttFile(selectedFile);
|
|
1898
1916
|
} catch (uploadError) {
|
|
1899
1917
|
throw toast.push({
|
|
1900
|
-
title: "Failed to upload
|
|
1918
|
+
title: "Failed to upload caption file",
|
|
1901
1919
|
status: "error",
|
|
1902
|
-
description: "Could not upload the
|
|
1920
|
+
description: "Could not upload the caption file to Sanity. Please try again."
|
|
1903
1921
|
}), setIsSubmitting(!1), uploadError;
|
|
1904
1922
|
}
|
|
1905
1923
|
await addTextTrackFromUrl(client, asset.assetId, vttUrlToUse, {
|
|
@@ -1912,13 +1930,13 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
1912
1930
|
assetId: asset.assetId,
|
|
1913
1931
|
trackName: trimmedName,
|
|
1914
1932
|
trackLanguageCode: trimmedLanguageCode,
|
|
1915
|
-
onTrackErrored: (track) => {
|
|
1933
|
+
onTrackErrored: async (track) => {
|
|
1916
1934
|
const errorMessage = track.error?.messages?.[0] || track.error?.type || "The track failed to download from the provided URL";
|
|
1917
1935
|
toast.push({
|
|
1918
1936
|
title: "Caption track failed",
|
|
1919
1937
|
status: "error",
|
|
1920
1938
|
description: errorMessage
|
|
1921
|
-
}), onAdd(track), onClose();
|
|
1939
|
+
}), await refreshAssetData(), onAdd(track), onClose();
|
|
1922
1940
|
}
|
|
1923
1941
|
});
|
|
1924
1942
|
if (!result.found || !result.track) {
|
|
@@ -1935,10 +1953,10 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
1935
1953
|
title: "Caption track is processing",
|
|
1936
1954
|
status: "info",
|
|
1937
1955
|
description: "The track was created and is being processed. It will appear in the list shortly."
|
|
1938
|
-
}), onAdd(result.track), onClose();
|
|
1956
|
+
}), await refreshAssetData(), onAdd(result.track), onClose();
|
|
1939
1957
|
return;
|
|
1940
1958
|
}
|
|
1941
|
-
toast.push({
|
|
1959
|
+
await refreshAssetData(), toast.push({
|
|
1942
1960
|
title: "Caption track added",
|
|
1943
1961
|
status: "success",
|
|
1944
1962
|
description: "Caption track added successfully"
|
|
@@ -1976,9 +1994,9 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
1976
1994
|
if (!isAutogenerated) {
|
|
1977
1995
|
if (!selectedFile && !vttUrl.trim()) {
|
|
1978
1996
|
toast.push({
|
|
1979
|
-
title: "
|
|
1997
|
+
title: "Caption file or URL required",
|
|
1980
1998
|
status: "error",
|
|
1981
|
-
description: "Please select a VTT file or enter a
|
|
1999
|
+
description: "Please select a VTT or SRT file or enter a caption file URL"
|
|
1982
2000
|
});
|
|
1983
2001
|
return;
|
|
1984
2002
|
}
|
|
@@ -1989,7 +2007,7 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
1989
2007
|
toast.push({
|
|
1990
2008
|
title: "Invalid URL",
|
|
1991
2009
|
status: "error",
|
|
1992
|
-
description: "Please enter a valid URL (e.g., https://example.com/subtitles.vtt)"
|
|
2010
|
+
description: "Please enter a valid URL (e.g., https://example.com/subtitles.vtt or subtitles.srt)"
|
|
1993
2011
|
});
|
|
1994
2012
|
return;
|
|
1995
2013
|
}
|
|
@@ -2071,7 +2089,7 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
2071
2089
|
{
|
|
2072
2090
|
ref: fileInputRef,
|
|
2073
2091
|
type: "file",
|
|
2074
|
-
accept: ".vtt,text/vtt",
|
|
2092
|
+
accept: ".vtt,text/vtt,.srt,application/x-subrip",
|
|
2075
2093
|
style: { display: "none" },
|
|
2076
2094
|
onChange: (e) => {
|
|
2077
2095
|
e.target.files && e.target.files.length > 0 && !isSubmitting && (setSelectedFile(e.target.files[0]), setVttUrl(""));
|
|
@@ -2079,9 +2097,9 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
|
|
|
2079
2097
|
}
|
|
2080
2098
|
)
|
|
2081
2099
|
] }),
|
|
2082
|
-
/* @__PURE__ */ jsx(Text, { size: 1, muted: !0, style: { textAlign: "center" }, children: "Or enter the
|
|
2100
|
+
/* @__PURE__ */ jsx(Text, { size: 1, muted: !0, style: { textAlign: "center" }, children: "Or enter the caption file URL" }),
|
|
2083
2101
|
/* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
2084
|
-
/* @__PURE__ */ jsx(Label$1, { htmlFor: "vtt-url", children: "
|
|
2102
|
+
/* @__PURE__ */ jsx(Label$1, { htmlFor: "vtt-url", children: "Caption File URL (.vtt or .srt)" }),
|
|
2085
2103
|
/* @__PURE__ */ jsx(
|
|
2086
2104
|
TextInput,
|
|
2087
2105
|
{
|
|
@@ -2214,8 +2232,8 @@ function EditCaptionDialog({ asset, track, onUpdate, onClose }) {
|
|
|
2214
2232
|
})).url, refreshAssetData = async () => {
|
|
2215
2233
|
if (!(!asset._id || !asset.assetId))
|
|
2216
2234
|
try {
|
|
2217
|
-
const latestAssetData = await getAsset(client, asset.assetId);
|
|
2218
|
-
await client.patch(asset._id).set({ data:
|
|
2235
|
+
const latestAssetData = await getAsset(client, asset.assetId), dataWithKeys = addKeysToMuxData(latestAssetData.data);
|
|
2236
|
+
await client.patch(asset._id).set({ data: dataWithKeys, status: latestAssetData.data.status }).commit({ returnDocuments: !1 });
|
|
2219
2237
|
} catch (refreshError) {
|
|
2220
2238
|
console.error("Failed to refresh asset data:", refreshError);
|
|
2221
2239
|
}
|
|
@@ -3154,7 +3172,7 @@ function VideoPlayer({
|
|
|
3154
3172
|
crossOrigin: "anonymous",
|
|
3155
3173
|
metadata: {
|
|
3156
3174
|
player_name: "Sanity Admin Dashboard",
|
|
3157
|
-
player_version: "2.
|
|
3175
|
+
player_version: "2.19.0",
|
|
3158
3176
|
page_type: "Preview Player"
|
|
3159
3177
|
},
|
|
3160
3178
|
audio: isAudio,
|
|
@@ -4165,7 +4183,8 @@ const useAccessControl = (config) => {
|
|
|
4165
4183
|
const { data } = await client.request({
|
|
4166
4184
|
url: `/addons/mux/assets/${dataset}/data/${asset.assetId}`,
|
|
4167
4185
|
withCredentials: !0,
|
|
4168
|
-
method: "GET"
|
|
4186
|
+
method: "GET",
|
|
4187
|
+
query: PLUGIN_VERSION_QUERY
|
|
4169
4188
|
});
|
|
4170
4189
|
client.patch(asset._id).set({ status: data.status, data }).commit({ returnDocuments: !1 });
|
|
4171
4190
|
},
|
|
@@ -4316,6 +4335,29 @@ function createUpChunkObservable(uuid2, uploadUrl2, source) {
|
|
|
4316
4335
|
return upchunk.on("success", successHandler), upchunk.on("error", errorHandler), upchunk.on("progress", progressHandler), upchunk.on("offline", offlineHandler), upchunk.on("online", onlineHandler), () => upchunk.abort();
|
|
4317
4336
|
});
|
|
4318
4337
|
}
|
|
4338
|
+
function formatDriveShareLink(url) {
|
|
4339
|
+
const formatExportLink = (id) => `https://drive.google.com/uc?export=download&id=${id}`;
|
|
4340
|
+
try {
|
|
4341
|
+
const trimmed = url.trim(), parsed = new URL(trimmed);
|
|
4342
|
+
if (parsed.hostname !== "drive.google.com")
|
|
4343
|
+
throw new Error("URL is not from Google Drive.");
|
|
4344
|
+
const id = parsed.searchParams.get("id") || "";
|
|
4345
|
+
if (id.length)
|
|
4346
|
+
return formatExportLink(id);
|
|
4347
|
+
const path2 = parsed.pathname.split("/") || [];
|
|
4348
|
+
if (path2.includes("file") && path2.includes("d")) {
|
|
4349
|
+
const index = path2.findIndex((value) => value === "d") + 1, fileId = path2.at(index) || "";
|
|
4350
|
+
return formatExportLink(fileId);
|
|
4351
|
+
}
|
|
4352
|
+
if (path2.includes("folders")) {
|
|
4353
|
+
const index = path2.findIndex((value) => value === "folders") + 1, folderId = path2.at(index) || "";
|
|
4354
|
+
return formatExportLink(folderId);
|
|
4355
|
+
}
|
|
4356
|
+
throw new Error("URL was not recognized.");
|
|
4357
|
+
} catch {
|
|
4358
|
+
return url;
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4319
4361
|
function roundPxString(value) {
|
|
4320
4362
|
if (typeof value != "string") return;
|
|
4321
4363
|
const trimmed = value.trim();
|
|
@@ -4347,7 +4389,8 @@ function cancelUpload(client, uuid2) {
|
|
|
4347
4389
|
return client.observable.request({
|
|
4348
4390
|
url: `/addons/mux/uploads/${client.config().dataset}/${uuid2}`,
|
|
4349
4391
|
withCredentials: !0,
|
|
4350
|
-
method: "DELETE"
|
|
4392
|
+
method: "DELETE",
|
|
4393
|
+
query: PLUGIN_VERSION_QUERY
|
|
4351
4394
|
});
|
|
4352
4395
|
}
|
|
4353
4396
|
function uploadUrl({
|
|
@@ -4378,7 +4421,7 @@ function uploadUrl({
|
|
|
4378
4421
|
"MUX-Proxy-UUID": uuid$1,
|
|
4379
4422
|
"Content-Type": "application/json"
|
|
4380
4423
|
},
|
|
4381
|
-
query
|
|
4424
|
+
query: { ...query, ...PLUGIN_VERSION_QUERY }
|
|
4382
4425
|
})
|
|
4383
4426
|
).pipe(
|
|
4384
4427
|
mergeMap((result) => {
|
|
@@ -4416,7 +4459,8 @@ function uploadFile({
|
|
|
4416
4459
|
"MUX-Proxy-UUID": uuid$1,
|
|
4417
4460
|
"Content-Type": "application/json"
|
|
4418
4461
|
},
|
|
4419
|
-
body
|
|
4462
|
+
body,
|
|
4463
|
+
query: PLUGIN_VERSION_QUERY
|
|
4420
4464
|
})
|
|
4421
4465
|
).pipe(
|
|
4422
4466
|
mergeMap((result) => createUpChunkObservable(uuid$1, result.upload.url, file).pipe(
|
|
@@ -4442,7 +4486,8 @@ function getUpload(client, assetId) {
|
|
|
4442
4486
|
return client.request({
|
|
4443
4487
|
url: `/addons/mux/uploads/${dataset}/${assetId}`,
|
|
4444
4488
|
withCredentials: !0,
|
|
4445
|
-
method: "GET"
|
|
4489
|
+
method: "GET",
|
|
4490
|
+
query: PLUGIN_VERSION_QUERY
|
|
4446
4491
|
});
|
|
4447
4492
|
}
|
|
4448
4493
|
function pollUpload(client, uuid2) {
|
|
@@ -4493,14 +4538,15 @@ function testUrl(url) {
|
|
|
4493
4538
|
const error = new Error("Invalid URL");
|
|
4494
4539
|
if (typeof url != "string")
|
|
4495
4540
|
return throwError(error);
|
|
4496
|
-
|
|
4541
|
+
let formattedUrl = url.trim();
|
|
4542
|
+
formattedUrl = formatDriveShareLink(formattedUrl);
|
|
4497
4543
|
let parsed;
|
|
4498
4544
|
try {
|
|
4499
|
-
parsed = new URL(
|
|
4545
|
+
parsed = new URL(formattedUrl);
|
|
4500
4546
|
} catch {
|
|
4501
4547
|
return throwError(error);
|
|
4502
4548
|
}
|
|
4503
|
-
return parsed && !parsed.protocol.match(/http:|https:/) ? throwError(error) : of(
|
|
4549
|
+
return parsed && !parsed.protocol.match(/http:|https:/) ? throwError(error) : of(formattedUrl);
|
|
4504
4550
|
}
|
|
4505
4551
|
function optionsFromFile(opts, file) {
|
|
4506
4552
|
if (!(typeof window > "u" || !(file instanceof window.File)))
|