-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·48 lines (35 loc) · 1.18 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
var watch = require('watch');
var fs = require("fs");
var request = require('request');
var util = require("util");
var monitorFolder = process.env.MONITOR_FOLDER;
var stravaToken = process.env.STRAVA_TOKEN;
util.log("Using Strava token: " + stravaToken);
var options = {
headers: {
'Authorization': 'Bearer ' + stravaToken
}
};
var callback = function optionalCallback(err, httpResponse, body) {
if (err) {
return util.error('Upload failed: ' + err);
}
util.log('Upload complete! Server responded with: ' + body);
};
var uploadActivity = function (file) {
var postRequest = request.post('http://www.strava.com/api/v3/uploads', options, callback);
var form = postRequest.form()
form.append('file', fs.createReadStream(file));
form.append('activity_type', 'ride');
form.append('data_type', 'fit');
}
watch.createMonitor(monitorFolder, function (monitor) {
util.log("Started monitoring " + monitorFolder);
monitor.on("created", function (f, stat) {
util.log("Detected new activity file " + f);
uploadActivity(f);
});
monitor.on("removed", function (f, stat) {
util.log(f + " was removed")
});
});