next-tinacms-dos 0.1.4 → 1.0.0

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 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
- const cdnUrl = (options == null ? void 0 : options.cdnUrl) || config.config.endpoint.toString().replace(/http(s|):\/\//i, `https://${bucket}.`);
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 + import_path.default.basename(filePath),
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
- const result = await client.send(command);
88
- res.json(result);
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 + "/" + file.Key,
163
- previewSrc: cdnUrl + "/" + file.Key,
175
+ src: cdnUrl + file.Key,
176
+ previewSrc: cdnUrl + file.Key,
164
177
  type: "file"
165
178
  };
166
179
  };
package/dist/index.es.js CHANGED
@@ -78,14 +78,7 @@ class DOSMediaStore {
78
78
  await new Promise((resolve) => {
79
79
  setTimeout(resolve, 2e3);
80
80
  });
81
- const parsedRes = {
82
- type: "file",
83
- id: fileRes.public_id,
84
- filename: fileRes.original_filename,
85
- directory: "/",
86
- previewSrc: fileRes.url
87
- };
88
- newFiles.push(parsedRes);
81
+ newFiles.push(fileRes);
89
82
  }
90
83
  return newFiles;
91
84
  }
package/dist/index.js CHANGED
@@ -82,14 +82,7 @@
82
82
  await new Promise((resolve) => {
83
83
  setTimeout(resolve, 2e3);
84
84
  });
85
- const parsedRes = {
86
- type: "file",
87
- id: fileRes.public_id,
88
- filename: fileRes.original_filename,
89
- directory: "/",
90
- previewSrc: fileRes.url
91
- };
92
- newFiles.push(parsedRes);
85
+ newFiles.push(fileRes);
93
86
  }
94
87
  return newFiles;
95
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-tinacms-dos",
3
- "version": "0.1.4",
3
+ "version": "1.0.0",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"
@@ -21,13 +21,13 @@
21
21
  "multer": "1.4.5-lts.1"
22
22
  },
23
23
  "devDependencies": {
24
- "@tinacms/toolkit": "0.58.1",
25
- "@tinacms/scripts": "0.51.3",
24
+ "@tinacms/toolkit": "1.0.0",
25
+ "@tinacms/scripts": "1.0.0",
26
26
  "@types/crypto-js": "^3.1.47",
27
27
  "@types/js-cookie": "^2.2.6",
28
28
  "@types/node": "^13.13.1",
29
29
  "next": "12.2.4",
30
- "tinacms": "0.69.18",
30
+ "tinacms": "1.0.0",
31
31
  "typescript": "4.3.5"
32
32
  },
33
33
  "publishConfig": {