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