next-tinacms-dos 0.1.3 → 0.1.5
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/dos-media-store.d.ts +1 -1
- package/dist/dos-tina-cloud-media-store.d.ts +1 -1
- 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/package.json +4 -14
|
@@ -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 DOSMediaStore 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 { DOSMediaStore } from './dos-media-store';
|
|
14
|
-
import { Client } from 'tinacms';
|
|
14
|
+
import type { Client } from 'tinacms';
|
|
15
15
|
export declare class TinaCloudDOSMediaStore extends DOSMediaStore {
|
|
16
16
|
client: Client;
|
|
17
17
|
constructor(client: Client);
|
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
|
@@ -40,7 +40,8 @@ var mediaHandlerConfig = {
|
|
|
40
40
|
var createMediaHandler = (config, options) => {
|
|
41
41
|
const client = new import_client_s3.S3Client(config.config);
|
|
42
42
|
const bucket = config.bucket;
|
|
43
|
-
|
|
43
|
+
let cdnUrl = (options == null ? void 0 : options.cdnUrl) || config.config.endpoint.toString().replace(/http(s|):\/\//i, `https://${bucket}.`);
|
|
44
|
+
cdnUrl = cdnUrl + (cdnUrl.endsWith("/") ? "" : "/");
|
|
44
45
|
return async (req, res) => {
|
|
45
46
|
const isAuthorized = await config.authorized(req, res);
|
|
46
47
|
if (!isAuthorized) {
|
|
@@ -51,7 +52,7 @@ var createMediaHandler = (config, options) => {
|
|
|
51
52
|
case "GET":
|
|
52
53
|
return listMedia(req, res, client, bucket, cdnUrl);
|
|
53
54
|
case "POST":
|
|
54
|
-
return uploadMedia(req, res, client, bucket);
|
|
55
|
+
return uploadMedia(req, res, client, bucket, cdnUrl);
|
|
55
56
|
case "DELETE":
|
|
56
57
|
return deleteAsset(req, res, client, bucket);
|
|
57
58
|
default:
|
|
@@ -59,7 +60,7 @@ var createMediaHandler = (config, options) => {
|
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
62
|
};
|
|
62
|
-
async function uploadMedia(req, res, client, bucket) {
|
|
63
|
+
async function uploadMedia(req, res, client, bucket, cdnUrl) {
|
|
63
64
|
const upload = (0, import_util.promisify)((0, import_multer.default)({
|
|
64
65
|
storage: import_multer.default.diskStorage({
|
|
65
66
|
directory: (req2, file, cb) => {
|
|
@@ -77,15 +78,27 @@ async function uploadMedia(req, res, client, bucket) {
|
|
|
77
78
|
prefix = prefix + "/";
|
|
78
79
|
const filePath = req.file.path;
|
|
79
80
|
const blob = import_fs.default.readFileSync(filePath);
|
|
81
|
+
const filename = import_path.default.basename(filePath);
|
|
80
82
|
const params = {
|
|
81
83
|
Bucket: bucket,
|
|
82
|
-
Key: prefix +
|
|
84
|
+
Key: prefix + filename,
|
|
83
85
|
Body: blob,
|
|
84
86
|
ACL: "public-read"
|
|
85
87
|
};
|
|
86
88
|
const command = new import_client_s3.PutObjectCommand(params);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
try {
|
|
90
|
+
await client.send(command);
|
|
91
|
+
res.json({
|
|
92
|
+
type: "file",
|
|
93
|
+
id: prefix + filename,
|
|
94
|
+
filename,
|
|
95
|
+
directory: prefix,
|
|
96
|
+
previewSrc: cdnUrl + prefix + filename,
|
|
97
|
+
src: cdnUrl + prefix + filename
|
|
98
|
+
});
|
|
99
|
+
} catch (e) {
|
|
100
|
+
res.status(500).send(findErrorMessage(e));
|
|
101
|
+
}
|
|
89
102
|
}
|
|
90
103
|
async function listMedia(req, res, client, bucket, cdnUrl) {
|
|
91
104
|
var _a;
|
|
@@ -159,8 +172,8 @@ function getDOSToTinaFunc(cdnUrl) {
|
|
|
159
172
|
id: file.Key,
|
|
160
173
|
filename,
|
|
161
174
|
directory,
|
|
162
|
-
src: cdnUrl +
|
|
163
|
-
previewSrc: cdnUrl +
|
|
175
|
+
src: cdnUrl + file.Key,
|
|
176
|
+
previewSrc: cdnUrl + file.Key,
|
|
164
177
|
type: "file"
|
|
165
178
|
};
|
|
166
179
|
};
|
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 Digital Ocean Space.",
|
|
@@ -71,14 +78,7 @@ class DOSMediaStore {
|
|
|
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-dos"] = {}));
|
|
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 Digital Ocean Space.",
|
|
8
16
|
docsLink: "https://tina.io/packages/next-tinacms-dos"
|
|
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-dos"
|
|
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 Digital Ocean Space because one or more environment variables are missing.",
|
|
18
26
|
docsLink: "https://tina.io/docs/media-dos/"
|
|
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 Digital Ocean Space because one or more environment variables are misconfigured.",
|
|
23
31
|
docsLink: "https://tina.io/docs/media-dos/"
|
|
24
32
|
});
|
|
25
|
-
const E_BAD_ROUTE = new
|
|
33
|
+
const E_BAD_ROUTE = new MediaListError({
|
|
26
34
|
title: "Bad Route",
|
|
27
35
|
message: "The Digital Ocean Space API route is missing or misconfigured.",
|
|
28
36
|
docsLink: "https://tina.io/packages/next-tinacms-dos/#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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-tinacms-dos",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -21,25 +21,15 @@
|
|
|
21
21
|
"multer": "1.4.5-lts.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tinacms/toolkit": "0.58.
|
|
25
|
-
"@tinacms/scripts": "0.51.
|
|
24
|
+
"@tinacms/toolkit": "0.58.2",
|
|
25
|
+
"@tinacms/scripts": "0.51.3",
|
|
26
26
|
"@types/crypto-js": "^3.1.47",
|
|
27
27
|
"@types/js-cookie": "^2.2.6",
|
|
28
28
|
"@types/node": "^13.13.1",
|
|
29
|
-
"@types/react": "^16.9.43",
|
|
30
29
|
"next": "12.2.4",
|
|
31
|
-
"
|
|
32
|
-
"react-dom": "17.0.2",
|
|
33
|
-
"tinacms": "0.69.17",
|
|
30
|
+
"tinacms": "0.69.20",
|
|
34
31
|
"typescript": "4.3.5"
|
|
35
32
|
},
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"@tinacms/toolkit": "*",
|
|
38
|
-
"react": ">=16.14",
|
|
39
|
-
"react-dom": ">=16.14",
|
|
40
|
-
"react-is": "^16.13.1 || <18.0.0",
|
|
41
|
-
"tinacms": ">=0.50.0"
|
|
42
|
-
},
|
|
43
33
|
"publishConfig": {
|
|
44
34
|
"registry": "https://registry.npmjs.org"
|
|
45
35
|
},
|