next-tinacms-cloudinary 3.4.4 → 3.5.2
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/CHANGELOG.md +31 -0
- package/dist/handlers.d.ts +4 -1
- package/dist/handlers.js +23 -16
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# next-tinacms-cloudinary
|
|
2
2
|
|
|
3
|
+
## 3.5.2
|
|
4
|
+
|
|
5
|
+
## 3.5.1
|
|
6
|
+
|
|
7
|
+
## 3.5.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 4a3990c7e: Cloudinary media store now serves images over `https` by default. This can now be configured though the handler provided.
|
|
12
|
+
|
|
13
|
+
To revert to the old behavior:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
export default createMediaHandler(
|
|
17
|
+
{
|
|
18
|
+
// ...
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
useHttps: false,
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The default for `useHttps` is `true`
|
|
27
|
+
|
|
28
|
+
## 3.4.5
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- 2a4a23b74: Fixed issue where folders could not have spaces
|
|
33
|
+
|
|
3
34
|
## 3.4.4
|
|
4
35
|
|
|
5
36
|
## 3.4.3
|
package/dist/handlers.d.ts
CHANGED
|
@@ -17,9 +17,12 @@ export interface CloudinaryConfig {
|
|
|
17
17
|
api_secret: string;
|
|
18
18
|
authorized: (req: NextApiRequest, res: NextApiResponse) => Promise<boolean>;
|
|
19
19
|
}
|
|
20
|
+
export interface CloudinaryOptions {
|
|
21
|
+
useHttps?: boolean;
|
|
22
|
+
}
|
|
20
23
|
export declare const mediaHandlerConfig: {
|
|
21
24
|
api: {
|
|
22
25
|
bodyParser: boolean;
|
|
23
26
|
};
|
|
24
27
|
};
|
|
25
|
-
export declare const createMediaHandler: (config: CloudinaryConfig) => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
28
|
+
export declare const createMediaHandler: (config: CloudinaryConfig, options?: CloudinaryOptions) => (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
package/dist/handlers.js
CHANGED
|
@@ -22,7 +22,7 @@ var __toModule = (module2) => {
|
|
|
22
22
|
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
// pnp:/
|
|
25
|
+
// pnp:/home/runner/work/tinacms/tinacms/packages/next-tinacms-cloudinary/src/handlers.ts
|
|
26
26
|
__export(exports, {
|
|
27
27
|
createMediaHandler: () => createMediaHandler,
|
|
28
28
|
mediaHandlerConfig: () => mediaHandlerConfig
|
|
@@ -36,7 +36,7 @@ var mediaHandlerConfig = {
|
|
|
36
36
|
bodyParser: false
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
var createMediaHandler = (config) => {
|
|
39
|
+
var createMediaHandler = (config, options) => {
|
|
40
40
|
import_cloudinary.v2.config(Object.assign({ secure: true }, config));
|
|
41
41
|
return async (req, res) => {
|
|
42
42
|
const isAuthorized = await config.authorized(req, res);
|
|
@@ -46,7 +46,7 @@ var createMediaHandler = (config) => {
|
|
|
46
46
|
}
|
|
47
47
|
switch (req.method) {
|
|
48
48
|
case "GET":
|
|
49
|
-
return listMedia(req, res);
|
|
49
|
+
return listMedia(req, res, options);
|
|
50
50
|
case "POST":
|
|
51
51
|
return uploadMedia(req, res);
|
|
52
52
|
case "DELETE":
|
|
@@ -76,7 +76,7 @@ async function uploadMedia(req, res) {
|
|
|
76
76
|
});
|
|
77
77
|
res.json(result);
|
|
78
78
|
}
|
|
79
|
-
async function listMedia(req, res) {
|
|
79
|
+
async function listMedia(req, res, opts) {
|
|
80
80
|
try {
|
|
81
81
|
const {
|
|
82
82
|
directory = '""',
|
|
@@ -84,9 +84,9 @@ async function listMedia(req, res) {
|
|
|
84
84
|
offset
|
|
85
85
|
} = req.query;
|
|
86
86
|
const useRootDirectory = !directory || directory === "/" || directory === '""';
|
|
87
|
-
const query = useRootDirectory ? 'folder=""' : `folder
|
|
87
|
+
const query = useRootDirectory ? 'folder=""' : `folder="${directory}"`;
|
|
88
88
|
const response = await import_cloudinary.v2.search.expression(query).max_results(limit).next_cursor(offset).execute();
|
|
89
|
-
const files = response.resources.map(
|
|
89
|
+
const files = response.resources.map(getCloudinaryToTinaFunc(opts));
|
|
90
90
|
import_cloudinary.v2.api.folders = (directory2 = '""') => {
|
|
91
91
|
if (useRootDirectory) {
|
|
92
92
|
return import_cloudinary.v2.api.root_folders();
|
|
@@ -135,16 +135,23 @@ async function deleteAsset(req, res) {
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
function getCloudinaryToTinaFunc(opts) {
|
|
139
|
+
return function cloudinaryToTina(file) {
|
|
140
|
+
let useHttps = true;
|
|
141
|
+
if (typeof opts !== "undefined" && typeof opts.useHttps !== "undefined") {
|
|
142
|
+
useHttps = opts.useHttps;
|
|
143
|
+
}
|
|
144
|
+
const sel = useHttps ? "secure_url" : "url";
|
|
145
|
+
const filename = import_path.default.basename(file.public_id);
|
|
146
|
+
const directory = import_path.default.dirname(file.public_id);
|
|
147
|
+
return {
|
|
148
|
+
id: file.public_id,
|
|
149
|
+
filename,
|
|
150
|
+
directory,
|
|
151
|
+
src: file[sel],
|
|
152
|
+
previewSrc: transformCloudinaryImage(file[sel], "w_75,h_75,c_fill,q_auto"),
|
|
153
|
+
type: "file"
|
|
154
|
+
};
|
|
148
155
|
};
|
|
149
156
|
}
|
|
150
157
|
function transformCloudinaryImage(url, transformations) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-cloudinary",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"multer": "^1.4.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@tinacms/toolkit": "0.56.
|
|
28
|
+
"@tinacms/toolkit": "0.56.8",
|
|
29
29
|
"@types/crypto-js": "^3.1.47",
|
|
30
30
|
"@types/js-cookie": "^2.2.6",
|
|
31
31
|
"@types/node": "^13.13.1",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"react": "16.14.0",
|
|
36
36
|
"react-dom": "16.14.0",
|
|
37
37
|
"styled-components": "^5.2.0",
|
|
38
|
-
"tinacms": "0.
|
|
38
|
+
"tinacms": "0.64.2",
|
|
39
39
|
"typescript": "^4.3.5"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|