Skip to content

Commit 85ef816

Browse files
authored
Merge pull request #122 from eexit/upgrade-deps
Update deps + replace request by got
2 parents 655b965 + 7eb9ab9 commit 85ef816

File tree

6 files changed

+716
-465
lines changed

6 files changed

+716
-465
lines changed

.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"parserOptions": {
3-
"ecmaVersion": 6,
3+
"ecmaVersion": 8,
44
"ecmaFeatures": {}
55
},
66
"rules": {
@@ -182,7 +182,6 @@
182182
"no-whitespace-before-property": 2,
183183
"no-with": 2,
184184
"nonblock-statement-body-position": 2,
185-
"object-curly-spacing": 2,
186185
"object-shorthand": [2, "consistent"],
187186
"one-var": 2,
188187
"operator-assignment": 2,

index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require('bluebird');
55
const StorageBase = require('ghost-storage-base'),
66
cloudinary = require('cloudinary').v2,
77
path = require('path'),
8-
request = require('request').defaults({encoding: null}),
8+
got = require('got'),
99
plugin = require(path.join(__dirname, '/plugins')),
1010
debug = require('ghost-ignition').debug('adapter'),
1111
common = (() => {
@@ -53,7 +53,7 @@ class CloudinaryAdapter extends StorageBase {
5353
exists(filename) {
5454
const pubId = this.toCloudinaryId(filename);
5555

56-
return new Promise((resolve) => cloudinary.uploader.explicit(pubId, {type: 'upload'}, (err) => {
56+
return new Promise((resolve) => cloudinary.uploader.explicit(pubId, { type: 'upload' }, (err) => {
5757
if (err) {
5858
return resolve(false);
5959
}
@@ -73,7 +73,7 @@ class CloudinaryAdapter extends StorageBase {
7373
if (uploaderOptions.upload.use_filename !== 'undefined' && uploaderOptions.upload.use_filename) {
7474
Object.assign(
7575
uploaderOptions.upload,
76-
{public_id: path.parse(this.getSanitizedFileName(image.name)).name}
76+
{ public_id: path.parse(this.getSanitizedFileName(image.name)).name }
7777
);
7878
}
7979

@@ -150,15 +150,17 @@ class CloudinaryAdapter extends StorageBase {
150150
*/
151151
read(options) {
152152
const opts = options || {};
153-
return new Promise((resolve, reject) => request.get(opts.path, (err, res) => {
154-
if (err) {
153+
return new Promise(async (resolve, reject) => {
154+
try {
155+
return resolve(await got(opts.path, { responseType: 'buffer',
156+
resolveBodyOnly: true }));
157+
} catch (err) {
155158
return reject(new common.errors.GhostError({
156159
err: err,
157160
message: `Could not read image ${opts.path}`
158161
}));
159162
}
160-
return resolve(res.body);
161-
}));
163+
});
162164
}
163165

164166
/**

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,21 @@
4040
},
4141
"dependencies": {
4242
"bluebird": "^3.7.0",
43-
"cloudinary": "~1.23.0",
44-
"ghost-ignition": "^4.2.2",
43+
"cloudinary": "~1.25.1",
44+
"ghost-ignition": "^4.6.1",
4545
"ghost-storage-base": "0.0.5",
46+
"got": "^11.8.2",
4647
"image-size": "^0.9.2",
4748
"lodash": "^4.17.20",
4849
"os-locale": "^5.0.0"
4950
},
5051
"devDependencies": {
5152
"chai": "^4.2.0",
5253
"eslint": "^7.17.0",
53-
"eslint-plugin-mocha": "^7.0.1",
54+
"eslint-plugin-mocha": "^8.1.0",
5455
"moment": "^2.29.1",
55-
"nock": "^12.0.3",
56+
"nock": "^13.0.11",
5657
"nyc": "^15.0.0",
57-
"sinon": "^9.2.2"
58+
"sinon": "^10.0.0"
5859
}
5960
}

tests/.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"plugins": ["mocha"],
33
"parserOptions": {
4-
"ecmaVersion": 6,
4+
"ecmaVersion": 8,
55
"ecmaFeatures": {}
66
},
77
"rules": {
@@ -182,7 +182,6 @@
182182
"no-whitespace-before-property": 2,
183183
"no-with": 2,
184184
"nonblock-statement-body-position": 2,
185-
"object-curly-spacing": 2,
186185
"object-shorthand": 2,
187186
"one-var": 2,
188187
"operator-assignment": 2,

tests/adapter/read.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('read', function () {
1616
cloudinaryAdapter = new CloudinaryAdapter(fixtures.sampleConfig);
1717
const scope = nock('https://blog.mornati.net')
1818
.get('/myimage.png')
19-
.reply(200, {"body": "imagecontent"}),
20-
options = {"path": "https://blog.mornati.net/myimage.png"};
19+
.reply(200, { "body": "imagecontent" }),
20+
options = { "path": "https://blog.mornati.net/myimage.png" };
2121

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

4646
cloudinaryAdapter = new CloudinaryAdapter(fixtures.sampleConfig);
4747
cloudinaryAdapter.read(options)

0 commit comments

Comments
 (0)