sanity-plugin-r2-video 0.1.3 → 0.1.4

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
 
@@ -1722,7 +1729,10 @@ var QUERY_ASSETS = `*[_type == "r2Video.asset"] | order(uploadedAt desc){
1722
1729
  poster,
1723
1730
  duration,
1724
1731
  hasAudio,
1725
- renditions,
1732
+
1733
+ // A document the pipeline never finished - Sanity's own create button made
1734
+ // these before the reference field disabled it - has no renditions at all
1735
+ "renditions": coalesce(renditions, []),
1726
1736
  uploadedAt,
1727
1737
  "posterUrl": poster.asset->url,
1728
1738
  "folderName": folder->name
@@ -1731,10 +1741,11 @@ var slugify = (name) => {
1731
1741
  return name.toLowerCase().replace(/['\u2019]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
1732
1742
  };
1733
1743
  var toTitle = (asset, isFiltered) => {
1744
+ const filename = asset.filename || "Untitled video";
1734
1745
  if (isFiltered || !asset.folderName) {
1735
- return asset.filename;
1746
+ return filename;
1736
1747
  }
1737
- return `${slugify(asset.folderName)}/${asset.filename}`;
1748
+ return `${slugify(asset.folderName)}/${filename}`;
1738
1749
  };
1739
1750
  var matches = (asset, search) => {
1740
1751
  if (!search) {
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.4",
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",