ghost-storage-adapter-s3-bartt
Advanced tools
Comparing version 0.1.2-development to 0.1.3-development
43
index.js
@@ -21,4 +21,8 @@ 'use strict'; | ||
var _mmmagic = require('mmmagic'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var magic = new _mmmagic.Magic(_mmmagic.MAGIC_MIME_TYPE); | ||
var readFileAsync = function readFileAsync(fp) { | ||
@@ -146,18 +150,37 @@ return new Promise(function (resolve, reject) { | ||
resolve(_this3.saveRaw(file, fileName)); | ||
}).catch(function (err) { | ||
return reject(err); | ||
}); | ||
}); | ||
} | ||
/** | ||
* Write the image to storage, ensuring that the path to the image stats with the | ||
* prefix and that the target directory exists. The existence of `saveRaw` enables | ||
* Ghost's automatic responsive images. | ||
*/ | ||
saveRaw(buffer, fileName) { | ||
if (!fileName.startsWith(this.pathPrefix)) { | ||
fileName = (0, _path.join)(this.pathPrefix, fileName); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
magic.detect(buffer, function (err, mimeType) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
var config = { | ||
ACL: _this3.acl, | ||
Body: file, | ||
Bucket: _this3.bucket, | ||
ACL: this.acl, | ||
Body: buffer, | ||
Bucket: this.bucket, | ||
CacheControl: `max-age=${30 * 24 * 60 * 60}`, | ||
ContentType: image.type, | ||
ContentType: mimeType, | ||
Key: stripLeadingSlash(fileName) | ||
}; | ||
if (_this3.serverSideEncryption !== '') { | ||
config.ServerSideEncryption = _this3.serverSideEncryption; | ||
if (this.serverSideEncryption !== '') { | ||
config.ServerSideEncryption = this.serverSideEncryption; | ||
} | ||
_this3.s3().putObject(config, function (err, data) { | ||
return err ? reject(err) : resolve(`${_this3.host}/${fileName}`); | ||
this.s3().putObject(config, function (err, data) { | ||
return err ? reject(err) : resolve(`${this.host}/${fileName}`); | ||
}); | ||
}).catch(function (err) { | ||
return reject(err); | ||
}); | ||
@@ -164,0 +187,0 @@ }); |
@@ -36,3 +36,4 @@ { | ||
"aws-sdk": "^2.331.0", | ||
"ghost-storage-base": "0.0.1" | ||
"ghost-storage-base": "0.0.1", | ||
"mmmagic": "^0.5.3" | ||
}, | ||
@@ -77,3 +78,3 @@ "description": "An AWS S3 storage adapter for Ghost 0.10+", | ||
}, | ||
"version": "0.1.2-development" | ||
"version": "0.1.3-development" | ||
} |
@@ -5,2 +5,4 @@ import AWS from 'aws-sdk' | ||
import { readFile } from 'fs' | ||
import {MAGIC_MIME_TYPE, Magic} from 'mmmagic' | ||
const magic = new Magic(MAGIC_MIME_TYPE) | ||
@@ -110,8 +112,28 @@ const readFileAsync = fp => new Promise((resolve, reject) => readFile(fp, (err, data) => err ? reject(err) : resolve(data))) | ||
]).then(([ fileName, file ]) => { | ||
let config = { | ||
resolve(this.saveRaw(file, fileName)) | ||
}) | ||
.catch(err => reject(err)) | ||
}) | ||
} | ||
/** | ||
* Write the image to storage, ensuring that the path to the image stats with the | ||
* prefix and that the target directory exists. The existence of `saveRaw` enables | ||
* Ghost's automatic responsive images. | ||
*/ | ||
saveRaw (buffer, fileName) { | ||
if (!fileName.startsWith(this.pathPrefix)) { | ||
fileName = join(this.pathPrefix, fileName) | ||
} | ||
return new Promise(function (resolve, reject) { | ||
magic.detect(buffer, function (err, mimeType) { | ||
if (err) { | ||
return reject(err) | ||
} | ||
var config = { | ||
ACL: this.acl, | ||
Body: file, | ||
Body: buffer, | ||
Bucket: this.bucket, | ||
CacheControl: `max-age=${30 * 24 * 60 * 60}`, | ||
ContentType: image.type, | ||
ContentType: mimeType, | ||
Key: stripLeadingSlash(fileName) | ||
@@ -122,6 +144,6 @@ } | ||
} | ||
this.s3() | ||
.putObject(config, (err, data) => err ? reject(err) : resolve(`${this.host}/${fileName}`)) | ||
this.s3().putObject(config, function (err, data) { | ||
return err ? reject(err) : resolve(`${this.host}/${fileName}`) | ||
}) | ||
}) | ||
.catch(err => reject(err)) | ||
}) | ||
@@ -128,0 +150,0 @@ } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
28969
356
0
3
+ Addedmmmagic@^0.5.3
+ Addedmmmagic@0.5.3(transitive)
+ Addednan@2.22.0(transitive)