-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·49 lines (36 loc) · 968 Bytes
/
index.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
#!/usr/bin/env node
var moment = require('moment')
var AWS = require('aws-sdk');
var cfgfile = process.env.CONFIG || './config.json';
console.log('Loading config from ' + cfgfile);
AWS.config.loadFromPath(cfgfile);
var s3 = new AWS.S3();
var net = require('net');
var client = new net.Socket();
client.on('data', function(data) {
uploadData(data.toString('utf8'));
});
client.on('close', function() {
console.log('Connection closed');
});
client.connect(11111, 'powerraw.shack', function() {
console.log('Connected');
});
function uploadData(strval) {
client.destroy();
var params = {
Bucket: 'shack-s3',
Key: 'powerraw.shack/' + moment().format('X'),
Body: strval
};
s3.putObject(params, function(err, data) {
if (err) {
console.log("--- [ERROR] - Caching Failed");
console.log(err, err.stack); // an error occurred
}
else {
console.log("--- File Cached");
console.log(data); // successful response
}
});
}