next-tinacms-cloudinary 27.0.1 → 27.0.3
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 +21 -8
- package/dist/search-expression.d.ts +11 -0
- package/dist/upload-filename.d.ts +7 -0
- package/package.json +5 -5
package/dist/handlers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/handlers.ts
|
|
2
2
|
import { v2 as cloudinary } from "cloudinary";
|
|
3
3
|
import path2 from "path";
|
|
4
|
+
import os from "os";
|
|
4
5
|
import multer from "multer";
|
|
5
6
|
import { promisify } from "util";
|
|
6
7
|
|
|
@@ -80,6 +81,17 @@ function resolveDirectory(rawDirectory) {
|
|
|
80
81
|
return normalized + "/";
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
// src/search-expression.ts
|
|
85
|
+
function escapeSearchValue(value) {
|
|
86
|
+
return value.replace(/[\\"*]/g, "\\$&");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/upload-filename.ts
|
|
90
|
+
function safeUploadName(originalName) {
|
|
91
|
+
const base = originalName.split(/[/\\]/).pop() || "";
|
|
92
|
+
return base === "." || base === ".." ? "" : base;
|
|
93
|
+
}
|
|
94
|
+
|
|
83
95
|
// src/handlers.ts
|
|
84
96
|
var mediaHandlerConfig = {
|
|
85
97
|
api: {
|
|
@@ -110,12 +122,11 @@ async function uploadMedia(req, res) {
|
|
|
110
122
|
const upload = promisify(
|
|
111
123
|
multer({
|
|
112
124
|
storage: multer.diskStorage({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
cb(null, "/tmp");
|
|
125
|
+
destination: (req2, file, cb) => {
|
|
126
|
+
cb(null, os.tmpdir());
|
|
116
127
|
},
|
|
117
128
|
filename: (req2, file, cb) => {
|
|
118
|
-
cb(null, file.originalname);
|
|
129
|
+
cb(null, safeUploadName(file.originalname));
|
|
119
130
|
}
|
|
120
131
|
})
|
|
121
132
|
}).single("file")
|
|
@@ -151,8 +162,10 @@ async function uploadMedia(req, res) {
|
|
|
151
162
|
}
|
|
152
163
|
async function listMedia(req, res, opts) {
|
|
153
164
|
try {
|
|
165
|
+
const rawDirectory = req.query.directory;
|
|
166
|
+
const directory = Array.isArray(rawDirectory) ? rawDirectory[0] : rawDirectory;
|
|
154
167
|
const mediaListOptions = {
|
|
155
|
-
directory:
|
|
168
|
+
directory: directory || '""',
|
|
156
169
|
limit: parseInt(req.query.limit, 10) || 500,
|
|
157
170
|
offset: req.query.offset,
|
|
158
171
|
filesOnly: req.query.filesOnly === "true" || false
|
|
@@ -169,14 +182,14 @@ async function listMedia(req, res, opts) {
|
|
|
169
182
|
throw e;
|
|
170
183
|
}
|
|
171
184
|
}
|
|
172
|
-
const query = useRootDirectory ? 'folder=""' : `folder="${mediaListOptions.directory}"`;
|
|
185
|
+
const query = useRootDirectory ? 'folder=""' : `folder="${escapeSearchValue(mediaListOptions.directory)}"`;
|
|
173
186
|
const response = await cloudinary.search.expression(query).max_results(mediaListOptions.limit).next_cursor(mediaListOptions.offset).execute();
|
|
174
187
|
const files = response.resources.map(getCloudinaryToTinaFunc(opts));
|
|
175
|
-
cloudinary.api.folders = (
|
|
188
|
+
cloudinary.api.folders = (directory2 = '""') => {
|
|
176
189
|
if (useRootDirectory) {
|
|
177
190
|
return cloudinary.api.root_folders();
|
|
178
191
|
} else {
|
|
179
|
-
return cloudinary.api.sub_folders(
|
|
192
|
+
return cloudinary.api.sub_folders(directory2);
|
|
180
193
|
}
|
|
181
194
|
};
|
|
182
195
|
let folders = [];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape a value for interpolation into a quoted Cloudinary Search API term.
|
|
3
|
+
*
|
|
4
|
+
* Cloudinary treats a double-quoted term literally except for `"` and `*`,
|
|
5
|
+
* which keep their meaning and must be backslash-escaped. Backslash is escaped
|
|
6
|
+
* too as a conservative hedge; callers reach this through resolveDirectory,
|
|
7
|
+
* which already rejects backslashes, so that branch is unreachable today.
|
|
8
|
+
*
|
|
9
|
+
* See https://cloudinary.com/documentation/search_expressions
|
|
10
|
+
*/
|
|
11
|
+
export declare function escapeSearchValue(value: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strip any directory component from an uploaded filename so
|
|
3
|
+
* path.join(os.tmpdir(), name) can't escape the temp dir. Defense in depth:
|
|
4
|
+
* multer's parser already basenames the name, but don't rely on it.
|
|
5
|
+
* Duplicated byte-for-byte across the multer-based media adapters.
|
|
6
|
+
*/
|
|
7
|
+
export declare function safeUploadName(originalName: string): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-cloudinary",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "27.0.
|
|
4
|
+
"version": "27.0.3",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"files": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"cloudinary": "^1.41.3",
|
|
23
|
-
"multer": "
|
|
23
|
+
"multer": "2.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/crypto-js": "^3.1.47",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"react": "^18.3.1",
|
|
31
31
|
"react-dom": "^18.3.1",
|
|
32
32
|
"typescript": "^5.7.3",
|
|
33
|
-
"@tinacms/scripts": "1.6.
|
|
34
|
-
"tinacms": "3.
|
|
33
|
+
"@tinacms/scripts": "1.6.3",
|
|
34
|
+
"tinacms": "3.12.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"tinacms": "3.
|
|
37
|
+
"tinacms": "^3.12.0"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"registry": "https://registry.npmjs.org"
|