Skip to content

Commit

Permalink
Merge pull request #122 from eexit/upgrade-deps
Browse files Browse the repository at this point in the history
Update deps + replace request by got
  • Loading branch information
eexit authored Mar 31, 2021
2 parents 655b965 + 7eb9ab9 commit 85ef816
Show file tree
Hide file tree
Showing 6 changed files with 716 additions and 465 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 8,
"ecmaFeatures": {}
},
"rules": {
Expand Down Expand Up @@ -182,7 +182,6 @@
"no-whitespace-before-property": 2,
"no-with": 2,
"nonblock-statement-body-position": 2,
"object-curly-spacing": 2,
"object-shorthand": [2, "consistent"],
"one-var": 2,
"operator-assignment": 2,
Expand Down
16 changes: 9 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require('bluebird');
const StorageBase = require('ghost-storage-base'),
cloudinary = require('cloudinary').v2,
path = require('path'),
request = require('request').defaults({encoding: null}),
got = require('got'),
plugin = require(path.join(__dirname, '/plugins')),
debug = require('ghost-ignition').debug('adapter'),
common = (() => {
Expand Down Expand Up @@ -53,7 +53,7 @@ class CloudinaryAdapter extends StorageBase {
exists(filename) {
const pubId = this.toCloudinaryId(filename);

return new Promise((resolve) => cloudinary.uploader.explicit(pubId, {type: 'upload'}, (err) => {
return new Promise((resolve) => cloudinary.uploader.explicit(pubId, { type: 'upload' }, (err) => {
if (err) {
return resolve(false);
}
Expand All @@ -73,7 +73,7 @@ class CloudinaryAdapter extends StorageBase {
if (uploaderOptions.upload.use_filename !== 'undefined' && uploaderOptions.upload.use_filename) {
Object.assign(
uploaderOptions.upload,
{public_id: path.parse(this.getSanitizedFileName(image.name)).name}
{ public_id: path.parse(this.getSanitizedFileName(image.name)).name }
);
}

Expand Down Expand Up @@ -150,15 +150,17 @@ class CloudinaryAdapter extends StorageBase {
*/
read(options) {
const opts = options || {};
return new Promise((resolve, reject) => request.get(opts.path, (err, res) => {
if (err) {
return new Promise(async (resolve, reject) => {
try {
return resolve(await got(opts.path, { responseType: 'buffer',
resolveBodyOnly: true }));
} catch (err) {
return reject(new common.errors.GhostError({
err: err,
message: `Could not read image ${opts.path}`
}));
}
return resolve(res.body);
}));
});
}

/**
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@
},
"dependencies": {
"bluebird": "^3.7.0",
"cloudinary": "~1.23.0",
"ghost-ignition": "^4.2.2",
"cloudinary": "~1.25.1",
"ghost-ignition": "^4.6.1",
"ghost-storage-base": "0.0.5",
"got": "^11.8.2",
"image-size": "^0.9.2",
"lodash": "^4.17.20",
"os-locale": "^5.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.17.0",
"eslint-plugin-mocha": "^7.0.1",
"eslint-plugin-mocha": "^8.1.0",
"moment": "^2.29.1",
"nock": "^12.0.3",
"nock": "^13.0.11",
"nyc": "^15.0.0",
"sinon": "^9.2.2"
"sinon": "^10.0.0"
}
}
3 changes: 1 addition & 2 deletions tests/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"plugins": ["mocha"],
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 8,
"ecmaFeatures": {}
},
"rules": {
Expand Down Expand Up @@ -182,7 +182,6 @@
"no-whitespace-before-property": 2,
"no-with": 2,
"nonblock-statement-body-position": 2,
"object-curly-spacing": 2,
"object-shorthand": 2,
"one-var": 2,
"operator-assignment": 2,
Expand Down
6 changes: 3 additions & 3 deletions tests/adapter/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe('read', function () {
cloudinaryAdapter = new CloudinaryAdapter(fixtures.sampleConfig);
const scope = nock('https://blog.mornati.net')
.get('/myimage.png')
.reply(200, {"body": "imagecontent"}),
options = {"path": "https://blog.mornati.net/myimage.png"};
.reply(200, { "body": "imagecontent" }),
options = { "path": "https://blog.mornati.net/myimage.png" };

cloudinaryAdapter.read(options).then(function () {
done(scope.done());
Expand All @@ -41,7 +41,7 @@ describe('read', function () {
const scope = nock('https://blog.mornati.net')
.get('/myimage.png')
.replyWithError('some error occurred'),
options = {"path": "https://blog.mornati.net/myimage.png"};
options = { "path": "https://blog.mornati.net/myimage.png" };

cloudinaryAdapter = new CloudinaryAdapter(fixtures.sampleConfig);
cloudinaryAdapter.read(options)
Expand Down
Loading

0 comments on commit 85ef816

Please sign in to comment.