sanity-plugin-mux-input 2.17.0 → 2.18.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
@@ -1888,7 +1888,15 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
1888
1888
  null
1889
1889
  ), [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
1890
  filename: file.name
1891
- })).url, handleAddTrackFromUrl = async () => {
1891
+ })).url, refreshAssetData = async () => {
1892
+ if (!(!asset._id || !asset.assetId))
1893
+ try {
1894
+ const latestAssetData = await getAsset(client, asset.assetId), dataWithKeys = addKeysToMuxData(latestAssetData.data);
1895
+ await client.patch(asset._id).set({ data: dataWithKeys, status: latestAssetData.data.status }).commit({ returnDocuments: !1 });
1896
+ } catch (refreshError) {
1897
+ console.error("Failed to refresh asset data:", refreshError);
1898
+ }
1899
+ }, handleAddTrackFromUrl = async () => {
1892
1900
  if (!asset.assetId)
1893
1901
  throw new Error("Asset ID is required");
1894
1902
  const trimmedName = name2.trim(), trimmedLanguageCode = languageCode.trim();
@@ -1898,9 +1906,9 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
1898
1906
  vttUrlToUse = await uploadVttFile(selectedFile);
1899
1907
  } catch (uploadError) {
1900
1908
  throw toast.push({
1901
- title: "Failed to upload VTT file",
1909
+ title: "Failed to upload caption file",
1902
1910
  status: "error",
1903
- description: "Could not upload the VTT file to Sanity. Please try again."
1911
+ description: "Could not upload the caption file to Sanity. Please try again."
1904
1912
  }), setIsSubmitting(!1), uploadError;
1905
1913
  }
1906
1914
  await addTextTrackFromUrl(client, asset.assetId, vttUrlToUse, {
@@ -1913,13 +1921,13 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
1913
1921
  assetId: asset.assetId,
1914
1922
  trackName: trimmedName,
1915
1923
  trackLanguageCode: trimmedLanguageCode,
1916
- onTrackErrored: (track) => {
1924
+ onTrackErrored: async (track) => {
1917
1925
  const errorMessage = track.error?.messages?.[0] || track.error?.type || "The track failed to download from the provided URL";
1918
1926
  toast.push({
1919
1927
  title: "Caption track failed",
1920
1928
  status: "error",
1921
1929
  description: errorMessage
1922
- }), onAdd(track), onClose();
1930
+ }), await refreshAssetData(), onAdd(track), onClose();
1923
1931
  }
1924
1932
  });
1925
1933
  if (!result.found || !result.track) {
@@ -1936,10 +1944,10 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
1936
1944
  title: "Caption track is processing",
1937
1945
  status: "info",
1938
1946
  description: "The track was created and is being processed. It will appear in the list shortly."
1939
- }), onAdd(result.track), onClose();
1947
+ }), await refreshAssetData(), onAdd(result.track), onClose();
1940
1948
  return;
1941
1949
  }
1942
- toast.push({
1950
+ await refreshAssetData(), toast.push({
1943
1951
  title: "Caption track added",
1944
1952
  status: "success",
1945
1953
  description: "Caption track added successfully"
@@ -1977,9 +1985,9 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
1977
1985
  if (!isAutogenerated) {
1978
1986
  if (!selectedFile && !vttUrl.trim()) {
1979
1987
  toast.push({
1980
- title: "VTT file or URL required",
1988
+ title: "Caption file or URL required",
1981
1989
  status: "error",
1982
- description: "Please select a VTT file or enter a VTT file URL"
1990
+ description: "Please select a VTT or SRT file or enter a caption file URL"
1983
1991
  });
1984
1992
  return;
1985
1993
  }
@@ -1990,7 +1998,7 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
1990
1998
  toast.push({
1991
1999
  title: "Invalid URL",
1992
2000
  status: "error",
1993
- description: "Please enter a valid URL (e.g., https://example.com/subtitles.vtt)"
2001
+ description: "Please enter a valid URL (e.g., https://example.com/subtitles.vtt or subtitles.srt)"
1994
2002
  });
1995
2003
  return;
1996
2004
  }
@@ -2072,7 +2080,7 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
2072
2080
  {
2073
2081
  ref: fileInputRef,
2074
2082
  type: "file",
2075
- accept: ".vtt,text/vtt",
2083
+ accept: ".vtt,text/vtt,.srt,application/x-subrip",
2076
2084
  style: { display: "none" },
2077
2085
  onChange: (e) => {
2078
2086
  e.target.files && e.target.files.length > 0 && !isSubmitting && (setSelectedFile(e.target.files[0]), setVttUrl(""));
@@ -2080,9 +2088,9 @@ function AddCaptionDialog({ asset, onAdd, onClose }) {
2080
2088
  }
2081
2089
  )
2082
2090
  ] }),
2083
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, muted: !0, style: { textAlign: "center" }, children: "Or enter the VTT file URL" }),
2091
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, muted: !0, style: { textAlign: "center" }, children: "Or enter the caption file URL" }),
2084
2092
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
2085
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vtt-url", children: "VTT File URL" }),
2093
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "vtt-url", children: "Caption File URL (.vtt or .srt)" }),
2086
2094
  /* @__PURE__ */ jsxRuntime.jsx(
2087
2095
  ui.TextInput,
2088
2096
  {
@@ -2215,8 +2223,8 @@ function EditCaptionDialog({ asset, track, onUpdate, onClose }) {
2215
2223
  })).url, refreshAssetData = async () => {
2216
2224
  if (!(!asset._id || !asset.assetId))
2217
2225
  try {
2218
- const latestAssetData = await getAsset(client, asset.assetId);
2219
- await client.patch(asset._id).set({ data: latestAssetData.data, status: latestAssetData.data.status }).commit();
2226
+ const latestAssetData = await getAsset(client, asset.assetId), dataWithKeys = addKeysToMuxData(latestAssetData.data);
2227
+ await client.patch(asset._id).set({ data: dataWithKeys, status: latestAssetData.data.status }).commit({ returnDocuments: !1 });
2220
2228
  } catch (refreshError) {
2221
2229
  console.error("Failed to refresh asset data:", refreshError);
2222
2230
  }
@@ -3155,7 +3163,7 @@ function VideoPlayer({
3155
3163
  crossOrigin: "anonymous",
3156
3164
  metadata: {
3157
3165
  player_name: "Sanity Admin Dashboard",
3158
- player_version: "2.17.0",
3166
+ player_version: "2.18.0",
3159
3167
  page_type: "Preview Player"
3160
3168
  },
3161
3169
  audio: isAudio,
@@ -4317,6 +4325,29 @@ function createUpChunkObservable(uuid2, uploadUrl2, source) {
4317
4325
  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
4326
  });
4319
4327
  }
4328
+ function formatDriveShareLink(url) {
4329
+ const formatExportLink = (id) => `https://drive.google.com/uc?export=download&id=${id}`;
4330
+ try {
4331
+ const trimmed = url.trim(), parsed = new URL(trimmed);
4332
+ if (parsed.hostname !== "drive.google.com")
4333
+ throw new Error("URL is not from Google Drive.");
4334
+ const id = parsed.searchParams.get("id") || "";
4335
+ if (id.length)
4336
+ return formatExportLink(id);
4337
+ const path2 = parsed.pathname.split("/") || [];
4338
+ if (path2.includes("file") && path2.includes("d")) {
4339
+ const index = path2.findIndex((value) => value === "d") + 1, fileId = path2.at(index) || "";
4340
+ return formatExportLink(fileId);
4341
+ }
4342
+ if (path2.includes("folders")) {
4343
+ const index = path2.findIndex((value) => value === "folders") + 1, folderId = path2.at(index) || "";
4344
+ return formatExportLink(folderId);
4345
+ }
4346
+ throw new Error("URL was not recognized.");
4347
+ } catch {
4348
+ return url;
4349
+ }
4350
+ }
4320
4351
  function roundPxString(value) {
4321
4352
  if (typeof value != "string") return;
4322
4353
  const trimmed = value.trim();
@@ -4494,14 +4525,15 @@ function testUrl(url) {
4494
4525
  const error = new Error("Invalid URL");
4495
4526
  if (typeof url != "string")
4496
4527
  return rxjs.throwError(error);
4497
- const trimmedUrl = url.trim();
4528
+ let formattedUrl = url.trim();
4529
+ formattedUrl = formatDriveShareLink(formattedUrl);
4498
4530
  let parsed;
4499
4531
  try {
4500
- parsed = new URL(trimmedUrl);
4532
+ parsed = new URL(formattedUrl);
4501
4533
  } catch {
4502
4534
  return rxjs.throwError(error);
4503
4535
  }
4504
- return parsed && !parsed.protocol.match(/http:|https:/) ? rxjs.throwError(error) : rxjs.of(trimmedUrl);
4536
+ return parsed && !parsed.protocol.match(/http:|https:/) ? rxjs.throwError(error) : rxjs.of(formattedUrl);
4505
4537
  }
4506
4538
  function optionsFromFile(opts, file) {
4507
4539
  if (!(typeof window > "u" || !(file instanceof window.File)))