/
index.js
52 lines (47 loc) · 1.65 KB
/
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
50
51
52
const SpacebroClient = require('spacebro-client').SpacebroClient
var standardSettings = require('standard-settings')
const assignment = require('assignment')
const settings = standardSettings.getSettings()
var Rsync = require('rsync')
var spacebroClient = new SpacebroClient()
spacebroClient.on(settings.service.spacebro.client.in.inMedia.eventName, media => {
media = assignment(JSON.parse(JSON.stringify(settings.media)), media)
spacebroClient.emit(settings.service.spacebro.client.out.outMedia.eventName, media)
console.log('File ' + media.path + ' received')
if (media.path) {
var rsync = new Rsync()
.shell('ssh')
.flags('Paur')
.set('relative')
.source(media.path)
.destination(settings.destination + ':/')
console.log('Sending to ' + settings.destination + ':' + media.path)
// execute with stream callbacks
rsyncPid = rsync.execute(
function (error, code, cmd) {
// we're done
console.log('File ' + media.path + ' has been sent')
console.log('err:' + error)
console.log('code:' + code)
}, function (data) {
data = data.toString('utf-8')
console.log('File ' + media.path + ' progress')
console.log(data)
}, function (data) {
data = data.toString('utf-8')
console.log('File ' + media.path + ' error')
console.log(data)
}
)
}
})
var quitting = function () {
if (rsyncPid) {
rsyncPid.kill()
}
process.exit()
}
process.on('SIGINT', quitting) // run signal handler on CTRL-C
process.on('SIGTERM', quitting) // run signal handler on SIGTERM
process.on('exit', quitting) // run signal handler when main process exits
var rsyncPid