steamcommunity 3.46.0 → 3.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classes/CConfirmation.js +37 -37
- package/classes/CEconItem.js +120 -120
- package/classes/CMarketItem.js +189 -189
- package/classes/CMarketSearchResult.js +89 -89
- package/classes/CSteamGroup.js +155 -155
- package/classes/CSteamUser.js +225 -217
- package/components/chat.js +283 -283
- package/components/confirmations.js +428 -428
- package/components/groups.js +798 -732
- package/components/help.js +64 -64
- package/components/helpers.js +128 -108
- package/components/http.js +150 -150
- package/components/inventoryhistory.js +173 -173
- package/components/market.js +387 -387
- package/components/profile.js +475 -475
- package/components/twofactor.js +152 -152
- package/components/users.js +831 -767
- package/components/webapi.js +118 -118
- package/examples/accept_all_confirmations.js +1 -1
- package/examples/edit-group-announcement.js +118 -118
- package/package.json +9 -2
- package/resources/EChatState.js +14 -14
- package/resources/EConfirmationType.js +12 -12
- package/resources/EFriendRelationship.js +23 -23
- package/resources/EPersonaState.js +23 -23
- package/resources/EPersonaStateFlag.js +32 -32
- package/resources/EResult.js +254 -254
- package/resources/ESharedFileType.js +13 -13
- package/.editorconfig +0 -13
- package/.github/FUNDING.yml +0 -2
- package/.idea/.name +0 -1
- package/.idea/codeStyleSettings.xml +0 -13
- package/.idea/codeStyles/Project.xml +0 -15
- package/.idea/codeStyles/codeStyleConfig.xml +0 -6
- package/.idea/copyright/profiles_settings.xml +0 -3
- package/.idea/encodings.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -11
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -9
- package/.idea/node-steamcommunity.iml +0 -8
- package/.idea/steamcommunity.iml +0 -10
- package/.idea/vcs.xml +0 -7
- package/.idea/watcherTasks.xml +0 -4
- package/CONTRIBUTING.md +0 -36
package/components/help.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
const SteamCommunity = require('../index.js');
|
|
2
|
-
|
|
3
|
-
const Helpers = require('./helpers.js');
|
|
4
|
-
|
|
5
|
-
const HELP_SITE_DOMAIN = 'https://help.steampowered.com';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Restore a previously removed steam package from your steam account.
|
|
9
|
-
* @param {int|string} packageID
|
|
10
|
-
* @param {function} callback
|
|
11
|
-
*/
|
|
12
|
-
SteamCommunity.prototype.restorePackage = function(packageID, callback) {
|
|
13
|
-
this.httpRequestPost({
|
|
14
|
-
uri: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRestore',
|
|
15
|
-
form: {
|
|
16
|
-
packageid: packageID,
|
|
17
|
-
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
|
18
|
-
wizard_ajax: 1
|
|
19
|
-
},
|
|
20
|
-
json: true
|
|
21
|
-
}, wizardAjaxHandler(callback));
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Remove a steam package from your steam account.
|
|
26
|
-
* @param {int|string} packageID
|
|
27
|
-
* @param {function} callback
|
|
28
|
-
*/
|
|
29
|
-
SteamCommunity.prototype.removePackage = function(packageID, callback) {
|
|
30
|
-
this.httpRequestPost({
|
|
31
|
-
uri: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRemove',
|
|
32
|
-
form: {
|
|
33
|
-
packageid: packageID,
|
|
34
|
-
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
|
35
|
-
wizard_ajax: 1
|
|
36
|
-
},
|
|
37
|
-
json: true
|
|
38
|
-
}, wizardAjaxHandler(callback));
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Returns a handler for wizard ajax HTTP requests.
|
|
43
|
-
* @param {function} callback
|
|
44
|
-
* @returns {(function(*=, *, *): void)|*}
|
|
45
|
-
*/
|
|
46
|
-
function wizardAjaxHandler(callback) {
|
|
47
|
-
return (err, res, body) => {
|
|
48
|
-
if (!callback) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (err) {
|
|
53
|
-
callback(err);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!body.success) {
|
|
58
|
-
callback(body.errorMsg ? new Error(body.errorMsg) : Helpers.eresultError(body.success));
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
callback(null);
|
|
63
|
-
};
|
|
64
|
-
}
|
|
1
|
+
const SteamCommunity = require('../index.js');
|
|
2
|
+
|
|
3
|
+
const Helpers = require('./helpers.js');
|
|
4
|
+
|
|
5
|
+
const HELP_SITE_DOMAIN = 'https://help.steampowered.com';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Restore a previously removed steam package from your steam account.
|
|
9
|
+
* @param {int|string} packageID
|
|
10
|
+
* @param {function} callback
|
|
11
|
+
*/
|
|
12
|
+
SteamCommunity.prototype.restorePackage = function(packageID, callback) {
|
|
13
|
+
this.httpRequestPost({
|
|
14
|
+
uri: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRestore',
|
|
15
|
+
form: {
|
|
16
|
+
packageid: packageID,
|
|
17
|
+
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
|
18
|
+
wizard_ajax: 1
|
|
19
|
+
},
|
|
20
|
+
json: true
|
|
21
|
+
}, wizardAjaxHandler(callback));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Remove a steam package from your steam account.
|
|
26
|
+
* @param {int|string} packageID
|
|
27
|
+
* @param {function} callback
|
|
28
|
+
*/
|
|
29
|
+
SteamCommunity.prototype.removePackage = function(packageID, callback) {
|
|
30
|
+
this.httpRequestPost({
|
|
31
|
+
uri: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRemove',
|
|
32
|
+
form: {
|
|
33
|
+
packageid: packageID,
|
|
34
|
+
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
|
35
|
+
wizard_ajax: 1
|
|
36
|
+
},
|
|
37
|
+
json: true
|
|
38
|
+
}, wizardAjaxHandler(callback));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns a handler for wizard ajax HTTP requests.
|
|
43
|
+
* @param {function} callback
|
|
44
|
+
* @returns {(function(*=, *, *): void)|*}
|
|
45
|
+
*/
|
|
46
|
+
function wizardAjaxHandler(callback) {
|
|
47
|
+
return (err, res, body) => {
|
|
48
|
+
if (!callback) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (err) {
|
|
53
|
+
callback(err);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!body.success) {
|
|
58
|
+
callback(body.errorMsg ? new Error(body.errorMsg) : Helpers.eresultError(body.success));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
callback(null);
|
|
63
|
+
};
|
|
64
|
+
}
|
package/components/helpers.js
CHANGED
|
@@ -1,108 +1,128 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const xml2js = require('xml2js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
date.
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
};
|
|
1
|
+
const request = require('request');
|
|
2
|
+
const SteamID = require('steamid');
|
|
3
|
+
const xml2js = require('xml2js');
|
|
4
|
+
|
|
5
|
+
const EResult = require('../resources/EResult.js');
|
|
6
|
+
|
|
7
|
+
exports.isSteamID = function(input) {
|
|
8
|
+
var keys = Object.keys(input);
|
|
9
|
+
if (keys.length != 4) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Make sure it has the keys we expect
|
|
14
|
+
keys = keys.filter(function(item) {
|
|
15
|
+
return ['universe', 'type', 'instance', 'accountid'].indexOf(item) != -1;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return keys.length == 4;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.decodeSteamTime = function(time) {
|
|
22
|
+
var date = new Date();
|
|
23
|
+
|
|
24
|
+
if (time.includes("@")) {
|
|
25
|
+
var parts = time.split('@');
|
|
26
|
+
if (!parts[0].includes(",")) {
|
|
27
|
+
// no year, assume current year
|
|
28
|
+
parts[0] += ", " + date.getFullYear();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
date = new Date(parts.join('@').replace(/(am|pm)/, ' $1') + " UTC"); // add a space so JS can decode it
|
|
32
|
+
} else {
|
|
33
|
+
// Relative date
|
|
34
|
+
var amount = time.replace(/(\d) (minutes|hour|hours) ago/, "$1");
|
|
35
|
+
|
|
36
|
+
if(time.includes("minutes")) {
|
|
37
|
+
date.setMinutes(date.getMinutes() - amount);
|
|
38
|
+
} else if(time.match(/hour|hours/)) {
|
|
39
|
+
date.setHours(date.getHours() - amount);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return date;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get an Error object for a particular EResult
|
|
48
|
+
* @param {int} eresult
|
|
49
|
+
* @returns {null|Error}
|
|
50
|
+
*/
|
|
51
|
+
exports.eresultError = function(eresult) {
|
|
52
|
+
if (eresult == EResult.OK) {
|
|
53
|
+
// no error
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var err = new Error(EResult[eresult] || ("Error " + eresult));
|
|
58
|
+
err.eresult = eresult;
|
|
59
|
+
return err;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.decodeJwt = function(jwt) {
|
|
63
|
+
let parts = jwt.split('.');
|
|
64
|
+
if (parts.length != 3) {
|
|
65
|
+
throw new Error('Invalid JWT');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let standardBase64 = parts[1].replace(/-/g, '+')
|
|
69
|
+
.replace(/_/g, '/');
|
|
70
|
+
|
|
71
|
+
return JSON.parse(Buffer.from(standardBase64, 'base64').toString('utf8'));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Resolves a Steam profile URL to get steamID64 and vanityURL
|
|
76
|
+
* @param {String} url - Full steamcommunity profile URL or only the vanity part.
|
|
77
|
+
* @param {Object} callback - First argument is null/Error, second is object containing vanityURL (String) and steamID (String)
|
|
78
|
+
*/
|
|
79
|
+
exports.resolveVanityURL = function(url, callback) {
|
|
80
|
+
// Precede url param if only the vanity was provided
|
|
81
|
+
if (!url.includes("steamcommunity.com")) {
|
|
82
|
+
url = "https://steamcommunity.com/id/" + url;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Make request to get XML data
|
|
86
|
+
request(url + "/?xml=1", function(err, response, body) {
|
|
87
|
+
if (err) {
|
|
88
|
+
callback(err);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Parse XML data returned from Steam into an object
|
|
93
|
+
new xml2js.Parser().parseString(body, (err, parsed) => {
|
|
94
|
+
if (err) {
|
|
95
|
+
callback(new Error("Couldn't parse XML response"));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (parsed.response && parsed.response.error) {
|
|
100
|
+
callback(new Error("Couldn't find Steam ID"));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let steamID64 = parsed.profile.steamID64[0];
|
|
105
|
+
let vanityURL = parsed.profile.customURL[0];
|
|
106
|
+
|
|
107
|
+
callback(null, {"vanityURL": vanityURL, "steamID": steamID64});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Converts `input` into a SteamID object, if it's a parseable string.
|
|
114
|
+
* @param {SteamID|string} input
|
|
115
|
+
* @return {SteamID}
|
|
116
|
+
*/
|
|
117
|
+
exports.steamID = function(input) {
|
|
118
|
+
if (exports.isSteamID(input)) {
|
|
119
|
+
return input;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof input != 'string') {
|
|
123
|
+
throw new Error(`Input SteamID value "${input}" is not a string`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// This will throw if the input is not a well-formed SteamID
|
|
127
|
+
return new SteamID(input);
|
|
128
|
+
};
|
package/components/http.js
CHANGED
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
var SteamCommunity = require('../index.js');
|
|
2
|
-
|
|
3
|
-
SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) {
|
|
4
|
-
if (typeof uri === 'object') {
|
|
5
|
-
source = callback;
|
|
6
|
-
callback = options;
|
|
7
|
-
options = uri;
|
|
8
|
-
uri = options.url || options.uri;
|
|
9
|
-
} else if (typeof options === 'function') {
|
|
10
|
-
source = callback;
|
|
11
|
-
callback = options;
|
|
12
|
-
options = {};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
options.url = options.uri = uri;
|
|
16
|
-
|
|
17
|
-
if (this._httpRequestConvenienceMethod) {
|
|
18
|
-
options.method = this._httpRequestConvenienceMethod;
|
|
19
|
-
delete this._httpRequestConvenienceMethod;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var requestID = ++this._httpRequestID;
|
|
23
|
-
source = source || "";
|
|
24
|
-
|
|
25
|
-
var self = this;
|
|
26
|
-
var continued = false;
|
|
27
|
-
|
|
28
|
-
if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
|
|
29
|
-
// No pre-hook, or the pre-hook doesn't want to delay the request.
|
|
30
|
-
continueRequest(null);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function continueRequest(err) {
|
|
34
|
-
if (continued) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
continued = true;
|
|
39
|
-
|
|
40
|
-
if (err) {
|
|
41
|
-
if (callback) {
|
|
42
|
-
callback(err);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
self.request(options, function (err, response, body) {
|
|
49
|
-
var hasCallback = !!callback;
|
|
50
|
-
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback, body);
|
|
51
|
-
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
|
|
52
|
-
var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {} : callback); // don't fire the callback if either of the previous already did
|
|
53
|
-
var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null;
|
|
54
|
-
|
|
55
|
-
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || jsonError || null, response, body, {
|
|
56
|
-
"hasCallback": hasCallback,
|
|
57
|
-
"httpError": httpError,
|
|
58
|
-
"communityError": communityError,
|
|
59
|
-
"tradeError": tradeError,
|
|
60
|
-
"jsonError": jsonError
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
if (hasCallback && !(httpError || communityError || tradeError)) {
|
|
64
|
-
if (jsonError) {
|
|
65
|
-
callback.call(self, jsonError, response);
|
|
66
|
-
} else {
|
|
67
|
-
callback.apply(self, arguments);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
SteamCommunity.prototype.httpRequestGet = function() {
|
|
75
|
-
this._httpRequestConvenienceMethod = "GET";
|
|
76
|
-
return this.httpRequest.apply(this, arguments);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
SteamCommunity.prototype.httpRequestPost = function() {
|
|
80
|
-
this._httpRequestConvenienceMethod = "POST";
|
|
81
|
-
return this.httpRequest.apply(this, arguments);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
SteamCommunity.prototype._notifySessionExpired = function(err) {
|
|
85
|
-
this.emit('sessionExpired', err);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
SteamCommunity.prototype._checkHttpError = function(err, response, callback, body) {
|
|
89
|
-
if (err) {
|
|
90
|
-
callback(err, response, body);
|
|
91
|
-
return err;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
|
|
95
|
-
err = new Error("Not Logged In");
|
|
96
|
-
callback(err, response, body);
|
|
97
|
-
this._notifySessionExpired(err);
|
|
98
|
-
return err;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (response.statusCode == 403 && typeof response.body === 'string' && response.body.match(/<div id="parental_notice_instructions">Enter your PIN below to exit Family View.<\/div>/)) {
|
|
102
|
-
err = new Error("Family View Restricted");
|
|
103
|
-
callback(err, response, body);
|
|
104
|
-
return err;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (response.statusCode >= 400) {
|
|
108
|
-
err = new Error("HTTP error " + response.statusCode);
|
|
109
|
-
err.code = response.statusCode;
|
|
110
|
-
callback(err, response, body);
|
|
111
|
-
return err;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return false;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
|
118
|
-
var err;
|
|
119
|
-
|
|
120
|
-
if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
|
|
121
|
-
var match = html.match(/<h3>(.+)<\/h3>/);
|
|
122
|
-
err = new Error(match ? match[1] : "Unknown error occurred");
|
|
123
|
-
callback(err);
|
|
124
|
-
return err;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (typeof html === 'string' && html.indexOf('g_steamID = false;') > -1 && html.indexOf('<title>Sign In</title>') > -1) {
|
|
128
|
-
err = new Error("Not Logged In");
|
|
129
|
-
callback(err);
|
|
130
|
-
this._notifySessionExpired(err);
|
|
131
|
-
return err;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return false;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
SteamCommunity.prototype._checkTradeError = function(html, callback) {
|
|
138
|
-
if (typeof html !== 'string') {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
|
|
143
|
-
if (match) {
|
|
144
|
-
var err = new Error(match[1].trim());
|
|
145
|
-
callback(err);
|
|
146
|
-
return err;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return false;
|
|
150
|
-
};
|
|
1
|
+
var SteamCommunity = require('../index.js');
|
|
2
|
+
|
|
3
|
+
SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) {
|
|
4
|
+
if (typeof uri === 'object') {
|
|
5
|
+
source = callback;
|
|
6
|
+
callback = options;
|
|
7
|
+
options = uri;
|
|
8
|
+
uri = options.url || options.uri;
|
|
9
|
+
} else if (typeof options === 'function') {
|
|
10
|
+
source = callback;
|
|
11
|
+
callback = options;
|
|
12
|
+
options = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
options.url = options.uri = uri;
|
|
16
|
+
|
|
17
|
+
if (this._httpRequestConvenienceMethod) {
|
|
18
|
+
options.method = this._httpRequestConvenienceMethod;
|
|
19
|
+
delete this._httpRequestConvenienceMethod;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var requestID = ++this._httpRequestID;
|
|
23
|
+
source = source || "";
|
|
24
|
+
|
|
25
|
+
var self = this;
|
|
26
|
+
var continued = false;
|
|
27
|
+
|
|
28
|
+
if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
|
|
29
|
+
// No pre-hook, or the pre-hook doesn't want to delay the request.
|
|
30
|
+
continueRequest(null);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function continueRequest(err) {
|
|
34
|
+
if (continued) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
continued = true;
|
|
39
|
+
|
|
40
|
+
if (err) {
|
|
41
|
+
if (callback) {
|
|
42
|
+
callback(err);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
self.request(options, function (err, response, body) {
|
|
49
|
+
var hasCallback = !!callback;
|
|
50
|
+
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback, body);
|
|
51
|
+
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
|
|
52
|
+
var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {} : callback); // don't fire the callback if either of the previous already did
|
|
53
|
+
var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null;
|
|
54
|
+
|
|
55
|
+
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || jsonError || null, response, body, {
|
|
56
|
+
"hasCallback": hasCallback,
|
|
57
|
+
"httpError": httpError,
|
|
58
|
+
"communityError": communityError,
|
|
59
|
+
"tradeError": tradeError,
|
|
60
|
+
"jsonError": jsonError
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (hasCallback && !(httpError || communityError || tradeError)) {
|
|
64
|
+
if (jsonError) {
|
|
65
|
+
callback.call(self, jsonError, response);
|
|
66
|
+
} else {
|
|
67
|
+
callback.apply(self, arguments);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
SteamCommunity.prototype.httpRequestGet = function() {
|
|
75
|
+
this._httpRequestConvenienceMethod = "GET";
|
|
76
|
+
return this.httpRequest.apply(this, arguments);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
SteamCommunity.prototype.httpRequestPost = function() {
|
|
80
|
+
this._httpRequestConvenienceMethod = "POST";
|
|
81
|
+
return this.httpRequest.apply(this, arguments);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
SteamCommunity.prototype._notifySessionExpired = function(err) {
|
|
85
|
+
this.emit('sessionExpired', err);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
SteamCommunity.prototype._checkHttpError = function(err, response, callback, body) {
|
|
89
|
+
if (err) {
|
|
90
|
+
callback(err, response, body);
|
|
91
|
+
return err;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
|
|
95
|
+
err = new Error("Not Logged In");
|
|
96
|
+
callback(err, response, body);
|
|
97
|
+
this._notifySessionExpired(err);
|
|
98
|
+
return err;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (response.statusCode == 403 && typeof response.body === 'string' && response.body.match(/<div id="parental_notice_instructions">Enter your PIN below to exit Family View.<\/div>/)) {
|
|
102
|
+
err = new Error("Family View Restricted");
|
|
103
|
+
callback(err, response, body);
|
|
104
|
+
return err;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (response.statusCode >= 400) {
|
|
108
|
+
err = new Error("HTTP error " + response.statusCode);
|
|
109
|
+
err.code = response.statusCode;
|
|
110
|
+
callback(err, response, body);
|
|
111
|
+
return err;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return false;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
|
118
|
+
var err;
|
|
119
|
+
|
|
120
|
+
if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
|
|
121
|
+
var match = html.match(/<h3>(.+)<\/h3>/);
|
|
122
|
+
err = new Error(match ? match[1] : "Unknown error occurred");
|
|
123
|
+
callback(err);
|
|
124
|
+
return err;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (typeof html === 'string' && html.indexOf('g_steamID = false;') > -1 && html.indexOf('<title>Sign In</title>') > -1) {
|
|
128
|
+
err = new Error("Not Logged In");
|
|
129
|
+
callback(err);
|
|
130
|
+
this._notifySessionExpired(err);
|
|
131
|
+
return err;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return false;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
SteamCommunity.prototype._checkTradeError = function(html, callback) {
|
|
138
|
+
if (typeof html !== 'string') {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
|
|
143
|
+
if (match) {
|
|
144
|
+
var err = new Error(match[1].trim());
|
|
145
|
+
callback(err);
|
|
146
|
+
return err;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return false;
|
|
150
|
+
};
|