mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-03-23 21:50:10 +08:00
Cleaned up webapi.js
This commit is contained in:
parent
9a4be453ec
commit
c69a5451eb
@ -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');
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user