-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
64 lines (50 loc) · 1.4 KB
/
app.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
61
62
63
64
var config = require('./config.json');
// User will need to create a config.json file with twilio account creds
var twilio = require('twilio')(config.twilio.account_sid, config.twilio.auth_token);
var imgur = require('imgur');
// User will need to create a config.json file with imgur account creds
imgur.setClientId(config.imgur.account_id);
var dropTarget = $('.drop-target');
var sendImage = function (url) {
twilio.sendMessage({
to : config.twilio.phone_number,
from : '12515807869',
mediaUrl : url
}, function (error, message) {
if (!error) {
console.log('success');
} else {
console.log(error);
}
});
};
dropTarget.on('dragover', function (e) {
e.preventDefault();
e.stopPropagation();
dropTarget.addClass('drag-over');
});
dropTarget.on('dragenter', function (e) {
e.preventDefault();
e.stopPropagation();
dropTarget.addClass('drag-over');
});
dropTarget.on('dragleave', function (e) {
e.preventDefault();
e.stopPropagation();
dropTarget.removeClass('drag-over');
});
dropTarget.on('drop', function (e) {
var dt = e.originalEvent.dataTransfer;
if (dt && dt.files.length) {
e.preventDefault();
e.stopPropagation();
}
imgur.uploadFile(dt.files[0].path)
.then(function (json) {
sendImage(json.data.link);
})
.catch(function (err) {
console.error(err.message);
});
dropTarget.removeClass('drag-over');
});