2018-01-18 20:45:50 -08:00
|
|
|
const {AssetGuard} = require('./assetguard.js')
|
|
|
|
|
2018-05-06 22:34:57 -07:00
|
|
|
const tracker = new AssetGuard(process.argv[2], process.argv[3], process.argv[4])
|
2018-01-18 20:45:50 -08:00
|
|
|
console.log('AssetExec Started')
|
|
|
|
|
|
|
|
// Temporary for debug purposes.
|
|
|
|
process.on('unhandledRejection', r => console.log(r))
|
|
|
|
|
2018-04-07 15:06:49 -07:00
|
|
|
tracker.on('assetVal', (data) => {
|
|
|
|
process.send({task: 0, total: data.total, value: data.acc, content: 'validateAssets'})
|
|
|
|
})
|
|
|
|
|
2018-01-18 20:45:50 -08:00
|
|
|
tracker.on('totaldlprogress', (data) => {
|
2018-04-02 15:40:32 -07:00
|
|
|
process.send({task: 0, total: data.total, value: data.acc, percent: parseInt((data.acc/data.total)*100), content: 'dl'})
|
2018-01-18 20:45:50 -08:00
|
|
|
})
|
|
|
|
|
2018-04-28 17:52:13 -07:00
|
|
|
tracker.on('extracting', () => {
|
|
|
|
process.send({task: 0.7, content: 'dl'})
|
|
|
|
})
|
|
|
|
|
2018-01-18 20:45:50 -08:00
|
|
|
tracker.on('dlcomplete', () => {
|
2018-04-02 15:40:32 -07:00
|
|
|
process.send({task: 1, content: 'dl'})
|
2018-01-18 20:45:50 -08:00
|
|
|
})
|
|
|
|
|
2018-04-07 15:06:49 -07:00
|
|
|
tracker.on('jExtracted', (jPath) => {
|
|
|
|
process.send({task: 2, content: 'dl', jPath})
|
|
|
|
})
|
|
|
|
|
2018-05-06 18:45:20 -07:00
|
|
|
tracker.on('dlerror', (err) => {
|
|
|
|
process.send({task: 0.9, content: 'dl', err})
|
|
|
|
})
|
|
|
|
|
2018-01-18 20:45:50 -08:00
|
|
|
process.on('message', (msg) => {
|
|
|
|
if(msg.task === 0){
|
|
|
|
const func = msg.content
|
2018-04-02 15:40:32 -07:00
|
|
|
let nS = tracker[func]
|
|
|
|
let iS = AssetGuard[func]
|
|
|
|
if(typeof nS === 'function' || typeof iS === 'function'){
|
|
|
|
const f = typeof nS === 'function' ? nS : iS
|
|
|
|
const res = f.apply(f === nS ? tracker : null, msg.argsArr)
|
2018-01-18 20:45:50 -08:00
|
|
|
if(res instanceof Promise){
|
|
|
|
res.then((v) => {
|
2018-04-02 15:40:32 -07:00
|
|
|
process.send({result: v, content: msg.content})
|
2018-05-08 03:34:16 -07:00
|
|
|
}).catch((err) => {
|
2018-05-08 17:10:46 -07:00
|
|
|
process.send({result: err, content: msg.content})
|
2018-01-18 20:45:50 -08:00
|
|
|
})
|
|
|
|
} else {
|
2018-04-02 15:40:32 -07:00
|
|
|
process.send({result: res, content: msg.content})
|
2018-01-18 20:45:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
process.on('disconnect', () => {
|
|
|
|
console.log('AssetExec Disconnected')
|
|
|
|
process.exit(0)
|
|
|
|
})
|