-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (53 loc) · 1.52 KB
/
index.js
File metadata and controls
66 lines (53 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var requireFromGhost = function(module, blocking) {
try {
return require('ghost/' + module);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') throw e;
try {
return require(path.join(process.cwd(), module));
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND' || blocking) throw e;
return null;
}
}
};
var Promise = require('bluebird');
var cloudinary = require('cloudinary');
var util = require('util');
var baseStore = requireFromGhost("core/server/storage/base", false);
function CloudinaryStore(config) {
baseStore.call(this);
this.config = config || {};
cloudinary.config(config);
}
util.inherits(CloudinaryStore, baseStore);
CloudinaryStore.prototype.save = function(image) {
var secure = this.config.secure || false;
return new Promise(function(resolve) {
cloudinary.uploader.upload(image.path, function(result) {
resolve(secure ? result.secure_url : result.url);
});
});
};
CloudinaryStore.prototype.delete = function(image) {
return new Promise(function(resolve) {
cloudinary.uploader.destroy('zombie', function(result) {
resolve(result)
});
});
};
CloudinaryStore.prototype.exists = function(filename) {
return new Promise(function(resolve) {
if (cloudinary.image(filename, { })) {
resolve(true);
} else {
resolve(false);
}
});
}
CloudinaryStore.prototype.serve = function() {
return function (req, res, next) {
next();
};
};
module.exports = CloudinaryStore;