(name, opts)
| 514 | // 来自 @chavyleung 大佬 |
| 515 | // https://raw.githubusercontent.com/chavyleung/scripts/master/Env.js |
| 516 | function Env(name, opts) { |
| 517 | class Http { |
| 518 | constructor(env) { |
| 519 | this.env = env |
| 520 | } |
| 521 | |
| 522 | send(opts, method = 'GET') { |
| 523 | opts = typeof opts === 'string' ? { |
| 524 | url: opts |
| 525 | } : opts |
| 526 | let sender = this.get |
| 527 | if (method === 'POST') { |
| 528 | sender = this.post |
| 529 | } |
| 530 | return new Promise((resolve, reject) => { |
| 531 | sender.call(this, opts, (err, resp, body) => { |
| 532 | if (err) reject(err) |
| 533 | else resolve(resp) |
| 534 | }) |
| 535 | }) |
| 536 | } |
| 537 | |
| 538 | get(opts) { |
| 539 | return this.send.call(this.env, opts) |
| 540 | } |
| 541 | |
| 542 | post(opts) { |
| 543 | return this.send.call(this.env, opts, 'POST') |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | return new(class { |
| 548 | constructor(name, opts) { |
| 549 | this.name = name |
| 550 | this.http = new Http(this) |
| 551 | this.data = null |
| 552 | this.dataFile = 'box.dat' |
| 553 | this.logs = [] |
| 554 | this.isMute = false |
| 555 | this.isNeedRewrite = false |
| 556 | this.logSeparator = '\n' |
| 557 | this.startTime = new Date().getTime() |
| 558 | Object.assign(this, opts) |
| 559 | this.log('', `🔔${this.name}, 开始!`) |
| 560 | } |
| 561 | |
| 562 | isNode() { |
| 563 | return 'undefined' !== typeof module && !!module.exports |
| 564 | } |
| 565 | |
| 566 | isQuanX() { |
| 567 | return 'undefined' !== typeof $task |
| 568 | } |
| 569 | |
| 570 | isSurge() { |
| 571 | return 'undefined' !== typeof $httpClient && 'undefined' === typeof $loon |
| 572 | } |
| 573 |
nothing calls this directly
no outgoing calls
no test coverage detected