mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-08-24 23:53:28 +08:00
Compare commits
5 Commits
v3.19.0-be
...
v3.19.0-be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
840e9548ed | ||
|
|
dee6b7964b | ||
|
|
2fc434d475 | ||
|
|
42ebbda00d | ||
|
|
eed791acbd |
@@ -22,30 +22,46 @@ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source)
|
||||
var requestID = ++this._httpRequestID;
|
||||
source = source || "";
|
||||
|
||||
if (this.onPreHttpRequest && this.onPreHttpRequest(requestID, source, options, callback) === false) {
|
||||
return false;
|
||||
var self = this;
|
||||
var continued = false;
|
||||
|
||||
if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
|
||||
// No pre-hook, or the pre-hook doesn't want to delay the request.
|
||||
continueRequest(null);
|
||||
}
|
||||
|
||||
var self = this;
|
||||
this.request(options, function(err, response, body) {
|
||||
var hasCallback = !!callback;
|
||||
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback);
|
||||
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function() {} : callback); // don't fire the callback if hasHttpError did it already
|
||||
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
|
||||
|
||||
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || null, response, body, {
|
||||
"hasCallback": hasCallback,
|
||||
"httpError": httpError,
|
||||
"communityError": communityError,
|
||||
"tradeError": tradeError
|
||||
});
|
||||
|
||||
if (hasCallback && !(httpError || communityError || tradeError)) {
|
||||
callback.apply(self, arguments);
|
||||
function continueRequest(err) {
|
||||
if (continued) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
continued = true;
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
self.request(options, function (err, response, body) {
|
||||
var hasCallback = !!callback;
|
||||
var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback);
|
||||
var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {
|
||||
} : callback); // don't fire the callback if hasHttpError did it already
|
||||
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
|
||||
|
||||
self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || null, response, body, {
|
||||
"hasCallback": hasCallback,
|
||||
"httpError": httpError,
|
||||
"communityError": communityError,
|
||||
"tradeError": tradeError
|
||||
});
|
||||
|
||||
if(hasCallback && !(httpError || communityError || tradeError)) {
|
||||
callback.apply(self, arguments);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.httpRequestGet = function() {
|
||||
@@ -81,7 +97,7 @@ SteamCommunity.prototype._checkHttpError = function(err, response, callback) {
|
||||
};
|
||||
|
||||
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
||||
if(html.match(/<h1>Sorry!<\/h1>/)) {
|
||||
if(html && html.match(/<h1>Sorry!<\/h1>/)) {
|
||||
var match = html.match(/<h3>(.+)<\/h3>/);
|
||||
var err = new Error(match ? match[1] : "Unknown error occurred");
|
||||
callback(err);
|
||||
@@ -92,6 +108,10 @@ SteamCommunity.prototype._checkCommunityError = function(html, callback) {
|
||||
};
|
||||
|
||||
SteamCommunity.prototype._checkTradeError = function(html, callback) {
|
||||
if (!html) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
|
||||
if (match) {
|
||||
var err = new Error(match[1].trim());
|
||||
|
||||
2
index.js
2
index.js
@@ -348,7 +348,7 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
||||
}
|
||||
|
||||
var options = {
|
||||
"uri": "https://steamcommunity.com" + mtch[1] + "/" + endpoint,
|
||||
"uri": "https://steamcommunity.com" + match[1] + "/" + endpoint,
|
||||
"method": "GET"
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "steamcommunity",
|
||||
"version": "3.19.0-beta3",
|
||||
"version": "3.19.0-beta5",
|
||||
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
||||
"keywords": ["steam", "steam community"],
|
||||
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
|
||||
|
||||
Reference in New Issue
Block a user