-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_upload.js
147 lines (100 loc) · 4.39 KB
/
db_upload.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var express = require('express'),
http = require("http"),
url = require("url"),
multipart = require("multipart"),
sys = require("sys"),
hbs = require ("hbs"),
fs = require('fs'),
Dropbox = require('dropbox'),
email = require("emailjs/email"),
exec = require('child_process').exec,
app = express();
var server = email.server.connect({
user: <gmail username>
password:<gmail Password>,
host: "smtp.gmail.com",
ssl: true
});
app.use(express.bodyParser());
app.set('view engine', 'html');
app.engine('html', hbs.__express);
var client = new Dropbox.Client({
"key": <DropBox key>,
"secret": <Dropbox Secret Key>,
"token": <Dropbox Token>,
"uid": <DropBox UID>
});
client.authenticate({interactive:false},function (error, client) {
if (error) {
console.log(error);
}
if (client.isAuthenticated()) {
console.log("Dropbox Auth done");
}
});
app.get('/', function (req, res) {
res.render('index');
});
/* File upload Module.. 'f' reads the file sent By client and it is written to Dropbox By client.writeFile method!*/
app.post('/upload', function (req, res) {
var f = req.files.uploads;
var email_add =req.body.email_add;
var phone_add = req.body.phone_add;
var dbx_file_stat;
var short_url;
var whatsapp = phone_add.split(',');
console.log("File Upload in progress...File name: "+f.name);
fs.readFile(f.path, function (error, data) {
if (error) {
return console.log(error);
}
client.writeFile(f.name, data, function (error, stat) {
if (error) {
return console.log(error);
}
client.makeUrl(f.name, {downloadHack:true},function (error,url) {
if (error) {
return console.log(error);
}
client.stat(f.name,function(error,stat){
dbx_file_stat = {name:stat.name,Icon:stat.typeIcon,version:stat.versionTag,mimeType:stat.mimeType,size:stat.size,humansize:stat.humanSize,hasIcon:stat.hasThumbnail,long_url:url.url};
var email_body = "\"Hi,\nYour friend recently Uploaded a new File To dropbox and shared it With you.\nHere's the link,\n"+url.url+"\nPlease go to this link and Download the file.\n\nFile information,\n"+"FileName:"+stat.name+"\nFileType:"+stat.mimeType+"\nFilesize:"+stat.humanSize+"\n------------------------------------------------------\nThanks\nEmail@ [email protected]\n\nA techieB! Initiative!\"";
client.makeUrl(f.name, {downloadHack:false},function (error,url) {
if (error) {
return console.log(error);
}
short_url = url.url;
var text_message = "\"Hi, Your friend Recently Uploaded a file. Details:- File name: "+stat.name+",File link: "+short_url+" For more details about file , please check your mailbox PS->This is a Autogenerated messgae please don't reply here.. A techieB! Initiative\"";
// send the message and get a callback with an error or details of the message that was sent
server.send({
text: email_body,
from: <Your Gmail Address>,
to: email_add,
cc: "",
subject: "You have got a Dropbox link!"
}, function(err, message) { console.log(err || message); });
/*Logic for sending Whatsapp Message*/
whatsapp.forEach(function(whatsap,i){
console.log(whatsapp[i]);
var command = "yowsup/src/yowsup-cli.py -s " +whatsapp[i]+" "+text_message+" -c yowsup/src/config.txt";
child = exec(command,function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
console.log(command);
}
else
console.log("Success! "+whatsapp[i]+" "+command);
});
})
});
res.type('text/plain');
res.send({name:stat.name,Icon:stat.typeIcon,version:stat.versionTag,mimeType:stat.mimeType,size:stat.size,humansize:stat.humanSize,hasIcon:stat.hasThumbnail,long_url:url.url});
res.end();
});
});
});
});
})
app.use('/static', express.static(__dirname + '/static'));
app.listen(8080);
console.log("Running on port 8080");