pinokiod 3.15.27 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kernel/bin/index.js +1 -0
- package/kernel/index.js +59 -0
- package/package.json +1 -1
package/kernel/bin/index.js
CHANGED
package/kernel/index.js
CHANGED
|
@@ -36,6 +36,9 @@ const Router = require("./router")
|
|
|
36
36
|
const Procs = require('./procs')
|
|
37
37
|
const Peer = require('./peer')
|
|
38
38
|
const Connect = require('./connect')
|
|
39
|
+
const { DownloaderHelper } = require('node-downloader-helper');
|
|
40
|
+
const { ProxyAgent } = require('proxy-agent');
|
|
41
|
+
const fakeUa = require('fake-useragent');
|
|
39
42
|
//const kill = require('./tree-kill');
|
|
40
43
|
const kill = require('kill-sync')
|
|
41
44
|
const VARS = {
|
|
@@ -381,6 +384,62 @@ class Kernel {
|
|
|
381
384
|
}
|
|
382
385
|
}
|
|
383
386
|
}
|
|
387
|
+
async download(options, ondata) {
|
|
388
|
+
console.log("download", { options })
|
|
389
|
+
const agent = new ProxyAgent();
|
|
390
|
+
const userAgent = fakeUa()
|
|
391
|
+
let url = options.uri
|
|
392
|
+
let cwd = options.path
|
|
393
|
+
const opts = {
|
|
394
|
+
override: true,
|
|
395
|
+
headers: {
|
|
396
|
+
"User-Agent": userAgent
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (options.filename) {
|
|
400
|
+
opts.fileName = options.filename
|
|
401
|
+
}
|
|
402
|
+
console.log("Download", opts)
|
|
403
|
+
if (process.env.HTTP_PROXY && process.env.HTTP_PROXY.length > 0) {
|
|
404
|
+
opts.httpRequestOptions = { agent }
|
|
405
|
+
opts.httpsRequestOptions = { agent }
|
|
406
|
+
}
|
|
407
|
+
if (process.env.HTTPS_PROXY && process.env.HTTPS_PROXY.length > 0) {
|
|
408
|
+
opts.httpRequestOptions = { agent }
|
|
409
|
+
opts.httpsRequestOptions = { agent }
|
|
410
|
+
}
|
|
411
|
+
const dl = new DownloaderHelper(url, cwd, opts)
|
|
412
|
+
ondata({ raw: `\r\nDownloading ${url} to ${cwd}...\r\n` })
|
|
413
|
+
let res = await new Promise((resolve, reject) => {
|
|
414
|
+
dl.on('end', () => {
|
|
415
|
+
ondata({ raw: `\r\nDownload Complete!\r\n` })
|
|
416
|
+
resolve()
|
|
417
|
+
})
|
|
418
|
+
dl.on('error', (err) => {
|
|
419
|
+
ondata({ raw: `\r\nDownload Failed: ${err.message}!\r\n` })
|
|
420
|
+
reject(err)
|
|
421
|
+
})
|
|
422
|
+
dl.on('progress', (stats) => {
|
|
423
|
+
let p = Math.floor(stats.progress)
|
|
424
|
+
let str = ""
|
|
425
|
+
for(let i=0; i<p; i++) {
|
|
426
|
+
str += "#"
|
|
427
|
+
}
|
|
428
|
+
for(let i=p; i<100; i++) {
|
|
429
|
+
str += "-"
|
|
430
|
+
}
|
|
431
|
+
ondata({ raw: `\r${str}` })
|
|
432
|
+
})
|
|
433
|
+
dl.start().catch((err) => {
|
|
434
|
+
ondata({ raw: `\r\nDownload Failed: ${err.message}!\r\n` })
|
|
435
|
+
reject(err)
|
|
436
|
+
})
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
/*
|
|
440
|
+
await this.exec({ message: `aria2 -o download.zip ${url}` })
|
|
441
|
+
*/
|
|
442
|
+
}
|
|
384
443
|
async _log(data, group, info) {
|
|
385
444
|
if (group) {
|
|
386
445
|
|