-
Notifications
You must be signed in to change notification settings - Fork 11
/
autoform-cloudinary-server.js
60 lines (49 loc) · 1.29 KB
/
autoform-cloudinary-server.js
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
var cloudinary = Npm.require('cloudinary');
if (process.env.CLOUDINARY_URL) {
var cloudinaryURL = new URI(process.env.CLOUDINARY_URL);
}
Meteor.methods({
afCloudinarySign: function (params) {
check(params, Match.Optional(Object));
params = params || {};
params.timestamp = (new Date).getTime();
return cloudinary.utils.sign_request(params, {
api_key: apiKey(),
api_secret: apiSecret()
});
},
publicCredentials: function() {
if (cloudinaryURL) {
return {
cloudName: apiHost(),
apiKey: apiKey()
}
}
}
});
apiHost = function() {
if (cloudinaryURL) {
return cloudinaryURL.hostname();
}
};
apiKey = function () {
if (cloudinaryURL) {
return cloudinaryURL.username();
}
if (! Meteor.settings ||
! Meteor.settings.public ||
! Meteor.settings.public.CLOUDINARY_API_KEY) {
throw new Error('Meteor.settings.public.CLOUDINARY_API_KEY is undefined');
}
return Meteor.settings.public.CLOUDINARY_API_KEY;
};
apiSecret = function () {
if (cloudinaryURL) {
return cloudinaryURL.password();
}
if (! Meteor.settings ||
! Meteor.settings.CLOUDINARY_API_SECRET) {
throw new Error('Meteor.settings.CLOUDINARY_API_SECRET is undefined');
}
return Meteor.settings.CLOUDINARY_API_SECRET;
};