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