Cleaned up webapi.js

This commit is contained in:
Alex Corn 2021-07-22 04:02:38 -04:00
parent 9a4be453ec
commit c69a5451eb
No known key found for this signature in database
GPG Key ID: E51989A3E7A27FDF

View File

@ -1,47 +1,46 @@
const SteamCommunity = require('../index.js');
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
var self = this;
this.httpRequest({
"uri": "https://steamcommunity.com/dev/apikey?l=english",
"followRedirect": false
}, function(err, response, body) {
uri: 'https://steamcommunity.com/dev/apikey?l=english',
followRedirect: false
}, (err, response, body) => {
if (err) {
callback(err);
return;
}
if(body.match(/<h2>Access Denied<\/h2>/)) {
return callback(new Error("Access Denied"));
if (body.includes('<h2>Access Denied</h2>')) {
return callback(new Error('Access Denied'));
}
if(body.match(/You must have a validated email address to create a Steam Web API key./)) {
return callback(new Error("You must have a validated email address to create a Steam Web API key."));
if (body.includes('You must have a validated email address to create a Steam Web API key.')) {
return callback(new Error('You must have a validated email address to create a Steam Web API key.'));
}
var match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
if(match) {
let match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
if (match) {
// We already have an API key registered
callback(null, match[1]);
} else {
// We need to register a new API key
self.httpRequestPost('https://steamcommunity.com/dev/registerkey?l=english', {
"form": {
"domain": domain,
"agreeToTerms": "agreed",
"sessionid": self.getSessionID(),
"Submit": "Register"
this.httpRequestPost('https://steamcommunity.com/dev/registerkey?l=english', {
form: {
domain,
agreeToTerms: 'agreed',
sessionid: this.getSessionID(),
Submit: 'Register'
}
}, function(err, response, body) {
}, (err, response, body) => {
if (err) {
callback(err);
return;
}
self.getWebApiKey(domain, callback);
}, "steamcommunity");
this.getWebApiKey(domain, callback);
}, 'steamcommunity');
}
}, "steamcommunity");
}, 'steamcommunity');
};
/**