next-tinacms-cloudinary 7.0.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/cloudinary-media-store.d.ts +6 -1
- package/dist/cloudinary-tina-cloud-media-store.d.ts +27 -8
- package/dist/handlers.js +19 -11
- package/dist/index.js +11 -10
- package/dist/index.mjs +12 -11
- package/package.json +4 -4
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Media, MediaList, MediaListOptions, MediaStore, MediaUploadOptions } from 'tinacms';
|
|
2
|
+
export declare type CloudinaryMediaStoreOptions = {
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
};
|
|
2
5
|
export declare class CloudinaryMediaStore implements MediaStore {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
constructor(options?: CloudinaryMediaStoreOptions);
|
|
3
8
|
fetchFunction: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
4
9
|
accept: string;
|
|
5
10
|
persist(media: MediaUploadOptions[]): Promise<Media[]>;
|
|
6
11
|
delete(media: Media): Promise<void>;
|
|
7
12
|
list(options: MediaListOptions): Promise<MediaList>;
|
|
8
13
|
parse: (img: any) => any;
|
|
9
|
-
|
|
14
|
+
buildQuery(options: MediaListOptions): string;
|
|
10
15
|
}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { CloudinaryMediaStore } from './cloudinary-media-store';
|
|
5
1
|
import type { Client } from 'tinacms';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import type { CloudinaryMediaStoreOptions } from './cloudinary-media-store';
|
|
3
|
+
export declare const createTinaCloudCloudinaryMediaStore: (options?: CloudinaryMediaStoreOptions) => {
|
|
4
|
+
new (client: Client): {
|
|
5
|
+
client: Client;
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
fetchFunction: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
8
|
+
accept: string;
|
|
9
|
+
persist(media: import("tinacms").MediaUploadOptions[]): Promise<import("tinacms").Media[]>;
|
|
10
|
+
delete(media: import("tinacms").Media): Promise<void>;
|
|
11
|
+
list(options: import("tinacms").MediaListOptions): Promise<import("tinacms").MediaList>;
|
|
12
|
+
parse: (img: any) => any;
|
|
13
|
+
buildQuery(options: import("tinacms").MediaListOptions): string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare const TinaCloudCloudinaryMediaStore: {
|
|
17
|
+
new (client: Client): {
|
|
18
|
+
client: Client;
|
|
19
|
+
baseUrl: string;
|
|
20
|
+
fetchFunction: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
21
|
+
accept: string;
|
|
22
|
+
persist(media: import("tinacms").MediaUploadOptions[]): Promise<import("tinacms").Media[]>;
|
|
23
|
+
delete(media: import("tinacms").Media): Promise<void>;
|
|
24
|
+
list(options: import("tinacms").MediaListOptions): Promise<import("tinacms").MediaList>;
|
|
25
|
+
parse: (img: any) => any;
|
|
26
|
+
buildQuery(options: import("tinacms").MediaListOptions): string;
|
|
27
|
+
};
|
|
28
|
+
};
|
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
|
|
94
|
-
offset
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
const
|
|
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 = (
|
|
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(
|
|
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
|
@@ -48,14 +48,13 @@
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
class CloudinaryMediaStore {
|
|
51
|
-
constructor() {
|
|
52
|
-
this.fetchFunction = (input, init) =>
|
|
53
|
-
return fetch(input, init);
|
|
54
|
-
};
|
|
51
|
+
constructor(options) {
|
|
52
|
+
this.fetchFunction = (input, init) => fetch(input, init);
|
|
55
53
|
this.accept = tinacms.DEFAULT_MEDIA_UPLOAD_TYPES;
|
|
56
54
|
this.parse = (img) => {
|
|
57
55
|
return img.src;
|
|
58
56
|
};
|
|
57
|
+
this.baseUrl = (options == null ? void 0 : options.baseUrl) || "/api/cloudinary/media";
|
|
59
58
|
}
|
|
60
59
|
async persist(media) {
|
|
61
60
|
const newFiles = [];
|
|
@@ -65,7 +64,7 @@
|
|
|
65
64
|
formData.append("file", file);
|
|
66
65
|
formData.append("directory", directory);
|
|
67
66
|
formData.append("filename", file.name);
|
|
68
|
-
const res = await this.fetchFunction(
|
|
67
|
+
const res = await this.fetchFunction(this.baseUrl, {
|
|
69
68
|
method: "POST",
|
|
70
69
|
body: formData
|
|
71
70
|
});
|
|
@@ -95,7 +94,7 @@
|
|
|
95
94
|
}
|
|
96
95
|
async delete(media) {
|
|
97
96
|
await this.fetchFunction(
|
|
98
|
-
|
|
97
|
+
`${this.baseUrl}/${encodeURIComponent(media.id)}`,
|
|
99
98
|
{
|
|
100
99
|
method: "DELETE"
|
|
101
100
|
}
|
|
@@ -103,7 +102,7 @@
|
|
|
103
102
|
}
|
|
104
103
|
async list(options) {
|
|
105
104
|
const query = this.buildQuery(options);
|
|
106
|
-
const response = await this.fetchFunction(
|
|
105
|
+
const response = await this.fetchFunction(this.baseUrl + query);
|
|
107
106
|
if (response.status == 401) {
|
|
108
107
|
throw E_UNAUTHORIZED;
|
|
109
108
|
}
|
|
@@ -126,9 +125,9 @@
|
|
|
126
125
|
return `?${params}`;
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
|
-
class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
128
|
+
const createTinaCloudCloudinaryMediaStore = (options = { baseUrl: "/api/cloudinary/media" }) => class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
130
129
|
constructor(client) {
|
|
131
|
-
super();
|
|
130
|
+
super(options);
|
|
132
131
|
this.client = client;
|
|
133
132
|
this.fetchFunction = async (input, init) => {
|
|
134
133
|
try {
|
|
@@ -141,8 +140,10 @@
|
|
|
141
140
|
}
|
|
142
141
|
};
|
|
143
142
|
}
|
|
144
|
-
}
|
|
143
|
+
};
|
|
144
|
+
const TinaCloudCloudinaryMediaStore = createTinaCloudCloudinaryMediaStore();
|
|
145
145
|
exports2.CloudinaryMediaStore = CloudinaryMediaStore;
|
|
146
146
|
exports2.TinaCloudCloudinaryMediaStore = TinaCloudCloudinaryMediaStore;
|
|
147
|
+
exports2.createTinaCloudCloudinaryMediaStore = createTinaCloudCloudinaryMediaStore;
|
|
147
148
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
148
149
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -45,14 +45,13 @@ const interpretErrorMessage = (message) => {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
class CloudinaryMediaStore {
|
|
48
|
-
constructor() {
|
|
49
|
-
this.fetchFunction = (input, init) =>
|
|
50
|
-
return fetch(input, init);
|
|
51
|
-
};
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.fetchFunction = (input, init) => fetch(input, init);
|
|
52
50
|
this.accept = DEFAULT_MEDIA_UPLOAD_TYPES;
|
|
53
51
|
this.parse = (img) => {
|
|
54
52
|
return img.src;
|
|
55
53
|
};
|
|
54
|
+
this.baseUrl = (options == null ? void 0 : options.baseUrl) || "/api/cloudinary/media";
|
|
56
55
|
}
|
|
57
56
|
async persist(media) {
|
|
58
57
|
const newFiles = [];
|
|
@@ -62,7 +61,7 @@ class CloudinaryMediaStore {
|
|
|
62
61
|
formData.append("file", file);
|
|
63
62
|
formData.append("directory", directory);
|
|
64
63
|
formData.append("filename", file.name);
|
|
65
|
-
const res = await this.fetchFunction(
|
|
64
|
+
const res = await this.fetchFunction(this.baseUrl, {
|
|
66
65
|
method: "POST",
|
|
67
66
|
body: formData
|
|
68
67
|
});
|
|
@@ -92,7 +91,7 @@ class CloudinaryMediaStore {
|
|
|
92
91
|
}
|
|
93
92
|
async delete(media) {
|
|
94
93
|
await this.fetchFunction(
|
|
95
|
-
|
|
94
|
+
`${this.baseUrl}/${encodeURIComponent(media.id)}`,
|
|
96
95
|
{
|
|
97
96
|
method: "DELETE"
|
|
98
97
|
}
|
|
@@ -100,7 +99,7 @@ class CloudinaryMediaStore {
|
|
|
100
99
|
}
|
|
101
100
|
async list(options) {
|
|
102
101
|
const query = this.buildQuery(options);
|
|
103
|
-
const response = await this.fetchFunction(
|
|
102
|
+
const response = await this.fetchFunction(this.baseUrl + query);
|
|
104
103
|
if (response.status == 401) {
|
|
105
104
|
throw E_UNAUTHORIZED;
|
|
106
105
|
}
|
|
@@ -123,9 +122,9 @@ class CloudinaryMediaStore {
|
|
|
123
122
|
return `?${params}`;
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
|
-
class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
125
|
+
const createTinaCloudCloudinaryMediaStore = (options = { baseUrl: "/api/cloudinary/media" }) => class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
127
126
|
constructor(client) {
|
|
128
|
-
super();
|
|
127
|
+
super(options);
|
|
129
128
|
this.client = client;
|
|
130
129
|
this.fetchFunction = async (input, init) => {
|
|
131
130
|
try {
|
|
@@ -138,8 +137,10 @@ class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
|
|
|
138
137
|
}
|
|
139
138
|
};
|
|
140
139
|
}
|
|
141
|
-
}
|
|
140
|
+
};
|
|
141
|
+
const TinaCloudCloudinaryMediaStore = createTinaCloudCloudinaryMediaStore();
|
|
142
142
|
export {
|
|
143
143
|
CloudinaryMediaStore,
|
|
144
|
-
TinaCloudCloudinaryMediaStore
|
|
144
|
+
TinaCloudCloudinaryMediaStore,
|
|
145
|
+
createTinaCloudCloudinaryMediaStore
|
|
145
146
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-cloudinary",
|
|
3
|
-
"version": "
|
|
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.
|
|
33
|
-
"tinacms": "2.
|
|
32
|
+
"@tinacms/scripts": "1.2.0",
|
|
33
|
+
"tinacms": "2.2.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"tinacms": "2.
|
|
36
|
+
"tinacms": "2.2.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"registry": "https://registry.npmjs.org"
|