next-tinacms-dos 0.0.0-f97a9b1-20241023074747 → 0.0.0-f9fb00b-20250728042847
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/README.md +1 -1
- package/dist/handlers.js +15 -16
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ Call `createMediaHandler` to set up routes and connect your instance of the Medi
|
|
|
92
92
|
|
|
93
93
|
Import `isAuthorized` from [`@tinacms/auth`](https://github.com/tinacms/tinacms/tree/main/packages/%40tinacms/auth).
|
|
94
94
|
|
|
95
|
-
The `authorized` key will make it so only authorized users within
|
|
95
|
+
The `authorized` key will make it so only authorized users within TinaCloud can upload and make media edits.
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
```
|
package/dist/handlers.js
CHANGED
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -51,7 +55,7 @@ var createMediaHandler = (config, options) => {
|
|
|
51
55
|
mediaRoot = mediaRoot.substr(1);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
|
-
let cdnUrl =
|
|
58
|
+
let cdnUrl = options?.cdnUrl || config.config.endpoint.toString().replace(/http(s|):\/\//i, `https://${bucket}.`);
|
|
55
59
|
cdnUrl = cdnUrl + (cdnUrl.endsWith("/") ? "" : "/");
|
|
56
60
|
return async (req, res) => {
|
|
57
61
|
const isAuthorized = await config.authorized(req, res);
|
|
@@ -72,10 +76,11 @@ var createMediaHandler = (config, options) => {
|
|
|
72
76
|
};
|
|
73
77
|
};
|
|
74
78
|
async function uploadMedia(req, res, client, bucket, mediaRoot, cdnUrl) {
|
|
75
|
-
var _a;
|
|
76
79
|
const upload = (0, import_util.promisify)(
|
|
77
80
|
(0, import_multer.default)({
|
|
78
81
|
storage: import_multer.default.diskStorage({
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
83
|
+
// @ts-ignore
|
|
79
84
|
directory: (req2, file, cb) => {
|
|
80
85
|
cb(null, "/tmp");
|
|
81
86
|
},
|
|
@@ -88,10 +93,9 @@ async function uploadMedia(req, res, client, bucket, mediaRoot, cdnUrl) {
|
|
|
88
93
|
await upload(req, res);
|
|
89
94
|
const { directory } = req.body;
|
|
90
95
|
let prefix = directory.replace(/^\//, "").replace(/\/$/, "");
|
|
91
|
-
if (prefix)
|
|
92
|
-
prefix = prefix + "/";
|
|
96
|
+
if (prefix) prefix = prefix + "/";
|
|
93
97
|
const filePath = req.file.path;
|
|
94
|
-
const fileType =
|
|
98
|
+
const fileType = req.file?.mimetype;
|
|
95
99
|
const blob = import_fs.default.readFileSync(filePath);
|
|
96
100
|
const filename = import_path.default.basename(filePath);
|
|
97
101
|
const params = {
|
|
@@ -140,7 +144,6 @@ function stripMediaRoot(mediaRoot, key) {
|
|
|
140
144
|
return keyParts.join("/");
|
|
141
145
|
}
|
|
142
146
|
async function listMedia(req, res, client, bucket, mediaRoot, cdnUrl) {
|
|
143
|
-
var _a;
|
|
144
147
|
try {
|
|
145
148
|
const {
|
|
146
149
|
directory = "",
|
|
@@ -148,18 +151,17 @@ async function listMedia(req, res, client, bucket, mediaRoot, cdnUrl) {
|
|
|
148
151
|
offset
|
|
149
152
|
} = req.query;
|
|
150
153
|
let prefix = directory.replace(/^\//, "").replace(/\/$/, "");
|
|
151
|
-
if (prefix)
|
|
152
|
-
prefix = prefix + "/";
|
|
154
|
+
if (prefix) prefix = prefix + "/";
|
|
153
155
|
const params = {
|
|
154
156
|
Bucket: bucket,
|
|
155
157
|
Delimiter: "/",
|
|
156
158
|
Prefix: mediaRoot ? import_path.default.join(mediaRoot, prefix) : prefix,
|
|
157
|
-
Marker: offset
|
|
159
|
+
Marker: offset?.toString(),
|
|
158
160
|
MaxKeys: directory && !offset ? +limit + 1 : +limit
|
|
159
161
|
};
|
|
160
162
|
const response = await client.send(new import_client_s3.ListObjectsCommand(params));
|
|
161
163
|
const items = [];
|
|
162
|
-
|
|
164
|
+
response.CommonPrefixes?.forEach(({ Prefix }) => {
|
|
163
165
|
const strippedPrefix = stripMediaRoot(mediaRoot, Prefix);
|
|
164
166
|
if (!strippedPrefix) {
|
|
165
167
|
return;
|
|
@@ -190,12 +192,9 @@ async function listMedia(req, res, client, bucket, mediaRoot, cdnUrl) {
|
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
var findErrorMessage = (e) => {
|
|
193
|
-
if (typeof e == "string")
|
|
194
|
-
|
|
195
|
-
if (e.message)
|
|
196
|
-
return e.message;
|
|
197
|
-
if (e.error && e.error.message)
|
|
198
|
-
return e.error.message;
|
|
195
|
+
if (typeof e == "string") return e;
|
|
196
|
+
if (e.message) return e.message;
|
|
197
|
+
if (e.error && e.error.message) return e.error.message;
|
|
199
198
|
return "an error occurred";
|
|
200
199
|
};
|
|
201
200
|
async function deleteAsset(req, res, client, bucket) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-dos",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-f9fb00b-20250728042847",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"files": [
|
|
@@ -18,18 +18,18 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"tinacms": "0.0.0-
|
|
21
|
+
"tinacms": "0.0.0-f9fb00b-20250728042847"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/crypto-js": "^3.1.47",
|
|
25
25
|
"@types/js-cookie": "^2.2.7",
|
|
26
|
-
"@types/node": "^22.
|
|
26
|
+
"@types/node": "^22.13.1",
|
|
27
27
|
"next": "14.2.10",
|
|
28
28
|
"react": "^18.3.1",
|
|
29
29
|
"react-dom": "^18.3.1",
|
|
30
|
-
"typescript": "^5.
|
|
31
|
-
"tinacms": "
|
|
32
|
-
"
|
|
30
|
+
"typescript": "^5.7.3",
|
|
31
|
+
"@tinacms/scripts": "1.4.0",
|
|
32
|
+
"tinacms": "0.0.0-f9fb00b-20250728042847"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"registry": "https://registry.npmjs.org"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"directory": "packages/next-tinacms-dos"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@aws-sdk/client-s3": "^3.
|
|
42
|
+
"@aws-sdk/client-s3": "^3.744.0",
|
|
43
43
|
"multer": "1.4.5-lts.1"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|