From 72f22b1cd902e549a8168a766caed8629a6f6bce Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 31 May 2018 02:37:23 -0700 Subject: [PATCH] fixes --- launcher/get-auth.js | 2 +- launcher/get-engine.js | 4 +--- launcher/get-lib.js | 2 +- lib/mr.js | 14 +++++++------- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/launcher/get-auth.js b/launcher/get-auth.js index 257d334..0a97f33 100644 --- a/launcher/get-auth.js +++ b/launcher/get-auth.js @@ -221,7 +221,7 @@ module.exports = function getAuth (cb) { } } debug('Authenticating - Please stand by...'.grey) - mr.post('https://code.bot18.net/auth/' + username, opts, function (err, resp, body) { + bot18.lib.mr_post('https://code.bot18.net/auth/' + username, opts, function (err, resp, body) { if (err) { return cb(new Error('Your network connection is down. Please try again later.')) } diff --git a/launcher/get-engine.js b/launcher/get-engine.js index 1bf7bb1..d565308 100644 --- a/launcher/get-engine.js +++ b/launcher/get-engine.js @@ -21,7 +21,6 @@ var bot18 = global.BOT18 module.exports = function getEngine (cb) { var salty = require('salty') - var mr = require('micro-request') var vm = require('vm') var zlib = require('zlib') var debug = bot18.debug('launcher') @@ -97,8 +96,7 @@ module.exports = function getEngine (cb) { return cb(new Error('Invalid request to ZalgoNet. The REST API may have changed.')) case 403: var err = new Error('Authorization expired. Please log in again.') - err.retry = true - return cb(err) + return require(r(__dirname, 'get-auth'))(cb) case 404: return cb(new Error('Invalid engine distribution channel. Please choose either "stable", "unstable", or "trial".')) case 429: diff --git a/launcher/get-lib.js b/launcher/get-lib.js index 5227ebf..b41b1e1 100644 --- a/launcher/get-lib.js +++ b/launcher/get-lib.js @@ -8,6 +8,6 @@ var bot18 = global.BOT18 module.exports = function (cb) { var r = require('path').resolve - require(r(__dirname, '..', 'lib', 'mr')) + require(r(__dirname, '..', 'lib', 'mr'))() cb() } \ No newline at end of file diff --git a/lib/mr.js b/lib/mr.js index 31177e6..8caef00 100644 --- a/lib/mr.js +++ b/lib/mr.js @@ -3,10 +3,6 @@ var bot18 = global.BOT18 module.exports = function () { function wrapMethod (method) { return function (url, opts, cb) { - if (typeof opts === 'function') { - cb = opts - opts = {} - } var defaults = { headers: { 'user-agent': bot18.user_agent @@ -15,10 +11,14 @@ module.exports = function () { if (bot18.auth && bot18.auth.authorized && bot18.auth.auth_token) { defaults.headers['x-bot18-auth'] = bot18.auth.auth_token } + if (typeof opts === 'function') { + cb = opts + opts = {} + } + var opts_copy = JSON.parse(JSON.stringify(opts)) + var opts_merged = require('lodash.defaultsdeep')(opts_copy, defaults) + return require('micro-request')[method](url, opts_merged, cb) } - var opts_copy = JSON.parse(JSON.stringify(opts)) - var opts_merged = require('lodash.defaultsdeep')(opts_copy, defaults) - return require('micro-request')[method](url, opts_merged, cb) } ;['get', 'post', 'put', 'delete'].forEach(function (method) { bot18.lib['mr_' + method] = wrapMethod(method)