Update inventory loading endpoint

Should fix 429s :)
This commit is contained in:
Vankxr 2016-12-11 00:14:09 +00:00
parent 95a36b00c1
commit a0843a0b12
2 changed files with 20 additions and 37 deletions

View File

@ -1,6 +1,6 @@
module.exports = CEconItem;
function CEconItem(item, descriptions, contextID) {
function CEconItem(item, descriptions) {
var thing;
for(thing in item) {
if(item.hasOwnProperty(thing)) {
@ -15,12 +15,9 @@ function CEconItem(item, descriptions, contextID) {
// Merge the description
if(descriptions) {
var description = descriptions[this.classid + '_' + this.instanceid];
if(description) {
for(thing in description) {
if(description.hasOwnProperty(thing)) {
this[thing] = description[thing];
}
for(thing in descriptions) {
if(descriptions.hasOwnProperty(thing)) {
this[thing] = descriptions[thing];
}
}
}

View File

@ -263,16 +263,16 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
if(typeof userID === 'string') {
userID = new SteamID(userID);
}
get([], [], 1);
var endpoint = "/profiles/" + userID.getSteamID64();
get([], []);
function get(inventory, currency, start) {
function get(inventory, currency, step, start) {
self.httpRequest({
"uri": "https://steamcommunity.com" + endpoint + "/inventory/json/" + appID + "/" + contextID,
"uri": "https://steamcommunity.com/inventory/" + userID.getSteamID64() + "/" + appID + "/" + contextID,
"qs": {
"start": start,
"trading": tradableOnly ? 1 : undefined
"l": "english", // Default language
"count": 5000, // Max items per 'page'
"start_assetid": start,
},
"json": true
}, function(err, response, body) {
@ -281,9 +281,9 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
return;
}
if(!body || !body.success || !body.rgInventory || !body.rgDescriptions || !body.rgCurrency) {
if(!body || !body.success || !body.assets || !body.descriptions) {
if(body) {
callback(new Error(body.Error || "Malformed response"));
callback(new Error(body.error || "Malformed response"));
} else {
callback(new Error("Malformed response"));
}
@ -291,30 +291,16 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
return;
}
var i;
for(i in body.rgInventory) {
if(!body.rgInventory.hasOwnProperty(i)) {
continue;
for(var i = 0; i < body.assets.length; i++) {
if(!tradableOnly || body.descriptions[i].tradable) {
inventory.push(new CEconItem(body.assets[i], body.descriptions[i], contextID));
}
inventory.push(new CEconItem(body.rgInventory[i], body.rgDescriptions, contextID));
}
// Dunno how to handle currencies now
for(i in body.rgCurrency) {
if(!body.rgCurrency.hasOwnProperty(i)) {
continue;
}
currency.push(new CEconItem(body.rgInventory[i], body.rgDescriptions, contextID));
}
if(body.more) {
var match = response.request.uri.href.match(/\/(profiles|id)\/([^\/]+)\//);
if(match) {
endpoint = "/" + match[1] + "/" + match[2];
}
get(inventory, currency, body.more_start);
if(body.total_inventory_count > 5000 * step) {
get(inventory, currency, step + 1, body.assets[body.assets.length - 1].assetid);
} else {
callback(null, inventory, currency);
}