next-tinacms-s3 0.0.4 → 0.0.6
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/errors.d.ts +12 -1
- package/dist/handlers.js +21 -8
- package/dist/index.es.js +9 -9
- package/dist/index.js +16 -15
- package/dist/s3-media-store.d.ts +1 -1
- package/dist/s3-tina-cloud-media-store.d.ts +1 -1
- package/package.json +5 -13
package/dist/errors.d.ts
CHANGED
|
@@ -10,10 +10,21 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
interface MediaListErrorConfig {
|
|
14
|
+
title: string;
|
|
15
|
+
message: string;
|
|
16
|
+
docsLink: string;
|
|
17
|
+
}
|
|
18
|
+
declare class MediaListError extends Error {
|
|
19
|
+
ERR_TYPE: string;
|
|
20
|
+
title: string;
|
|
21
|
+
docsLink: string;
|
|
22
|
+
constructor(config: MediaListErrorConfig);
|
|
23
|
+
}
|
|
14
24
|
export declare const E_DEFAULT: MediaListError;
|
|
15
25
|
export declare const E_UNAUTHORIZED: MediaListError;
|
|
16
26
|
export declare const E_CONFIG: MediaListError;
|
|
17
27
|
export declare const E_KEY_FAIL: MediaListError;
|
|
18
28
|
export declare const E_BAD_ROUTE: MediaListError;
|
|
19
29
|
export declare const interpretErrorMessage: (message: string) => MediaListError;
|
|
30
|
+
export {};
|
package/dist/handlers.js
CHANGED
|
@@ -42,7 +42,8 @@ var createMediaHandler = (config, options) => {
|
|
|
42
42
|
const bucket = config.bucket;
|
|
43
43
|
const region = config.config.region || "us-east-1";
|
|
44
44
|
const endpoint = config.config.endpoint || `https://s3.${region}.amazonaws.com`;
|
|
45
|
-
|
|
45
|
+
let cdnUrl = (options == null ? void 0 : options.cdnUrl) || endpoint.toString().replace(/http(s|):\/\//i, `https://${bucket}.`);
|
|
46
|
+
cdnUrl = cdnUrl + (cdnUrl.endsWith("/") ? "" : "/");
|
|
46
47
|
return async (req, res) => {
|
|
47
48
|
const isAuthorized = await config.authorized(req, res);
|
|
48
49
|
if (!isAuthorized) {
|
|
@@ -53,7 +54,7 @@ var createMediaHandler = (config, options) => {
|
|
|
53
54
|
case "GET":
|
|
54
55
|
return listMedia(req, res, client, bucket, cdnUrl);
|
|
55
56
|
case "POST":
|
|
56
|
-
return uploadMedia(req, res, client, bucket);
|
|
57
|
+
return uploadMedia(req, res, client, bucket, cdnUrl);
|
|
57
58
|
case "DELETE":
|
|
58
59
|
return deleteAsset(req, res, client, bucket);
|
|
59
60
|
default:
|
|
@@ -61,7 +62,7 @@ var createMediaHandler = (config, options) => {
|
|
|
61
62
|
}
|
|
62
63
|
};
|
|
63
64
|
};
|
|
64
|
-
async function uploadMedia(req, res, client, bucket) {
|
|
65
|
+
async function uploadMedia(req, res, client, bucket, cdnUrl) {
|
|
65
66
|
try {
|
|
66
67
|
const upload = (0, import_util.promisify)((0, import_multer.default)({
|
|
67
68
|
storage: import_multer.default.diskStorage({
|
|
@@ -80,15 +81,27 @@ async function uploadMedia(req, res, client, bucket) {
|
|
|
80
81
|
prefix = prefix + "/";
|
|
81
82
|
const filePath = req.file.path;
|
|
82
83
|
const blob = import_fs.default.readFileSync(filePath);
|
|
84
|
+
const filename = import_path.default.basename(filePath);
|
|
83
85
|
const params = {
|
|
84
86
|
Bucket: bucket,
|
|
85
|
-
Key: prefix +
|
|
87
|
+
Key: prefix + filename,
|
|
86
88
|
Body: blob,
|
|
87
89
|
ACL: "public-read"
|
|
88
90
|
};
|
|
89
91
|
const command = new import_client_s3.PutObjectCommand(params);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
try {
|
|
93
|
+
await client.send(command);
|
|
94
|
+
res.json({
|
|
95
|
+
type: "file",
|
|
96
|
+
id: prefix + filename,
|
|
97
|
+
filename,
|
|
98
|
+
directory: prefix,
|
|
99
|
+
previewSrc: cdnUrl + prefix + filename,
|
|
100
|
+
src: cdnUrl + prefix + filename
|
|
101
|
+
});
|
|
102
|
+
} catch (e) {
|
|
103
|
+
res.status(500).send(findErrorMessage(e));
|
|
104
|
+
}
|
|
92
105
|
} catch (e) {
|
|
93
106
|
res.status(500);
|
|
94
107
|
const message = findErrorMessage(e);
|
|
@@ -167,8 +180,8 @@ function getS3ToTinaFunc(cdnUrl) {
|
|
|
167
180
|
id: file.Key,
|
|
168
181
|
filename,
|
|
169
182
|
directory,
|
|
170
|
-
src: cdnUrl +
|
|
171
|
-
previewSrc: cdnUrl +
|
|
183
|
+
src: cdnUrl + file.Key,
|
|
184
|
+
previewSrc: cdnUrl + file.Key,
|
|
172
185
|
type: "file"
|
|
173
186
|
};
|
|
174
187
|
};
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
class MediaListError extends Error {
|
|
2
|
+
constructor(config) {
|
|
3
|
+
super(config.message);
|
|
4
|
+
this.ERR_TYPE = "MediaListError";
|
|
5
|
+
this.title = config.title;
|
|
6
|
+
this.docsLink = config.docsLink;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
2
9
|
const E_DEFAULT = new MediaListError({
|
|
3
10
|
title: "An Error Occurred",
|
|
4
11
|
message: "Something went wrong fetching your media from S3.",
|
|
@@ -71,14 +78,7 @@ class S3MediaStore {
|
|
|
71
78
|
await new Promise((resolve) => {
|
|
72
79
|
setTimeout(resolve, 2e3);
|
|
73
80
|
});
|
|
74
|
-
|
|
75
|
-
type: "file",
|
|
76
|
-
id: fileRes.public_id,
|
|
77
|
-
filename: fileRes.original_filename,
|
|
78
|
-
directory: "/",
|
|
79
|
-
previewSrc: fileRes.url
|
|
80
|
-
};
|
|
81
|
-
newFiles.push(parsedRes);
|
|
81
|
+
newFiles.push(fileRes);
|
|
82
82
|
}
|
|
83
83
|
return newFiles;
|
|
84
84
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
(function(global, factory) {
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports
|
|
3
|
-
})(this, function(exports2
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["next-tinacms-s3"] = {}));
|
|
3
|
+
})(this, function(exports2) {
|
|
4
4
|
"use strict";
|
|
5
|
-
|
|
5
|
+
class MediaListError extends Error {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
super(config.message);
|
|
8
|
+
this.ERR_TYPE = "MediaListError";
|
|
9
|
+
this.title = config.title;
|
|
10
|
+
this.docsLink = config.docsLink;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const E_DEFAULT = new MediaListError({
|
|
6
14
|
title: "An Error Occurred",
|
|
7
15
|
message: "Something went wrong fetching your media from S3.",
|
|
8
16
|
docsLink: "https://tina.io/packages/next-tinacms-s3"
|
|
9
17
|
});
|
|
10
|
-
const E_UNAUTHORIZED = new
|
|
18
|
+
const E_UNAUTHORIZED = new MediaListError({
|
|
11
19
|
title: "Unauthorized",
|
|
12
20
|
message: "You don't have access to this resource.",
|
|
13
21
|
docsLink: "https://tina.io/packages/next-tinacms-s3"
|
|
14
22
|
});
|
|
15
|
-
const E_CONFIG = new
|
|
23
|
+
const E_CONFIG = new MediaListError({
|
|
16
24
|
title: "Missing Credentials",
|
|
17
25
|
message: "Unable to connect to S3 because one or more environment variables are missing.",
|
|
18
26
|
docsLink: "https://tina.io/docs/media-s3/"
|
|
19
27
|
});
|
|
20
|
-
const E_KEY_FAIL = new
|
|
28
|
+
const E_KEY_FAIL = new MediaListError({
|
|
21
29
|
title: "Bad Credentials",
|
|
22
30
|
message: "Unable to connect to S3 because one or more environment variables are misconfigured.",
|
|
23
31
|
docsLink: "https://tina.io/docs/media-s3/"
|
|
24
32
|
});
|
|
25
|
-
const E_BAD_ROUTE = new
|
|
33
|
+
const E_BAD_ROUTE = new MediaListError({
|
|
26
34
|
title: "Bad Route",
|
|
27
35
|
message: "The S3 API route is missing or misconfigured.",
|
|
28
36
|
docsLink: "https://tina.io/packages/next-tinacms-s3/#set-up-api-routes"
|
|
@@ -74,14 +82,7 @@
|
|
|
74
82
|
await new Promise((resolve) => {
|
|
75
83
|
setTimeout(resolve, 2e3);
|
|
76
84
|
});
|
|
77
|
-
|
|
78
|
-
type: "file",
|
|
79
|
-
id: fileRes.public_id,
|
|
80
|
-
filename: fileRes.original_filename,
|
|
81
|
-
directory: "/",
|
|
82
|
-
previewSrc: fileRes.url
|
|
83
|
-
};
|
|
84
|
-
newFiles.push(parsedRes);
|
|
85
|
+
newFiles.push(fileRes);
|
|
85
86
|
}
|
|
86
87
|
return newFiles;
|
|
87
88
|
}
|
package/dist/s3-media-store.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
10
10
|
See the License for the specific language governing permissions and
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import { Media, MediaList, MediaListOptions, MediaStore, MediaUploadOptions } from '@tinacms/toolkit';
|
|
13
|
+
import type { Media, MediaList, MediaListOptions, MediaStore, MediaUploadOptions } from '@tinacms/toolkit';
|
|
14
14
|
export declare class S3MediaStore implements MediaStore {
|
|
15
15
|
fetchFunction: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
16
16
|
accept: string;
|
|
@@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
|
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
import { S3MediaStore } from './s3-media-store';
|
|
14
|
-
import { Client } from 'tinacms';
|
|
14
|
+
import type { Client } from 'tinacms';
|
|
15
15
|
export declare class TinaCloudS3MediaStore extends S3MediaStore {
|
|
16
16
|
client: Client;
|
|
17
17
|
constructor(client: Client);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-s3",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -22,25 +22,17 @@
|
|
|
22
22
|
"multer": "1.4.5-lts.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@tinacms/toolkit": "0.58.
|
|
26
|
-
"@tinacms/scripts": "0.51.
|
|
25
|
+
"@tinacms/toolkit": "0.58.2",
|
|
26
|
+
"@tinacms/scripts": "0.51.3",
|
|
27
27
|
"@types/crypto-js": "^3.1.47",
|
|
28
28
|
"@types/js-cookie": "^2.2.6",
|
|
29
29
|
"@types/node": "^13.13.1",
|
|
30
30
|
"@types/react": "^16.9.43",
|
|
31
31
|
"next": "12.2.4",
|
|
32
|
-
"
|
|
33
|
-
"react-dom": "17.0.2",
|
|
34
|
-
"tinacms": "0.69.17",
|
|
32
|
+
"tinacms": "0.69.20",
|
|
35
33
|
"typescript": "4.3.5"
|
|
36
34
|
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"@tinacms/toolkit": "*",
|
|
39
|
-
"react": ">=16.14",
|
|
40
|
-
"react-dom": ">=16.14",
|
|
41
|
-
"react-is": "^16.13.1 || <18.0.0",
|
|
42
|
-
"tinacms": ">=0.50.0"
|
|
43
|
-
},
|
|
35
|
+
"peerDependencies": {},
|
|
44
36
|
"publishConfig": {
|
|
45
37
|
"registry": "https://registry.npmjs.org"
|
|
46
38
|
},
|