next-tinacms-cloudinary 7.1.0 → 8.0.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/handlers.js CHANGED
@@ -88,26 +88,34 @@ async function uploadMedia(req, res) {
88
88
  async function listMedia(req, res, opts) {
89
89
  var _a;
90
90
  try {
91
- const {
92
- directory = '""',
93
- limit = 500,
94
- offset
95
- } = req.query;
96
- const useRootDirectory = !directory || directory === "/" || directory === '""';
97
- const query = useRootDirectory ? 'folder=""' : `folder="${directory}"`;
98
- const response = await import_cloudinary.v2.search.expression(query).max_results(limit).next_cursor(offset).execute();
91
+ const mediaListOptions = {
92
+ directory: req.query.directory || '""',
93
+ limit: parseInt(req.query.limit, 10) || 500,
94
+ offset: req.query.offset,
95
+ filesOnly: req.query.filesOnly === "true" || false
96
+ };
97
+ const useRootDirectory = !mediaListOptions.directory || mediaListOptions.directory === "/" || mediaListOptions.directory === '""';
98
+ const query = useRootDirectory ? 'folder=""' : `folder="${mediaListOptions.directory}"`;
99
+ const response = await import_cloudinary.v2.search.expression(query).max_results(mediaListOptions.limit).next_cursor(mediaListOptions.offset).execute();
99
100
  const files = response.resources.map(getCloudinaryToTinaFunc(opts));
100
- import_cloudinary.v2.api.folders = (directory2 = '""') => {
101
+ import_cloudinary.v2.api.folders = (directory = '""') => {
101
102
  if (useRootDirectory) {
102
103
  return import_cloudinary.v2.api.root_folders();
103
104
  } else {
104
- return import_cloudinary.v2.api.sub_folders(directory2);
105
+ return import_cloudinary.v2.api.sub_folders(directory);
105
106
  }
106
107
  };
107
108
  let folders = [];
108
109
  let folderRes = null;
110
+ if (mediaListOptions.filesOnly) {
111
+ res.json({
112
+ items: [...files],
113
+ offset: response.next_cursor
114
+ });
115
+ return;
116
+ }
109
117
  try {
110
- folderRes = await import_cloudinary.v2.api.folders(directory);
118
+ folderRes = await import_cloudinary.v2.api.folders(mediaListOptions.directory);
111
119
  } catch (e) {
112
120
  if ((_a = e.error) == null ? void 0 : _a.message.startsWith("Can't find folder with path")) {
113
121
  } else {
package/dist/index.js CHANGED
@@ -93,9 +93,12 @@
93
93
  return newFiles;
94
94
  }
95
95
  async delete(media) {
96
- await this.fetchFunction(`${this.baseUrl}/${encodeURIComponent(media.id)}`, {
97
- method: "DELETE"
98
- });
96
+ await this.fetchFunction(
97
+ `${this.baseUrl}/${encodeURIComponent(media.id)}`,
98
+ {
99
+ method: "DELETE"
100
+ }
101
+ );
99
102
  }
100
103
  async list(options) {
101
104
  const query = this.buildQuery(options);
package/dist/index.mjs CHANGED
@@ -90,9 +90,12 @@ class CloudinaryMediaStore {
90
90
  return newFiles;
91
91
  }
92
92
  async delete(media) {
93
- await this.fetchFunction(`${this.baseUrl}/${encodeURIComponent(media.id)}`, {
94
- method: "DELETE"
95
- });
93
+ await this.fetchFunction(
94
+ `${this.baseUrl}/${encodeURIComponent(media.id)}`,
95
+ {
96
+ method: "DELETE"
97
+ }
98
+ );
96
99
  }
97
100
  async list(options) {
98
101
  const query = this.buildQuery(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-tinacms-cloudinary",
3
- "version": "7.1.0",
3
+ "version": "8.0.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "files": [
@@ -29,11 +29,11 @@
29
29
  "react": "^18.3.1",
30
30
  "react-dom": "^18.3.1",
31
31
  "typescript": "4.6.4",
32
- "@tinacms/scripts": "1.1.6",
33
- "tinacms": "2.1.1"
32
+ "@tinacms/scripts": "1.2.0",
33
+ "tinacms": "2.2.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "tinacms": "2.1.1"
36
+ "tinacms": "2.2.0"
37
37
  },
38
38
  "publishConfig": {
39
39
  "registry": "https://registry.npmjs.org"