2019-02-14 13:29:21 +08:00
|
|
|
const SteamCommunity = require('../index.js');
|
2015-11-27 14:28:31 +08:00
|
|
|
|
2015-12-03 10:35:35 +08:00
|
|
|
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
|
2016-03-05 07:26:47 +08:00
|
|
|
this.httpRequest({
|
2021-07-22 16:02:38 +08:00
|
|
|
uri: 'https://steamcommunity.com/dev/apikey?l=english',
|
|
|
|
followRedirect: false
|
|
|
|
}, (err, response, body) => {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-12-03 10:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-22 16:02:38 +08:00
|
|
|
if (body.includes('<h2>Access Denied</h2>')) {
|
|
|
|
return callback(new Error('Access Denied'));
|
2015-12-03 10:35:35 +08:00
|
|
|
}
|
2019-02-14 13:29:21 +08:00
|
|
|
|
2021-07-22 16:02:38 +08:00
|
|
|
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.'));
|
2018-01-22 10:48:45 +08:00
|
|
|
}
|
2015-12-03 10:35:35 +08:00
|
|
|
|
2021-07-22 16:02:38 +08:00
|
|
|
let match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
|
|
|
|
if (match) {
|
2015-12-03 10:35:35 +08:00
|
|
|
// We already have an API key registered
|
|
|
|
callback(null, match[1]);
|
|
|
|
} else {
|
|
|
|
// We need to register a new API key
|
2021-07-22 16:02:38 +08:00
|
|
|
this.httpRequestPost('https://steamcommunity.com/dev/registerkey?l=english', {
|
|
|
|
form: {
|
|
|
|
domain,
|
|
|
|
agreeToTerms: 'agreed',
|
|
|
|
sessionid: this.getSessionID(),
|
|
|
|
Submit: 'Register'
|
2015-12-03 10:35:35 +08:00
|
|
|
}
|
2021-07-22 16:02:38 +08:00
|
|
|
}, (err, response, body) => {
|
2016-03-05 12:59:49 +08:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
2015-12-03 10:35:35 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-22 16:02:38 +08:00
|
|
|
this.getWebApiKey(domain, callback);
|
|
|
|
}, 'steamcommunity');
|
2015-12-03 10:35:35 +08:00
|
|
|
}
|
2021-07-22 16:02:38 +08:00
|
|
|
}, 'steamcommunity');
|
2015-12-03 10:35:35 +08:00
|
|
|
};
|