sanity-plugin-r2-video 0.1.3 → 0.1.5

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.
@@ -90,14 +90,21 @@ var findReferencingDocuments = (client, id) => {
90
90
  };
91
91
  var deleteVideoAsset = async (client, config, asset) => {
92
92
  await client.delete(asset._id);
93
- try {
94
- await client.delete(asset.poster.asset._ref);
95
- } catch (error) {
96
- console.info(`Kept poster for '${asset.filename}' - still in use.`, error);
93
+ const posterId = asset.poster?.asset?._ref;
94
+ const renditions = asset.renditions ?? [];
95
+ if (posterId) {
96
+ try {
97
+ await client.delete(posterId);
98
+ } catch (error) {
99
+ console.info(
100
+ `Kept poster for '${asset.filename}' - still in use.`,
101
+ error
102
+ );
103
+ }
97
104
  }
98
105
  await deleteObjects(
99
106
  config,
100
- asset.renditions.map((rendition) => rendition.key)
107
+ renditions.map((rendition) => rendition.key)
101
108
  );
102
109
  };
103
110
 
@@ -203,22 +210,6 @@ var formatBitrate = (bytes, seconds) => {
203
210
  }
204
211
  return `${(bytes * 8 / seconds / 1e6).toFixed(2)} Mbps`;
205
212
  };
206
- var OVERLAY_STYLE = {
207
- alignItems: "center",
208
- background: "rgba(0, 0, 0, 0.75)",
209
- color: "#fff",
210
- display: "flex",
211
- height: "100%",
212
- justifyContent: "center",
213
- position: "absolute",
214
- right: 0,
215
- top: 0,
216
- width: "100%",
217
- zIndex: 3
218
- };
219
- var DragOverlay = () => {
220
- return /* @__PURE__ */ jsx(Flex, { style: OVERLAY_STYLE, children: /* @__PURE__ */ jsx(Text, { size: 3, style: { color: "inherit" }, children: "Drop files to upload" }) });
221
- };
222
213
  var hasVideoFile = (transfer) => {
223
214
  return Array.from(transfer.items).some((item) => {
224
215
  if (item.kind !== "file") {
@@ -794,7 +785,7 @@ var DialogUpload = ({
794
785
  const stage = (files) => {
795
786
  setItems((existing) => [...existing, ...files.map(toItem)]);
796
787
  };
797
- const { isDragging, dropProps } = useFileDrop({
788
+ const { isDragging, isRejected, dropProps } = useFileDrop({
798
789
  isEnabled: !isBusy && canEncode !== false,
799
790
  onDrop: stage
800
791
  });
@@ -871,7 +862,7 @@ var DialogUpload = ({
871
862
  tone: "transparent",
872
863
  ...dropProps,
873
864
  children: [
874
- isDragging && /* @__PURE__ */ jsx(DragOverlay, {}),
865
+ isDragging && /* @__PURE__ */ jsx(DropToUpload, { isRejected }),
875
866
  /* @__PURE__ */ jsxs(Stack, { gap: 4, children: [
876
867
  /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
877
868
  /* @__PURE__ */ jsx(Flex, { justify: "center", children: /* @__PURE__ */ jsx(Text, { muted: true, size: 3, children: /* @__PURE__ */ jsx(UploadIcon, {}) }) }),
@@ -1441,7 +1432,7 @@ var DialogDetails = ({
1441
1432
  return /* @__PURE__ */ jsx(
1442
1433
  Dialog,
1443
1434
  {
1444
- header: asset.filename,
1435
+ header: asset.filename || "Untitled video",
1445
1436
  id: "r2-video-details",
1446
1437
  width: 1,
1447
1438
  onClose: isSaving ? void 0 : onClose,
@@ -1717,12 +1708,18 @@ var FolderSidebar = ({
1717
1708
  var QUERY_ASSETS = `*[_type == "r2Video.asset"] | order(uploadedAt desc){
1718
1709
  _id,
1719
1710
  _type,
1720
- filename,
1711
+
1712
+ // Both are absent on a document the pipeline never finished, and every
1713
+ // consumer of this query treats them as present
1714
+ "filename": coalesce(filename, ""),
1721
1715
  folder,
1722
1716
  poster,
1723
1717
  duration,
1724
1718
  hasAudio,
1725
- renditions,
1719
+
1720
+ // A document the pipeline never finished - Sanity's own create button made
1721
+ // these before the reference field disabled it - has no renditions at all
1722
+ "renditions": coalesce(renditions, []),
1726
1723
  uploadedAt,
1727
1724
  "posterUrl": poster.asset->url,
1728
1725
  "folderName": folder->name
@@ -1731,10 +1728,11 @@ var slugify = (name) => {
1731
1728
  return name.toLowerCase().replace(/['\u2019]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
1732
1729
  };
1733
1730
  var toTitle = (asset, isFiltered) => {
1731
+ const filename = asset.filename || "Untitled video";
1734
1732
  if (isFiltered || !asset.folderName) {
1735
- return asset.filename;
1733
+ return filename;
1736
1734
  }
1737
- return `${slugify(asset.folderName)}/${asset.filename}`;
1735
+ return `${slugify(asset.folderName)}/${filename}`;
1738
1736
  };
1739
1737
  var matches = (asset, search) => {
1740
1738
  if (!search) {
@@ -1771,7 +1769,7 @@ var ToolVideoLibrary = () => {
1771
1769
  const paths = resolveFolderPaths(folders).filter((entry) => {
1772
1770
  return counts.has(entry.id);
1773
1771
  });
1774
- const { isDragging, dropProps } = useFileDrop({
1772
+ const { isDragging, isRejected, dropProps } = useFileDrop({
1775
1773
  isEnabled: !isUploadOpen,
1776
1774
  onDrop: (files) => {
1777
1775
  setDroppedFiles(files);
@@ -1873,7 +1871,7 @@ var ToolVideoLibrary = () => {
1873
1871
  asset._id
1874
1872
  )) })
1875
1873
  ] }) }) }),
1876
- isDragging && /* @__PURE__ */ jsx(DragOverlay, {}),
1874
+ isDragging && /* @__PURE__ */ jsx(DropToUpload, { isRejected }),
1877
1875
  isUploadOpen && /* @__PURE__ */ jsx(
1878
1876
  DialogUpload,
1879
1877
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-r2-video",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Video for Sanity Studio, encoded in the browser and stored in Cloudflare R2 as a ladder of plain MP4s.",
5
5
  "keywords": [
6
6
  "sanity",