mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
Token Caching now works
This commit is contained in:
@@ -23,8 +23,24 @@ var Cache = (function (_Array) {
|
||||
Cache.prototype.get = function get(key, value) {
|
||||
if (key === this[discrimS]) return this[discrimCacheS][value] || null;
|
||||
|
||||
var l = this.length;
|
||||
for (var i = 0; i < l; i++) if (this[i][key] == value) return this[i];
|
||||
for (var _iterator = this, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var _ref;
|
||||
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var item = _ref;
|
||||
|
||||
if (item[key] == value) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,10 +41,9 @@ var TokenCacher = (function (_EventEmitter) {
|
||||
|
||||
TokenCacher.prototype.setToken = function setToken(email, password, token) {
|
||||
console.log("wanting to cache", token);
|
||||
token = new Buffer(token).toString("base64");
|
||||
var cipher = _crypto2["default"].createCipher(algo, password);
|
||||
var crypted = cipher.update(token, 'utf8', 'base64');
|
||||
crypted += cipher.final('base64');
|
||||
var crypted = cipher.update("valid" + token, 'utf8', 'hex');
|
||||
crypted += cipher.final('hex');
|
||||
this.data[email] = crypted;
|
||||
this.save();
|
||||
};
|
||||
@@ -59,10 +58,11 @@ var TokenCacher = (function (_EventEmitter) {
|
||||
|
||||
try {
|
||||
var decipher = _crypto2["default"].createDecipher(algo, password);
|
||||
var dec = decipher.update(this.data[email], "base64", 'utf8');
|
||||
var dec = decipher.update(this.data[email], "hex", 'utf8');
|
||||
dec += decipher.final('utf8');
|
||||
return new Buffer(dec, "base64").toString("ascii");
|
||||
return dec.indexOf("valid") === 0 ? dec.substr(5) : false;
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user