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