From 087c0f001192d9ade31fe116cd7411f66159f62d Mon Sep 17 00:00:00 2001 From: NetroScript Date: Fri, 20 Jul 2018 01:38:54 +0200 Subject: [PATCH 01/18] Added the possibility to edit showcases The option "showcases" was added to editProfile(). For this option you have to submit an array of objects. These objects have all the property "showcase", and some need the property "values". They will be displayed in the order in which they were in the array. Possible showcase values: infobox, artwork, trade, items, game, badge, rareachievements, screenshot, group, review, workshop, guide, achievements, games, ownguides, ownworkshop, (steam game ones like salien, but these will be obsolent at some point so not included here) Information about these: infobox: * values: "title" and "notes" artwork: * values: a single array with up to 4 publishedfileids (f.e. just copy them from the page of your artwork) trade: * values: "notes" and "items" which is an array of objects in the following manner - {"appid": ..., "item_contextid": ..., "item_assetid": ...} up to 6 items: * values: "items" which is an array of objects in the following manner - {"appid": ..., "item_contextid": ..., "item_assetid": ...} up to 10 game: * values: "appid" badge: * values: "style" which can be one of the following - [rare, selected, recent, random], "badges" which is an array of objects in the following manner - {"appid": ..., "badgeid": ..., "border_color": ...} (although I do not know the influence of border_color, if the badge is not a game badge, fill only badgeid, if it is a badge from a game the badgeid is 1 and you have to fill in appid) up to 6 rareachievements: * values: none screenshot: * values: a single array with up to 4 publishedfileids group: * values: "groupid" which is a SteamID review: * values: "appid" of the game where you want to display your review workshop: * values: "appid" of the game, "publishedfileid" of the workshop item guide: * values: "appid" of the game, "publishedfileid" of the guide achievements: * values: "achievements" which is an array of objects in the following manner - {"appid": ..., "title": ...} (for the title either get it manually or use https://steamcommunity.com/id//ajaxgetachievementsforgame/ ) up to 7 games: * values: "games" which is an array of objects in the following manner - {"appid": ...} up to 4 ownguides: * values: an array of objects in the following manner - {"appid": ..., "publishedfileid": ...} up to 4 ownworkshop: * values: an array of objects in the following manner - {"appid": ..., "publishedfileid": ...} up to 5 Some showcases of course only work if you fulfill the requirements, meaning it could be that I am missing some. --- components/profile.js | 457 +++++++++++++++++++++++++++++++++++++----- package.json | 3 +- 2 files changed, 408 insertions(+), 52 deletions(-) diff --git a/components/profile.js b/components/profile.js index e8652021..1e86a3c9 100644 --- a/components/profile.js +++ b/components/profile.js @@ -1,6 +1,7 @@ const Cheerio = require('cheerio'); const FS = require('fs'); const SteamID = require('steamid'); +const Param = require('jquery-param'); const Helpers = require('./helpers.js'); const SteamCommunity = require('../index.js'); @@ -53,10 +54,8 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { return; } - var values = {}; - form.serializeArray().forEach(function(item) { - values[item.name] = item.value; - }); + var formd = form.serializeArray(); + var out = [].concat(formd.slice(0,19)); for(var i in settings) { if(!settings.hasOwnProperty(i)) { @@ -65,57 +64,413 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { switch(i) { case 'name': - values.personaName = settings[i]; - break; - - case 'realName': - values.real_name = settings[i]; - break; - - case 'summary': - values.summary = settings[i]; - break; - - case 'country': - values.country = settings[i]; - break; - - case 'state': - values.state = settings[i]; - break; - - case 'city': - values.city = settings[i]; - break; - - case 'customURL': - values.customURL = settings[i]; - break; - - case 'background': - // The assetid of our desired profile background - values.profile_background = settings[i]; - break; - - case 'featuredBadge': - // Currently, game badges aren't supported - values.favorite_badge_badgeid = settings[i]; - break; - - case 'primaryGroup': - if(typeof settings[i] === 'object' && settings[i].getSteamID64) { - values.primary_group_steamid = settings[i].getSteamID64(); - } else { - values.primary_group_steamid = new SteamID(settings[i]).getSteamID64(); - } - - break; + out[8] = { + "name": formd[8].name, + "value": settings[i] + }; + break; + + case 'realName': + out[9] = { + "name": formd[9].name, + "value": settings[i] + }; + break; + + case 'summary': + out[14] = { + "name": formd[14].name, + "value": settings[i] + }; + break; + + case 'country': + out[10] = { + "name": formd[10].name, + "value": settings[i] + }; + break; + + case 'state': + out[11] = { + "name": formd[11].name, + "value": settings[i] + }; + break; + + case 'city': + out[12] = { + "name": formd[12].name, + "value": settings[i] + }; + break; + + case 'customURL': + out[13] = { + "name": formd[13].name, + "value": settings[i] + }; + break; + + case 'background': + // The assetid of our desired profile background + out[15] = { + "name": formd[15].name, + "value": settings[i] + }; + break; + + case 'featuredBadge': + // Currently, game badges aren't supported + out[16] = { + "name": formd[16].name, + "value": settings[i] + }; + break; + + case 'primaryGroup': + if (typeof settings[i] === 'object' && settings[i].getSteamID64) { + out[18] = { + "name": formd[18].name, + "value": settings[i].getSteamID64() + }; + } else { + out[18] = { + "name": formd[18].name, + "value": new SteamID(settings[i]).getSteamID64() + }; + } + + break; + + case 'showcases': + for (var t in settings[i]) { + var showcaseconfig = [false,0,0,[]]; + + switch (settings[i][t].showcase) { + + case 'infobox': + out.push({ + "name": "profile_showcase[]", + "value": "8" + }); + out.push({ + "name": "rgShowcaseConfig[8][0][title]", + "value": settings[i][t]["values"]["title"] + }); + out.push({ + "name": "rgShowcaseConfig[8][0][notes]", + "value": settings[i][t]["values"]["notes"] + }); + break; + + case 'artwork': + out.push({ + "name": "profile_showcase[]", + "value": "13" + }); + for (var n = 0; n < 4; n++) { + out.push({ + "name": "rgShowcaseConfig[13][" + n + "][publishedfileid]", + "value": settings[i][t]["values"][n] || "" + }); + } + break; + + case 'trade': + out.push({ + "name": "profile_showcase[]", + "value": "4" + }); + out.push({ + "name": "rgShowcaseConfig[4][6][notes]", + "value": settings[i][t]["values"]["notes"] + }); + + if (settings[i][t]["values"].hasOwnProperty("items")) { + showcaseconfig = [true, 6, 4, settings[i][t]["values"]["items"]]; + } + break; + + case 'items': + out.push({ + "name": "profile_showcase[]", + "value": "3" + }); + + if (settings[i][t]["values"].hasOwnProperty("items")) { + showcaseconfig = [true, 10, 3, settings[i][t]["values"]["items"]]; + } + break; + + case 'game': + out.push({ + "name": "profile_showcase[]", + "value": "6" + }); + out.push({ + "name": "rgShowcaseConfig[6][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + break; + + case 'badge': + out.push({ + "name": "profile_showcase[]", + "value": "5" + }); + var styles = ["rare","selected",null,"recent","random"]; + out.push({ + "name": "profile_showcase_style_5", + "value": styles.indexOf(settings[i][t]["values"]["style"]) + }); + + if (settings[i][t]["values"].hasOwnProperty("badges")){ + for(var n = 0; n < 6; n++){ + var defaultval = ["", "", ""]; + if (settings[i][t]["values"]["badges"][n] != undefined) { + defaultval = [settings[i][t]["values"]["badges"][n]["badgeid"], settings[i][t]["values"]["badges"][n]["appid"], settings[i][t]["values"]["badges"][n]["border_color"]]; + } + out.push({ + "name": "rgShowcaseConfig[5][" + n + "][badgeid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[5][" + n + "][appid]", + "value": defaultval[1] + }); + out.push({ + "name": "rgShowcaseConfig[5][" + n + "][border_color]", + "value": defaultval[2] + }); + } + } + + break; + + case 'rareachievements': + out.push({ + "name": "profile_showcase[]", + "value": "1" + }); + break; + + case 'screenshot': + out.push({ + "name": "profile_showcase[]", + "value": "7" + }); + for (var n = 0; n < 4; n++) { + out.push({ + "name": "rgShowcaseConfig[7][" + n + "][publishedfileid]", + "value": settings[i][t]["values"][n] || "" + }); + } + break; + + case 'group': + out.push({ + "name": "profile_showcase[]", + "value": "9" + }); + if (typeof settings[i][t]["values"]["groupid"] === 'object' && settings[i][t]["values"]["groupid"].getSteamID64) { + out.push({ + "name": "rgShowcaseConfig[9][0][accountid]", + "value": settings[i][t]["values"]["groupid"].getSteamID64() + }); + } else { + out.push({ + "name": "rgShowcaseConfig[9][0][accountid]", + "value": new SteamID(settings[i][t]["values"]["groupid"]).getSteamID64() + }); + } + break; + + case 'review': + out.push({ + "name": "profile_showcase[]", + "value": "10" + }); + out.push({ + "name": "rgShowcaseConfig[10][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + break; + + case 'workshop': + out.push({ + "name": "profile_showcase[]", + "value": "11" + }); + out.push({ + "name": "rgShowcaseConfig[11][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + out.push({ + "name": "rgShowcaseConfig[11][0][publishedfileid]", + "value": settings[i][t]["values"]["publishedfileid"] + }); + break; + + case 'guide': + out.push({ + "name": "profile_showcase[]", + "value": "15" + }); + out.push({ + "name": "rgShowcaseConfig[15][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + out.push({ + "name": "rgShowcaseConfig[15][0][publishedfileid]", + "value": settings[i][t]["values"]["publishedfileid"] + }); + break; + + case 'achievements': + out.push({ + "name": "profile_showcase[]", + "value": "17" + }); + if (settings[i][t]["values"].hasOwnProperty("achievements")) { + for (var n = 0; n < 7; n++) { + var defaultval = ["", ""]; + if (settings[i][t]["values"]["achievements"][n] != undefined) { + defaultval = [settings[i][t]["values"]["achievements"][n]["appid"], settings[i][t]["values"]["achievements"][n]["title"]]; + } + out.push({ + "name": "rgShowcaseConfig[17][" + n + "][appid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[17][" + n + "][title]", + "value": defaultval[1] + }); + } + } + break; + + case 'games': + out.push({ + "name": "profile_showcase[]", + "value": "2" + }); + + if (settings[i][t]["values"].hasOwnProperty("games")) { + showcaseconfig = [true, 4, 2, settings[i][t]["values"]["games"]]; + } + break; + + case 'ownguides': + out.push({ + "name": "profile_showcase[]", + "value": "16" + }); + + for (var n = 0; n < 4; n++) { + var defaultval = ["", ""]; + if (settings[i][t]["values"][n] != undefined) { + defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; + } + out.push({ + "name": "rgShowcaseConfig[16][" + n + "][appid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[16][" + n + "][publishedfileid]", + "value": defaultval[1] + }); + } + break; + + case 'ownguides': + out.push({ + "name": "profile_showcase[]", + "value": "12" + }); + + for (var n = 0; n < 5; n++) { + var defaultval = ["", ""]; + if (settings[i][t]["values"][n] != undefined) { + defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; + } + out.push({ + "name": "rgShowcaseConfig[12][" + n + "][appid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[12][" + n + "][publishedfileid]", + "value": defaultval[1] + }); + } + break; + } + + if (showcaseconfig[0]) { + for (var n = 0; n < showcaseconfig[1]; n++) { + var requestdata; + if (showcaseconfig[3][n] == undefined) { + requestdata = { + appid: 0, + item_contextid: 0, + item_assetid: 0, + customization_type: showcaseconfig[2], + slot: n, + sessionid: formd[0].value + }; + } else { + requestdata = { + appid: showcaseconfig[3][n]["appid"], + item_contextid: showcaseconfig[3][n]["item_contextid"], + item_assetid: showcaseconfig[3][n]["item_assetid"], + customization_type: showcaseconfig[2], + slot: n, + sessionid: formd[0].value + }; + + } + + self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + if (settings.customURL) { + delete selfe._profileURL; + } + + if (err || response.statusCode != 200) { + if (callback) { + callback(err || new Error("HTTP error " + response.statusCode)); + } + + return; + } + + // Check for an error + var $ = Cheerio.load(body); + var error = $('#errorText .formRowFields'); + if (error) { + error = error.text().trim(); + if (error) { + if (callback) { + callback(new Error(error)); + } + + return; + } + } + + if (callback) { + callback(null); + } + }); + } + + } + } + break; - // TODO: profile showcases } } - self._myProfile("edit", values, function(err, response, body) { + self._myProfile("edit", Param(out), function(err, response, body) { if (settings.customURL) { delete self._profileURL; } diff --git a/package.json b/package.json index 77cc123c..697f083e 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "xml2js": "^0.4.11", "cheerio": "0.22.0", "async": "^2.1.4", - "steam-totp": "^1.3.0" + "steam-totp": "^1.3.0", + "jquery-param": "1.0.1" }, "engines": { "node": ">=4.0.0" From 9b1d40ce7f1733836fe69f2a65cda776db7cb247 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Fri, 20 Jul 2018 01:46:33 +0200 Subject: [PATCH 02/18] Added the possibility to edit showcases The option "showcases" was added to editProfile(). For this option you have to submit an array of objects. These objects have all the property "showcase", and some need the property "values". They will be displayed in the order in which they were in the array. Possible showcase values: infobox, artwork, trade, items, game, badge, rareachievements, screenshot, group, review, workshop, guide, achievements, games, ownguides, ownworkshop, (steam game ones like salien, but these will be obsolent at some point so not included here) Information about these: infobox: * values: "title" and "notes" artwork: * values: a single array with up to 4 publishedfileids (f.e. just copy them from the page of your artwork) trade: * values: "notes" and "items" which is an array of objects in the following manner - {"appid": ..., "item_contextid": ..., "item_assetid": ...} up to 6 items: * values: "items" which is an array of objects in the following manner - {"appid": ..., "item_contextid": ..., "item_assetid": ...} up to 10 game: * values: "appid" badge: * values: "style" which can be one of the following - [rare, selected, recent, random], "badges" which is an array of objects in the following manner - {"appid": ..., "badgeid": ..., "border_color": ...} (although I do not know the influence of border_color, if the badge is not a game badge, fill only badgeid, if it is a badge from a game the badgeid is 1 and you have to fill in appid) up to 6 rareachievements: * values: none screenshot: * values: a single array with up to 4 publishedfileids group: * values: "groupid" which is a SteamID review: * values: "appid" of the game where you want to display your review workshop: * values: "appid" of the game, "publishedfileid" of the workshop item guide: * values: "appid" of the game, "publishedfileid" of the guide achievements: * values: "achievements" which is an array of objects in the following manner - {"appid": ..., "title": ...} (for the title either get it manually or use https://steamcommunity.com/id//ajaxgetachievementsforgame/ ) up to 7 games: * values: "games" which is an array of objects in the following manner - {"appid": ...} up to 4 ownguides: * values: an array of objects in the following manner - {"appid": ..., "publishedfileid": ...} up to 4 ownworkshop: * values: an array of objects in the following manner - {"appid": ..., "publishedfileid": ...} up to 5 Some showcases of course only work if you fulfill the requirements, meaning it could be that I am missing some. (and changed spaces to tabs because `Tabs for indentation`) --- components/profile.js | 796 +++++++++++++++++++++--------------------- 1 file changed, 398 insertions(+), 398 deletions(-) diff --git a/components/profile.js b/components/profile.js index 1e86a3c9..0d224b87 100644 --- a/components/profile.js +++ b/components/profile.js @@ -64,408 +64,408 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { switch(i) { case 'name': - out[8] = { - "name": formd[8].name, - "value": settings[i] - }; - break; - - case 'realName': - out[9] = { - "name": formd[9].name, - "value": settings[i] - }; - break; - - case 'summary': - out[14] = { - "name": formd[14].name, - "value": settings[i] - }; - break; - - case 'country': - out[10] = { - "name": formd[10].name, - "value": settings[i] - }; - break; - - case 'state': - out[11] = { - "name": formd[11].name, - "value": settings[i] - }; - break; - - case 'city': - out[12] = { - "name": formd[12].name, - "value": settings[i] - }; - break; - - case 'customURL': - out[13] = { - "name": formd[13].name, - "value": settings[i] - }; - break; - - case 'background': - // The assetid of our desired profile background - out[15] = { - "name": formd[15].name, - "value": settings[i] - }; - break; - - case 'featuredBadge': - // Currently, game badges aren't supported - out[16] = { - "name": formd[16].name, - "value": settings[i] - }; - break; - - case 'primaryGroup': - if (typeof settings[i] === 'object' && settings[i].getSteamID64) { - out[18] = { - "name": formd[18].name, - "value": settings[i].getSteamID64() - }; - } else { - out[18] = { - "name": formd[18].name, - "value": new SteamID(settings[i]).getSteamID64() - }; - } - - break; - - case 'showcases': - for (var t in settings[i]) { - var showcaseconfig = [false,0,0,[]]; - - switch (settings[i][t].showcase) { - - case 'infobox': - out.push({ - "name": "profile_showcase[]", - "value": "8" - }); - out.push({ - "name": "rgShowcaseConfig[8][0][title]", - "value": settings[i][t]["values"]["title"] - }); - out.push({ - "name": "rgShowcaseConfig[8][0][notes]", - "value": settings[i][t]["values"]["notes"] - }); - break; - - case 'artwork': - out.push({ - "name": "profile_showcase[]", - "value": "13" - }); - for (var n = 0; n < 4; n++) { - out.push({ - "name": "rgShowcaseConfig[13][" + n + "][publishedfileid]", - "value": settings[i][t]["values"][n] || "" - }); - } - break; - - case 'trade': - out.push({ - "name": "profile_showcase[]", - "value": "4" - }); - out.push({ - "name": "rgShowcaseConfig[4][6][notes]", - "value": settings[i][t]["values"]["notes"] - }); - - if (settings[i][t]["values"].hasOwnProperty("items")) { - showcaseconfig = [true, 6, 4, settings[i][t]["values"]["items"]]; - } - break; - - case 'items': - out.push({ - "name": "profile_showcase[]", - "value": "3" - }); - - if (settings[i][t]["values"].hasOwnProperty("items")) { - showcaseconfig = [true, 10, 3, settings[i][t]["values"]["items"]]; - } - break; - - case 'game': - out.push({ - "name": "profile_showcase[]", - "value": "6" - }); - out.push({ - "name": "rgShowcaseConfig[6][0][appid]", - "value": settings[i][t]["values"]["appid"] - }); - break; - - case 'badge': - out.push({ - "name": "profile_showcase[]", - "value": "5" - }); - var styles = ["rare","selected",null,"recent","random"]; - out.push({ - "name": "profile_showcase_style_5", - "value": styles.indexOf(settings[i][t]["values"]["style"]) - }); - - if (settings[i][t]["values"].hasOwnProperty("badges")){ - for(var n = 0; n < 6; n++){ + out[8] = { + "name": formd[8].name, + "value": settings[i] + }; + break; + + case 'realName': + out[9] = { + "name": formd[9].name, + "value": settings[i] + }; + break; + + case 'summary': + out[14] = { + "name": formd[14].name, + "value": settings[i] + }; + break; + + case 'country': + out[10] = { + "name": formd[10].name, + "value": settings[i] + }; + break; + + case 'state': + out[11] = { + "name": formd[11].name, + "value": settings[i] + }; + break; + + case 'city': + out[12] = { + "name": formd[12].name, + "value": settings[i] + }; + break; + + case 'customURL': + out[13] = { + "name": formd[13].name, + "value": settings[i] + }; + break; + + case 'background': + // The assetid of our desired profile background + out[15] = { + "name": formd[15].name, + "value": settings[i] + }; + break; + + case 'featuredBadge': + // Currently, game badges aren't supported + out[16] = { + "name": formd[16].name, + "value": settings[i] + }; + break; + + case 'primaryGroup': + if (typeof settings[i] === 'object' && settings[i].getSteamID64) { + out[18] = { + "name": formd[18].name, + "value": settings[i].getSteamID64() + }; + } else { + out[18] = { + "name": formd[18].name, + "value": new SteamID(settings[i]).getSteamID64() + }; + } + + break; + + case 'showcases': + for (var t in settings[i]) { + var showcaseconfig = [false,0,0,[]]; + + switch (settings[i][t].showcase) { + + case 'infobox': + out.push({ + "name": "profile_showcase[]", + "value": "8" + }); + out.push({ + "name": "rgShowcaseConfig[8][0][title]", + "value": settings[i][t]["values"]["title"] + }); + out.push({ + "name": "rgShowcaseConfig[8][0][notes]", + "value": settings[i][t]["values"]["notes"] + }); + break; + + case 'artwork': + out.push({ + "name": "profile_showcase[]", + "value": "13" + }); + for (var n = 0; n < 4; n++) { + out.push({ + "name": "rgShowcaseConfig[13][" + n + "][publishedfileid]", + "value": settings[i][t]["values"][n] || "" + }); + } + break; + + case 'trade': + out.push({ + "name": "profile_showcase[]", + "value": "4" + }); + out.push({ + "name": "rgShowcaseConfig[4][6][notes]", + "value": settings[i][t]["values"]["notes"] + }); + + if (settings[i][t]["values"].hasOwnProperty("items")) { + showcaseconfig = [true, 6, 4, settings[i][t]["values"]["items"]]; + } + break; + + case 'items': + out.push({ + "name": "profile_showcase[]", + "value": "3" + }); + + if (settings[i][t]["values"].hasOwnProperty("items")) { + showcaseconfig = [true, 10, 3, settings[i][t]["values"]["items"]]; + } + break; + + case 'game': + out.push({ + "name": "profile_showcase[]", + "value": "6" + }); + out.push({ + "name": "rgShowcaseConfig[6][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + break; + + case 'badge': + out.push({ + "name": "profile_showcase[]", + "value": "5" + }); + var styles = ["rare","selected",null,"recent","random"]; + out.push({ + "name": "profile_showcase_style_5", + "value": styles.indexOf(settings[i][t]["values"]["style"]) + }); + + if (settings[i][t]["values"].hasOwnProperty("badges")){ + for(var n = 0; n < 6; n++){ var defaultval = ["", "", ""]; - if (settings[i][t]["values"]["badges"][n] != undefined) { - defaultval = [settings[i][t]["values"]["badges"][n]["badgeid"], settings[i][t]["values"]["badges"][n]["appid"], settings[i][t]["values"]["badges"][n]["border_color"]]; - } - out.push({ - "name": "rgShowcaseConfig[5][" + n + "][badgeid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[5][" + n + "][appid]", - "value": defaultval[1] - }); - out.push({ - "name": "rgShowcaseConfig[5][" + n + "][border_color]", - "value": defaultval[2] - }); - } - } - - break; - - case 'rareachievements': - out.push({ - "name": "profile_showcase[]", - "value": "1" - }); - break; - - case 'screenshot': - out.push({ - "name": "profile_showcase[]", - "value": "7" - }); - for (var n = 0; n < 4; n++) { - out.push({ - "name": "rgShowcaseConfig[7][" + n + "][publishedfileid]", - "value": settings[i][t]["values"][n] || "" - }); - } - break; - - case 'group': - out.push({ - "name": "profile_showcase[]", - "value": "9" - }); - if (typeof settings[i][t]["values"]["groupid"] === 'object' && settings[i][t]["values"]["groupid"].getSteamID64) { - out.push({ - "name": "rgShowcaseConfig[9][0][accountid]", - "value": settings[i][t]["values"]["groupid"].getSteamID64() - }); - } else { - out.push({ - "name": "rgShowcaseConfig[9][0][accountid]", - "value": new SteamID(settings[i][t]["values"]["groupid"]).getSteamID64() - }); - } - break; - - case 'review': - out.push({ - "name": "profile_showcase[]", - "value": "10" - }); - out.push({ - "name": "rgShowcaseConfig[10][0][appid]", - "value": settings[i][t]["values"]["appid"] - }); - break; - - case 'workshop': - out.push({ - "name": "profile_showcase[]", - "value": "11" - }); - out.push({ - "name": "rgShowcaseConfig[11][0][appid]", - "value": settings[i][t]["values"]["appid"] - }); - out.push({ - "name": "rgShowcaseConfig[11][0][publishedfileid]", - "value": settings[i][t]["values"]["publishedfileid"] - }); - break; - - case 'guide': - out.push({ - "name": "profile_showcase[]", - "value": "15" - }); - out.push({ - "name": "rgShowcaseConfig[15][0][appid]", - "value": settings[i][t]["values"]["appid"] - }); - out.push({ - "name": "rgShowcaseConfig[15][0][publishedfileid]", - "value": settings[i][t]["values"]["publishedfileid"] - }); - break; - - case 'achievements': - out.push({ - "name": "profile_showcase[]", - "value": "17" - }); - if (settings[i][t]["values"].hasOwnProperty("achievements")) { - for (var n = 0; n < 7; n++) { + if (settings[i][t]["values"]["badges"][n] != undefined) { + defaultval = [settings[i][t]["values"]["badges"][n]["badgeid"], settings[i][t]["values"]["badges"][n]["appid"], settings[i][t]["values"]["badges"][n]["border_color"]]; + } + out.push({ + "name": "rgShowcaseConfig[5][" + n + "][badgeid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[5][" + n + "][appid]", + "value": defaultval[1] + }); + out.push({ + "name": "rgShowcaseConfig[5][" + n + "][border_color]", + "value": defaultval[2] + }); + } + } + + break; + + case 'rareachievements': + out.push({ + "name": "profile_showcase[]", + "value": "1" + }); + break; + + case 'screenshot': + out.push({ + "name": "profile_showcase[]", + "value": "7" + }); + for (var n = 0; n < 4; n++) { + out.push({ + "name": "rgShowcaseConfig[7][" + n + "][publishedfileid]", + "value": settings[i][t]["values"][n] || "" + }); + } + break; + + case 'group': + out.push({ + "name": "profile_showcase[]", + "value": "9" + }); + if (typeof settings[i][t]["values"]["groupid"] === 'object' && settings[i][t]["values"]["groupid"].getSteamID64) { + out.push({ + "name": "rgShowcaseConfig[9][0][accountid]", + "value": settings[i][t]["values"]["groupid"].getSteamID64() + }); + } else { + out.push({ + "name": "rgShowcaseConfig[9][0][accountid]", + "value": new SteamID(settings[i][t]["values"]["groupid"]).getSteamID64() + }); + } + break; + + case 'review': + out.push({ + "name": "profile_showcase[]", + "value": "10" + }); + out.push({ + "name": "rgShowcaseConfig[10][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + break; + + case 'workshop': + out.push({ + "name": "profile_showcase[]", + "value": "11" + }); + out.push({ + "name": "rgShowcaseConfig[11][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + out.push({ + "name": "rgShowcaseConfig[11][0][publishedfileid]", + "value": settings[i][t]["values"]["publishedfileid"] + }); + break; + + case 'guide': + out.push({ + "name": "profile_showcase[]", + "value": "15" + }); + out.push({ + "name": "rgShowcaseConfig[15][0][appid]", + "value": settings[i][t]["values"]["appid"] + }); + out.push({ + "name": "rgShowcaseConfig[15][0][publishedfileid]", + "value": settings[i][t]["values"]["publishedfileid"] + }); + break; + + case 'achievements': + out.push({ + "name": "profile_showcase[]", + "value": "17" + }); + if (settings[i][t]["values"].hasOwnProperty("achievements")) { + for (var n = 0; n < 7; n++) { var defaultval = ["", ""]; - if (settings[i][t]["values"]["achievements"][n] != undefined) { - defaultval = [settings[i][t]["values"]["achievements"][n]["appid"], settings[i][t]["values"]["achievements"][n]["title"]]; - } - out.push({ - "name": "rgShowcaseConfig[17][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[17][" + n + "][title]", - "value": defaultval[1] - }); - } - } - break; + if (settings[i][t]["values"]["achievements"][n] != undefined) { + defaultval = [settings[i][t]["values"]["achievements"][n]["appid"], settings[i][t]["values"]["achievements"][n]["title"]]; + } + out.push({ + "name": "rgShowcaseConfig[17][" + n + "][appid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[17][" + n + "][title]", + "value": defaultval[1] + }); + } + } + break; case 'games': - out.push({ - "name": "profile_showcase[]", - "value": "2" - }); - - if (settings[i][t]["values"].hasOwnProperty("games")) { - showcaseconfig = [true, 4, 2, settings[i][t]["values"]["games"]]; - } - break; - - case 'ownguides': - out.push({ - "name": "profile_showcase[]", - "value": "16" - }); - - for (var n = 0; n < 4; n++) { - var defaultval = ["", ""]; - if (settings[i][t]["values"][n] != undefined) { - defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; - } - out.push({ - "name": "rgShowcaseConfig[16][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[16][" + n + "][publishedfileid]", - "value": defaultval[1] - }); - } - break; - - case 'ownguides': - out.push({ - "name": "profile_showcase[]", - "value": "12" - }); - - for (var n = 0; n < 5; n++) { - var defaultval = ["", ""]; - if (settings[i][t]["values"][n] != undefined) { - defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; - } - out.push({ - "name": "rgShowcaseConfig[12][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[12][" + n + "][publishedfileid]", - "value": defaultval[1] - }); - } - break; - } - - if (showcaseconfig[0]) { - for (var n = 0; n < showcaseconfig[1]; n++) { - var requestdata; - if (showcaseconfig[3][n] == undefined) { - requestdata = { - appid: 0, - item_contextid: 0, - item_assetid: 0, - customization_type: showcaseconfig[2], - slot: n, - sessionid: formd[0].value - }; - } else { - requestdata = { - appid: showcaseconfig[3][n]["appid"], - item_contextid: showcaseconfig[3][n]["item_contextid"], - item_assetid: showcaseconfig[3][n]["item_assetid"], - customization_type: showcaseconfig[2], - slot: n, - sessionid: formd[0].value - }; - - } - - self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - if (settings.customURL) { - delete selfe._profileURL; - } - - if (err || response.statusCode != 200) { - if (callback) { - callback(err || new Error("HTTP error " + response.statusCode)); - } - - return; - } - - // Check for an error - var $ = Cheerio.load(body); - var error = $('#errorText .formRowFields'); - if (error) { - error = error.text().trim(); - if (error) { - if (callback) { - callback(new Error(error)); - } - - return; - } - } - - if (callback) { - callback(null); - } - }); - } - - } - } - break; + out.push({ + "name": "profile_showcase[]", + "value": "2" + }); + + if (settings[i][t]["values"].hasOwnProperty("games")) { + showcaseconfig = [true, 4, 2, settings[i][t]["values"]["games"]]; + } + break; + + case 'ownguides': + out.push({ + "name": "profile_showcase[]", + "value": "16" + }); + + for (var n = 0; n < 4; n++) { + var defaultval = ["", ""]; + if (settings[i][t]["values"][n] != undefined) { + defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; + } + out.push({ + "name": "rgShowcaseConfig[16][" + n + "][appid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[16][" + n + "][publishedfileid]", + "value": defaultval[1] + }); + } + break; + + case 'ownguides': + out.push({ + "name": "profile_showcase[]", + "value": "12" + }); + + for (var n = 0; n < 5; n++) { + var defaultval = ["", ""]; + if (settings[i][t]["values"][n] != undefined) { + defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; + } + out.push({ + "name": "rgShowcaseConfig[12][" + n + "][appid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[12][" + n + "][publishedfileid]", + "value": defaultval[1] + }); + } + break; + } + + if (showcaseconfig[0]) { + for (var n = 0; n < showcaseconfig[1]; n++) { + var requestdata; + if (showcaseconfig[3][n] == undefined) { + requestdata = { + appid: 0, + item_contextid: 0, + item_assetid: 0, + customization_type: showcaseconfig[2], + slot: n, + sessionid: formd[0].value + }; + } else { + requestdata = { + appid: showcaseconfig[3][n]["appid"], + item_contextid: showcaseconfig[3][n]["item_contextid"], + item_assetid: showcaseconfig[3][n]["item_assetid"], + customization_type: showcaseconfig[2], + slot: n, + sessionid: formd[0].value + }; + + } + + self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + if (settings.customURL) { + delete selfe._profileURL; + } + + if (err || response.statusCode != 200) { + if (callback) { + callback(err || new Error("HTTP error " + response.statusCode)); + } + + return; + } + + // Check for an error + var $ = Cheerio.load(body); + var error = $('#errorText .formRowFields'); + if (error) { + error = error.text().trim(); + if (error) { + if (callback) { + callback(new Error(error)); + } + + return; + } + } + + if (callback) { + callback(null); + } + }); + } + + } + } + break; } } From a5a03f1919e9cc526e0bd49174e6c1f3554a9f3d Mon Sep 17 00:00:00 2001 From: NetroScript Date: Fri, 20 Jul 2018 18:25:00 +0200 Subject: [PATCH 03/18] Fixing potential error Further testing showed that unlike how it was in my previous tests, that the first 18 elements are not always the same (and same position) and sent in every request. In my personal test only the profile_background parameter was missing, so this code adds this parameter should it be missing in the correct place. I don't know if this is a one time problem or if it is needed to validate all of the 18 first elements of the form. --- components/profile.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/profile.js b/components/profile.js index 0d224b87..803fc470 100644 --- a/components/profile.js +++ b/components/profile.js @@ -55,6 +55,9 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } var formd = form.serializeArray(); + if (formd[15].name != "profile_background") { + formd.splice(15, 0, {"name": "profile_background", "value": ""}); + } var out = [].concat(formd.slice(0,19)); for(var i in settings) { From 0f9ae265317ccb1e069470b5f703aa7c1fe0cd63 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Fri, 20 Jul 2018 23:04:38 +0200 Subject: [PATCH 04/18] Removed dependency of param --- components/profile.js | 9 +++++++-- package.json | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/components/profile.js b/components/profile.js index 803fc470..05c5acde 100644 --- a/components/profile.js +++ b/components/profile.js @@ -1,7 +1,6 @@ const Cheerio = require('cheerio'); const FS = require('fs'); const SteamID = require('steamid'); -const Param = require('jquery-param'); const Helpers = require('./helpers.js'); const SteamCommunity = require('../index.js'); @@ -473,7 +472,13 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } } - self._myProfile("edit", Param(out), function(err, response, body) { + var parameters = []; + for(let i = 0; i < out.length; i++){ + parameters.push(encodeURIComponent(out[i].name) + "=" + encodeURIComponent(out[i].value)); + } + parameters = parameters.join("&"); + + self._myProfile("edit", parameters, function(err, response, body) { if (settings.customURL) { delete self._profileURL; } diff --git a/package.json b/package.json index 697f083e..77cc123c 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,7 @@ "xml2js": "^0.4.11", "cheerio": "0.22.0", "async": "^2.1.4", - "steam-totp": "^1.3.0", - "jquery-param": "1.0.1" + "steam-totp": "^1.3.0" }, "engines": { "node": ">=4.0.0" From de4c3779da8229a3d84b28ac04ccb8aa6570a1cc Mon Sep 17 00:00:00 2001 From: NetroScript Date: Fri, 20 Jul 2018 23:27:31 +0200 Subject: [PATCH 05/18] Ensures the array index for the submitted settings. Now the array index for name for example will always be 8. --- components/profile.js | 79 ++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 47 deletions(-) diff --git a/components/profile.js b/components/profile.js index 05c5acde..23a4d6d6 100644 --- a/components/profile.js +++ b/components/profile.js @@ -53,11 +53,29 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { return; } + var values = {}; var formd = form.serializeArray(); - if (formd[15].name != "profile_background") { - formd.splice(15, 0, {"name": "profile_background", "value": ""}); + var i = 0; + form.serializeArray().forEach(function (item) { + values[item.name] = i; + i++; + }); + var out = []; + var requiredvalues = ["sessionID", "type", "weblink_1_title", "weblink_1_url", "weblink_2_title", "weblink_2_url", "weblink_3_title", "weblink_3_url", "personaName", "real_name", "country", "state", "city", "customURL", "summary", "profile_background", "favorite_badge_badgeid", "favorite_badge_communityitemid", "primary_group_steamid"]; + + for (var i = 0; i < 18; i++) { + if (values.hasOwnProperty(requiredvalues[i])) { + out.push({ + "name": requiredvalues[i], + "value": formd[values[requiredvalues[i]]].value + }); + } else { + out.push({ + "name": requiredvalues[i], + "value": "" + }); + } } - var out = [].concat(formd.slice(0,19)); for(var i in settings) { if(!settings.hasOwnProperty(i)) { @@ -66,81 +84,48 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { switch(i) { case 'name': - out[8] = { - "name": formd[8].name, - "value": settings[i] - }; + out[8].value = settings[i]; break; case 'realName': - out[9] = { - "name": formd[9].name, - "value": settings[i] - }; + out[9].value = settings[i]; break; case 'summary': - out[14] = { - "name": formd[14].name, - "value": settings[i] - }; + out[14].value = settings[i]; break; case 'country': - out[10] = { - "name": formd[10].name, - "value": settings[i] - }; + out[10].value = settings[i]; break; case 'state': - out[11] = { - "name": formd[11].name, - "value": settings[i] - }; + out[11].value = settings[i]; break; case 'city': - out[12] = { - "name": formd[12].name, - "value": settings[i] - }; + out[12].value = settings[i]; break; case 'customURL': - out[13] = { - "name": formd[13].name, - "value": settings[i] - }; + out[13].value = settings[i]; break; case 'background': // The assetid of our desired profile background - out[15] = { - "name": formd[15].name, - "value": settings[i] - }; + out[15].value = settings[i]; break; case 'featuredBadge': // Currently, game badges aren't supported - out[16] = { - "name": formd[16].name, - "value": settings[i] - }; + out[16].value = settings[i]; break; case 'primaryGroup': if (typeof settings[i] === 'object' && settings[i].getSteamID64) { - out[18] = { - "name": formd[18].name, - "value": settings[i].getSteamID64() - }; + out[18].value = settings[i].getSteamID64(); } else { - out[18] = { - "name": formd[18].name, - "value": new SteamID(settings[i]).getSteamID64() - }; + out[18].value = new SteamID(settings[i]).getSteamID64(); } break; From a8d9f16cba252e9c3a20df42be1eddb97d9f7cb2 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Fri, 20 Jul 2018 23:38:33 +0200 Subject: [PATCH 06/18] Improved readability of `showcaseconfig` --- components/profile.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/components/profile.js b/components/profile.js index 23a4d6d6..21a80194 100644 --- a/components/profile.js +++ b/components/profile.js @@ -132,7 +132,13 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { case 'showcases': for (var t in settings[i]) { - var showcaseconfig = [false,0,0,[]]; + //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... + var showcaseconfig = { + "supplied": false, + "numberofrequests": 0, + "showcasetype": 0, + "itemarray": [] + }; switch (settings[i][t].showcase) { @@ -175,7 +181,10 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); if (settings[i][t]["values"].hasOwnProperty("items")) { - showcaseconfig = [true, 6, 4, settings[i][t]["values"]["items"]]; + showcaseconfig.supplied = true; + showcaseconfig.numberofrequests = 6; + showcaseconfig.showcasetype = 4; + showcaseconfig.itemarray = settings[i][t]["values"]["items"]; } break; @@ -186,7 +195,10 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); if (settings[i][t]["values"].hasOwnProperty("items")) { - showcaseconfig = [true, 10, 3, settings[i][t]["values"]["items"]]; + showcaseconfig.supplied = true; + showcaseconfig.numberofrequests = 10; + showcaseconfig.showcasetype = 3; + showcaseconfig.itemarray = settings[i][t]["values"]["items"]; } break; @@ -344,7 +356,10 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); if (settings[i][t]["values"].hasOwnProperty("games")) { - showcaseconfig = [true, 4, 2, settings[i][t]["values"]["games"]]; + showcaseconfig.supplied = true; + showcaseconfig.numberofrequests = 4; + showcaseconfig.showcasetype = 2; + showcaseconfig.itemarray = settings[i][t]["values"]["games"]; } break; @@ -393,24 +408,24 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { break; } - if (showcaseconfig[0]) { - for (var n = 0; n < showcaseconfig[1]; n++) { + if (showcaseconfig.supplied) { + for (var n = 0; n < showcaseconfig.numberofrequests; n++) { var requestdata; - if (showcaseconfig[3][n] == undefined) { + if (showcaseconfig.itemarray[n] == undefined) { requestdata = { appid: 0, item_contextid: 0, item_assetid: 0, - customization_type: showcaseconfig[2], + customization_type: showcaseconfig.showcasetype, slot: n, sessionid: formd[0].value }; } else { requestdata = { - appid: showcaseconfig[3][n]["appid"], - item_contextid: showcaseconfig[3][n]["item_contextid"], - item_assetid: showcaseconfig[3][n]["item_assetid"], - customization_type: showcaseconfig[2], + appid: showcaseconfig.itemarray[n]["appid"], + item_contextid: showcaseconfig.itemarray[n]["item_contextid"], + item_assetid: showcaseconfig.itemarray[n]["item_assetid"], + customization_type: showcaseconfig.showcasetype, slot: n, sessionid: formd[0].value }; From a9264f26a5655d24a85eeecebe24431012e8f4aa Mon Sep 17 00:00:00 2001 From: NetroScript Date: Fri, 20 Jul 2018 23:51:15 +0200 Subject: [PATCH 07/18] Replaced t with type and added delay to the `ajaxsetshowcaseconfig` requests The delay is 1.5 seconds --- components/profile.js | 70 +++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/components/profile.js b/components/profile.js index 21a80194..29e16c5d 100644 --- a/components/profile.js +++ b/components/profile.js @@ -131,7 +131,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { break; case 'showcases': - for (var t in settings[i]) { + for (var type in settings[i]) { //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... var showcaseconfig = { "supplied": false, @@ -140,7 +140,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { "itemarray": [] }; - switch (settings[i][t].showcase) { + switch (settings[i][type].showcase) { case 'infobox': out.push({ @@ -149,11 +149,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); out.push({ "name": "rgShowcaseConfig[8][0][title]", - "value": settings[i][t]["values"]["title"] + "value": settings[i][type]["values"]["title"] }); out.push({ "name": "rgShowcaseConfig[8][0][notes]", - "value": settings[i][t]["values"]["notes"] + "value": settings[i][type]["values"]["notes"] }); break; @@ -165,7 +165,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { for (var n = 0; n < 4; n++) { out.push({ "name": "rgShowcaseConfig[13][" + n + "][publishedfileid]", - "value": settings[i][t]["values"][n] || "" + "value": settings[i][type]["values"][n] || "" }); } break; @@ -177,14 +177,14 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); out.push({ "name": "rgShowcaseConfig[4][6][notes]", - "value": settings[i][t]["values"]["notes"] + "value": settings[i][type]["values"]["notes"] }); - if (settings[i][t]["values"].hasOwnProperty("items")) { + if (settings[i][type]["values"].hasOwnProperty("items")) { showcaseconfig.supplied = true; showcaseconfig.numberofrequests = 6; showcaseconfig.showcasetype = 4; - showcaseconfig.itemarray = settings[i][t]["values"]["items"]; + showcaseconfig.itemarray = settings[i][type]["values"]["items"]; } break; @@ -194,11 +194,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { "value": "3" }); - if (settings[i][t]["values"].hasOwnProperty("items")) { + if (settings[i][type]["values"].hasOwnProperty("items")) { showcaseconfig.supplied = true; showcaseconfig.numberofrequests = 10; showcaseconfig.showcasetype = 3; - showcaseconfig.itemarray = settings[i][t]["values"]["items"]; + showcaseconfig.itemarray = settings[i][type]["values"]["items"]; } break; @@ -209,7 +209,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); out.push({ "name": "rgShowcaseConfig[6][0][appid]", - "value": settings[i][t]["values"]["appid"] + "value": settings[i][type]["values"]["appid"] }); break; @@ -221,14 +221,14 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { var styles = ["rare","selected",null,"recent","random"]; out.push({ "name": "profile_showcase_style_5", - "value": styles.indexOf(settings[i][t]["values"]["style"]) + "value": styles.indexOf(settings[i][type]["values"]["style"]) }); - if (settings[i][t]["values"].hasOwnProperty("badges")){ + if (settings[i][type]["values"].hasOwnProperty("badges")){ for(var n = 0; n < 6; n++){ var defaultval = ["", "", ""]; - if (settings[i][t]["values"]["badges"][n] != undefined) { - defaultval = [settings[i][t]["values"]["badges"][n]["badgeid"], settings[i][t]["values"]["badges"][n]["appid"], settings[i][t]["values"]["badges"][n]["border_color"]]; + if (settings[i][type]["values"]["badges"][n] != undefined) { + defaultval = [settings[i][type]["values"]["badges"][n]["badgeid"], settings[i][type]["values"]["badges"][n]["appid"], settings[i][type]["values"]["badges"][n]["border_color"]]; } out.push({ "name": "rgShowcaseConfig[5][" + n + "][badgeid]", @@ -262,7 +262,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { for (var n = 0; n < 4; n++) { out.push({ "name": "rgShowcaseConfig[7][" + n + "][publishedfileid]", - "value": settings[i][t]["values"][n] || "" + "value": settings[i][type]["values"][n] || "" }); } break; @@ -272,15 +272,15 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { "name": "profile_showcase[]", "value": "9" }); - if (typeof settings[i][t]["values"]["groupid"] === 'object' && settings[i][t]["values"]["groupid"].getSteamID64) { + if (typeof settings[i][type]["values"]["groupid"] === 'object' && settings[i][type]["values"]["groupid"].getSteamID64) { out.push({ "name": "rgShowcaseConfig[9][0][accountid]", - "value": settings[i][t]["values"]["groupid"].getSteamID64() + "value": settings[i][type]["values"]["groupid"].getSteamID64() }); } else { out.push({ "name": "rgShowcaseConfig[9][0][accountid]", - "value": new SteamID(settings[i][t]["values"]["groupid"]).getSteamID64() + "value": new SteamID(settings[i][type]["values"]["groupid"]).getSteamID64() }); } break; @@ -292,7 +292,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); out.push({ "name": "rgShowcaseConfig[10][0][appid]", - "value": settings[i][t]["values"]["appid"] + "value": settings[i][type]["values"]["appid"] }); break; @@ -303,11 +303,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); out.push({ "name": "rgShowcaseConfig[11][0][appid]", - "value": settings[i][t]["values"]["appid"] + "value": settings[i][type]["values"]["appid"] }); out.push({ "name": "rgShowcaseConfig[11][0][publishedfileid]", - "value": settings[i][t]["values"]["publishedfileid"] + "value": settings[i][type]["values"]["publishedfileid"] }); break; @@ -318,11 +318,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }); out.push({ "name": "rgShowcaseConfig[15][0][appid]", - "value": settings[i][t]["values"]["appid"] + "value": settings[i][type]["values"]["appid"] }); out.push({ "name": "rgShowcaseConfig[15][0][publishedfileid]", - "value": settings[i][t]["values"]["publishedfileid"] + "value": settings[i][type]["values"]["publishedfileid"] }); break; @@ -331,11 +331,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { "name": "profile_showcase[]", "value": "17" }); - if (settings[i][t]["values"].hasOwnProperty("achievements")) { + if (settings[i][type]["values"].hasOwnProperty("achievements")) { for (var n = 0; n < 7; n++) { var defaultval = ["", ""]; - if (settings[i][t]["values"]["achievements"][n] != undefined) { - defaultval = [settings[i][t]["values"]["achievements"][n]["appid"], settings[i][t]["values"]["achievements"][n]["title"]]; + if (settings[i][type]["values"]["achievements"][n] != undefined) { + defaultval = [settings[i][type]["values"]["achievements"][n]["appid"], settings[i][type]["values"]["achievements"][n]["title"]]; } out.push({ "name": "rgShowcaseConfig[17][" + n + "][appid]", @@ -355,11 +355,11 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { "value": "2" }); - if (settings[i][t]["values"].hasOwnProperty("games")) { + if (settings[i][type]["values"].hasOwnProperty("games")) { showcaseconfig.supplied = true; showcaseconfig.numberofrequests = 4; showcaseconfig.showcasetype = 2; - showcaseconfig.itemarray = settings[i][t]["values"]["games"]; + showcaseconfig.itemarray = settings[i][type]["values"]["games"]; } break; @@ -371,8 +371,8 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { for (var n = 0; n < 4; n++) { var defaultval = ["", ""]; - if (settings[i][t]["values"][n] != undefined) { - defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; + if (settings[i][type]["values"][n] != undefined) { + defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; } out.push({ "name": "rgShowcaseConfig[16][" + n + "][appid]", @@ -393,8 +393,8 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { for (var n = 0; n < 5; n++) { var defaultval = ["", ""]; - if (settings[i][t]["values"][n] != undefined) { - defaultval = [settings[i][t]["values"][n]["appid"], settings[i][t]["values"][n]["publishedfileid"]]; + if (settings[i][type]["values"][n] != undefined) { + defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; } out.push({ "name": "rgShowcaseConfig[12][" + n + "][appid]", @@ -432,7 +432,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } - self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + setTimeout(self._myProfile.bind(self,"ajaxsetshowcaseconfig", requestdata, function (err, response, body) { if (settings.customURL) { delete selfe._profileURL; } @@ -462,7 +462,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { if (callback) { callback(null); } - }); + }), n * 1500); } } From 72b57d4432e401b800b96f4657a4138d5b25af09 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 14:06:50 +0200 Subject: [PATCH 08/18] Improved behaviour of callbacks when a request to change a single item failed. With the variable `showshowcaseconfigerrors` (true or false) in the values object it is now possible to control if the callback is called when a request fails. Additionally the callback is fired only once now in any case and the error message has the string appended, that the error happened when changing a specific item. (` | Happened while updating specific showcase items.`) --- components/profile.js | 44 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/components/profile.js b/components/profile.js index 29e16c5d..6a603c42 100644 --- a/components/profile.js +++ b/components/profile.js @@ -139,7 +139,16 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { "showcasetype": 0, "itemarray": [] }; - + //Controls if the callback function is called when a request changing f.e. a single item or game in a showcase fails + var errorcontrol = { + error: false, + showerrors: false + }; + if(settings[i][type].hasOwnProperty("values")){ + if(settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")){ + errorcontrol.showerrors = settings[i][type]["values"]["showshowcaseconfigerrors"]; + } + } switch (settings[i][type].showcase) { case 'infobox': @@ -433,36 +442,19 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } setTimeout(self._myProfile.bind(self,"ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - if (settings.customURL) { - delete selfe._profileURL; - } - if (err || response.statusCode != 200) { - if (callback) { - callback(err || new Error("HTTP error " + response.statusCode)); + if (err || response.statusCode != 200 && this.showerrors) { + if(err){ + err.message += " | Happened while updating specific showcase items."; } - return; - } - - // Check for an error - var $ = Cheerio.load(body); - var error = $('#errorText .formRowFields'); - if (error) { - error = error.text().trim(); - if (error) { - if (callback) { - callback(new Error(error)); - } - - return; + if (callback && !this.error) { + callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); } + this.error = true; + return; } - - if (callback) { - callback(null); - } - }), n * 1500); + }.bind(errorcontrol)), n * 1500); } } From 8c61d785e3e8d8d9aad4b80c071518c9d1bcab82 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 14:28:55 +0200 Subject: [PATCH 09/18] Fixing indention + removing unnecessary iterator variable --- components/profile.js | 176 +++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 89 deletions(-) diff --git a/components/profile.js b/components/profile.js index 6a603c42..4ffa8f56 100644 --- a/components/profile.js +++ b/components/profile.js @@ -55,10 +55,8 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { var values = {}; var formd = form.serializeArray(); - var i = 0; - form.serializeArray().forEach(function (item) { + form.serializeArray().forEach(function (item, i) { values[item.name] = i; - i++; }); var out = []; var requiredvalues = ["sessionID", "type", "weblink_1_title", "weblink_1_url", "weblink_2_title", "weblink_2_url", "weblink_3_title", "weblink_3_url", "personaName", "real_name", "country", "state", "city", "customURL", "summary", "profile_background", "favorite_badge_badgeid", "favorite_badge_communityitemid", "primary_group_steamid"]; @@ -118,7 +116,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { case 'featuredBadge': // Currently, game badges aren't supported - out[16].value = settings[i]; + out[16].value = settings[i]; break; case 'primaryGroup': @@ -358,107 +356,107 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } break; - case 'games': - out.push({ - "name": "profile_showcase[]", - "value": "2" - }); + case 'games': + out.push({ + "name": "profile_showcase[]", + "value": "2" + }); - if (settings[i][type]["values"].hasOwnProperty("games")) { - showcaseconfig.supplied = true; - showcaseconfig.numberofrequests = 4; - showcaseconfig.showcasetype = 2; - showcaseconfig.itemarray = settings[i][type]["values"]["games"]; - } - break; + if (settings[i][type]["values"].hasOwnProperty("games")) { + showcaseconfig.supplied = true; + showcaseconfig.numberofrequests = 4; + showcaseconfig.showcasetype = 2; + showcaseconfig.itemarray = settings[i][type]["values"]["games"]; + } + break; - case 'ownguides': - out.push({ - "name": "profile_showcase[]", - "value": "16" - }); + case 'ownguides': + out.push({ + "name": "profile_showcase[]", + "value": "16" + }); - for (var n = 0; n < 4; n++) { - var defaultval = ["", ""]; - if (settings[i][type]["values"][n] != undefined) { - defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; - } - out.push({ - "name": "rgShowcaseConfig[16][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[16][" + n + "][publishedfileid]", - "value": defaultval[1] - }); + for (var n = 0; n < 4; n++) { + var defaultval = ["", ""]; + if (settings[i][type]["values"][n] != undefined) { + defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; } - break; - - case 'ownguides': out.push({ - "name": "profile_showcase[]", - "value": "12" + "name": "rgShowcaseConfig[16][" + n + "][appid]", + "value": defaultval[0] }); + out.push({ + "name": "rgShowcaseConfig[16][" + n + "][publishedfileid]", + "value": defaultval[1] + }); + } + break; - for (var n = 0; n < 5; n++) { - var defaultval = ["", ""]; - if (settings[i][type]["values"][n] != undefined) { - defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; - } - out.push({ - "name": "rgShowcaseConfig[12][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[12][" + n + "][publishedfileid]", - "value": defaultval[1] - }); - } - break; - } - - if (showcaseconfig.supplied) { - for (var n = 0; n < showcaseconfig.numberofrequests; n++) { - var requestdata; - if (showcaseconfig.itemarray[n] == undefined) { - requestdata = { - appid: 0, - item_contextid: 0, - item_assetid: 0, - customization_type: showcaseconfig.showcasetype, - slot: n, - sessionid: formd[0].value - }; - } else { - requestdata = { - appid: showcaseconfig.itemarray[n]["appid"], - item_contextid: showcaseconfig.itemarray[n]["item_contextid"], - item_assetid: showcaseconfig.itemarray[n]["item_assetid"], - customization_type: showcaseconfig.showcasetype, - slot: n, - sessionid: formd[0].value - }; + case 'ownguides': + out.push({ + "name": "profile_showcase[]", + "value": "12" + }); + for (var n = 0; n < 5; n++) { + var defaultval = ["", ""]; + if (settings[i][type]["values"][n] != undefined) { + defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; } + out.push({ + "name": "rgShowcaseConfig[12][" + n + "][appid]", + "value": defaultval[0] + }); + out.push({ + "name": "rgShowcaseConfig[12][" + n + "][publishedfileid]", + "value": defaultval[1] + }); + } + break; + } + + if (showcaseconfig.supplied) { + for (var n = 0; n < showcaseconfig.numberofrequests; n++) { + var requestdata; + if (showcaseconfig.itemarray[n] == undefined) { + requestdata = { + appid: 0, + item_contextid: 0, + item_assetid: 0, + customization_type: showcaseconfig.showcasetype, + slot: n, + sessionid: formd[0].value + }; + } else { + requestdata = { + appid: showcaseconfig.itemarray[n]["appid"], + item_contextid: showcaseconfig.itemarray[n]["item_contextid"], + item_assetid: showcaseconfig.itemarray[n]["item_assetid"], + customization_type: showcaseconfig.showcasetype, + slot: n, + sessionid: formd[0].value + }; - setTimeout(self._myProfile.bind(self,"ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + } - if (err || response.statusCode != 200 && this.showerrors) { - if(err){ - err.message += " | Happened while updating specific showcase items."; - } + setTimeout(self._myProfile.bind(self,"ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - if (callback && !this.error) { - callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); - } - this.error = true; - return; + if (err || response.statusCode != 200 && this.showerrors) { + if(err){ + err.message += " | Happened while updating specific showcase items."; } - }.bind(errorcontrol)), n * 1500); - } + if (callback && !this.error) { + callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); + } + this.error = true; + return; + } + }.bind(errorcontrol)), n * 1500); } } + + } break; } From cba563bdf578ff553ee0150c79758b064ec1e5e1 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 14:38:06 +0200 Subject: [PATCH 10/18] Improved timeout for additional changes to showcase config items. Now it can't happen, that f.e. games and items are changed at the same time leading to simultaneous requests. --- components/profile.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/profile.js b/components/profile.js index 4ffa8f56..ab2a1ce7 100644 --- a/components/profile.js +++ b/components/profile.js @@ -129,6 +129,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { break; case 'showcases': + var num_of_requests = 0; for (var type in settings[i]) { //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... var showcaseconfig = { @@ -417,6 +418,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { if (showcaseconfig.supplied) { for (var n = 0; n < showcaseconfig.numberofrequests; n++) { + num_of_requests++; var requestdata; if (showcaseconfig.itemarray[n] == undefined) { requestdata = { @@ -452,7 +454,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { this.error = true; return; } - }.bind(errorcontrol)), n * 1500); + }.bind(errorcontrol)), num_of_requests * 1500); } } From 47e6d2308833f63146d3d3239786e4b4ccf77bc5 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 16:28:14 +0200 Subject: [PATCH 11/18] Rewrite from array to object. Additionally now all values are unchanged if not supplied, or supplied as `undefined` in arrays. Showcases where the `values` property had only one value were changed to only this value instead of an additonaly object with f.e. "appid" as key. (Showcases were this changed are `game`,`review`,`group`). Additionally changed condition for errors in `ajaxsetshowcaseconfig` so they only throw an error in the correct scenario. --- components/profile.js | 413 ++++++++++++++++-------------------------- 1 file changed, 157 insertions(+), 256 deletions(-) diff --git a/components/profile.js b/components/profile.js index ab2a1ce7..e470f787 100644 --- a/components/profile.js +++ b/components/profile.js @@ -54,82 +54,73 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } var values = {}; - var formd = form.serializeArray(); - form.serializeArray().forEach(function (item, i) { - values[item.name] = i; + form.serializeArray().forEach(function (item) { + values[item.name] = item.value; }); - var out = []; - var requiredvalues = ["sessionID", "type", "weblink_1_title", "weblink_1_url", "weblink_2_title", "weblink_2_url", "weblink_3_title", "weblink_3_url", "personaName", "real_name", "country", "state", "city", "customURL", "summary", "profile_background", "favorite_badge_badgeid", "favorite_badge_communityitemid", "primary_group_steamid"]; - - for (var i = 0; i < 18; i++) { - if (values.hasOwnProperty(requiredvalues[i])) { - out.push({ - "name": requiredvalues[i], - "value": formd[values[requiredvalues[i]]].value - }); - } else { - out.push({ - "name": requiredvalues[i], - "value": "" - }); - } - } - for(var i in settings) { - if(!settings.hasOwnProperty(i)) { + for (var i in settings) { + if (!settings.hasOwnProperty(i)) { continue; } - - switch(i) { + switch (i) { case 'name': - out[8].value = settings[i]; + values.personaName = settings[i]; break; case 'realName': - out[9].value = settings[i]; + values.real_name = settings[i]; break; case 'summary': - out[14].value = settings[i]; + values.summary = settings[i]; break; case 'country': - out[10].value = settings[i]; + values.country = settings[i]; break; case 'state': - out[11].value = settings[i]; + values.state = settings[i]; break; case 'city': - out[12].value = settings[i]; + values.city = settings[i]; break; case 'customURL': - out[13].value = settings[i]; + values.customURL = settings[i]; break; case 'background': // The assetid of our desired profile background - out[15].value = settings[i]; + values.profile_background = settings[i]; break; case 'featuredBadge': // Currently, game badges aren't supported - out[16].value = settings[i]; + values.favorite_badge_badgeid = settings[i]; break; case 'primaryGroup': if (typeof settings[i] === 'object' && settings[i].getSteamID64) { - out[18].value = settings[i].getSteamID64(); + values.primary_group_steamid = settings[i].getSteamID64(); } else { - out[18].value = new SteamID(settings[i]).getSteamID64(); + values.primary_group_steamid = new SteamID(settings[i]).getSteamID64(); } break; + case 'showcases': var num_of_requests = 0; + //When supplying a new showcases array, remove the old showcase (order) + for (var val in values) { + if (val.indexOf("[") !== -1) { + if (val.split("[")[0] == "profile_showcase") + delete values[val]; + } + + } for (var type in settings[i]) { //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... var showcaseconfig = { @@ -143,66 +134,59 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { error: false, showerrors: false }; - if(settings[i][type].hasOwnProperty("values")){ - if(settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")){ + if (settings[i][type].hasOwnProperty("values")) { + if (settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")) { errorcontrol.showerrors = settings[i][type]["values"]["showshowcaseconfigerrors"]; } } switch (settings[i][type].showcase) { case 'infobox': - out.push({ - "name": "profile_showcase[]", - "value": "8" - }); - out.push({ - "name": "rgShowcaseConfig[8][0][title]", - "value": settings[i][type]["values"]["title"] - }); - out.push({ - "name": "rgShowcaseConfig[8][0][notes]", - "value": settings[i][type]["values"]["notes"] - }); + values["profile_showcase[8]"] = 8; + + if (settings[i][type].hasOwnProperty("values")){ + if (settings[i][type]["values"].hasOwnProperty("title")){ + values["rgShowcaseConfig[8][0][title]"] = settings[i][type]["values"]["title"]; + } + if (settings[i][type]["values"].hasOwnProperty("notes")) { + values["rgShowcaseConfig[8][0][notes]"] = settings[i][type]["values"]["notes"]; + } + } + break; case 'artwork': - out.push({ - "name": "profile_showcase[]", - "value": "13" - }); - for (var n = 0; n < 4; n++) { - out.push({ - "name": "rgShowcaseConfig[13][" + n + "][publishedfileid]", - "value": settings[i][type]["values"][n] || "" - }); + values["profile_showcase[13]"] = 13; + + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + values["profile_showcase[13][" + n + "][publishedfileid]"] = settings[i][type]["values"][n] || ""; + } } break; case 'trade': - out.push({ - "name": "profile_showcase[]", - "value": "4" - }); - out.push({ - "name": "rgShowcaseConfig[4][6][notes]", - "value": settings[i][type]["values"]["notes"] - }); - - if (settings[i][type]["values"].hasOwnProperty("items")) { - showcaseconfig.supplied = true; - showcaseconfig.numberofrequests = 6; - showcaseconfig.showcasetype = 4; - showcaseconfig.itemarray = settings[i][type]["values"]["items"]; + values["profile_showcase[4]"] = 4; + + if (settings[i][type].hasOwnProperty("values")) { + + if (settings[i][type]["values"].hasOwnProperty("notes")) { + values["rgShowcaseConfig[4][6][notes]"] = settings[i][type]["values"]["notes"]; + } + + if (settings[i][type]["values"].hasOwnProperty("items")) { + showcaseconfig.supplied = true; + showcaseconfig.numberofrequests = 6; + showcaseconfig.showcasetype = 4; + showcaseconfig.itemarray = settings[i][type]["values"]["items"]; + } } break; case 'items': - out.push({ - "name": "profile_showcase[]", - "value": "3" - }); + values["profile_showcase[3]"] = 3; - if (settings[i][type]["values"].hasOwnProperty("items")) { + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("items")) { showcaseconfig.supplied = true; showcaseconfig.numberofrequests = 10; showcaseconfig.showcasetype = 3; @@ -211,159 +195,110 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { break; case 'game': - out.push({ - "name": "profile_showcase[]", - "value": "6" - }); - out.push({ - "name": "rgShowcaseConfig[6][0][appid]", - "value": settings[i][type]["values"]["appid"] - }); + values["profile_showcase[6]"] = 6; + + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[6][0][appid]"] = settings[i][type]["values"]; + } break; case 'badge': - out.push({ - "name": "profile_showcase[]", - "value": "5" - }); - var styles = ["rare","selected",null,"recent","random"]; - out.push({ - "name": "profile_showcase_style_5", - "value": styles.indexOf(settings[i][type]["values"]["style"]) - }); - - if (settings[i][type]["values"].hasOwnProperty("badges")){ - for(var n = 0; n < 6; n++){ - var defaultval = ["", "", ""]; - if (settings[i][type]["values"]["badges"][n] != undefined) { - defaultval = [settings[i][type]["values"]["badges"][n]["badgeid"], settings[i][type]["values"]["badges"][n]["appid"], settings[i][type]["values"]["badges"][n]["border_color"]]; + values["profile_showcase[5]"] = 5; + + if (settings[i][type].hasOwnProperty("values")) { + + if (settings[i][type]["values"].hasOwnProperty("style")) { + var styles = ["rare", "selected", null, "recent", "random"]; + values["profile_showcase_style_5"] = styles.indexOf(settings[i][type]["values"]["style"]); + } + + if (settings[i][type]["values"].hasOwnProperty("badges")) { + var types = ["badgeid", "appid", "border_color"]; + for (var n = 0; n < 6; n++) { + for (var m = 0; m < 3; m++){ + if (settings[i][type]["values"]["badges"][n] != undefined) { + if (settings[i][type]["values"]["badges"][n].hasOwnProperty(types[m])){ + values["rgShowcaseConfig[5][" + n + "][" + types[m] + "]"] = settings[i][type]["values"]["badges"][n][types[m]] || values["rgShowcaseConfig[5][" + n + "][" + types[m] + "]"] || ""; + } + } + } } - out.push({ - "name": "rgShowcaseConfig[5][" + n + "][badgeid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[5][" + n + "][appid]", - "value": defaultval[1] - }); - out.push({ - "name": "rgShowcaseConfig[5][" + n + "][border_color]", - "value": defaultval[2] - }); } } break; case 'rareachievements': - out.push({ - "name": "profile_showcase[]", - "value": "1" - }); + values["profile_showcase[1]"] = 1; break; case 'screenshot': - out.push({ - "name": "profile_showcase[]", - "value": "7" - }); - for (var n = 0; n < 4; n++) { - out.push({ - "name": "rgShowcaseConfig[7][" + n + "][publishedfileid]", - "value": settings[i][type]["values"][n] || "" - }); + values["profile_showcase[7]"] = 7; + + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[7][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]; + } + } } break; case 'group': - out.push({ - "name": "profile_showcase[]", - "value": "9" - }); - if (typeof settings[i][type]["values"]["groupid"] === 'object' && settings[i][type]["values"]["groupid"].getSteamID64) { - out.push({ - "name": "rgShowcaseConfig[9][0][accountid]", - "value": settings[i][type]["values"]["groupid"].getSteamID64() - }); - } else { - out.push({ - "name": "rgShowcaseConfig[9][0][accountid]", - "value": new SteamID(settings[i][type]["values"]["groupid"]).getSteamID64() - }); + values["profile_showcase[9]"] = 9; + + if (settings[i][type].hasOwnProperty("values")) { + if (typeof settings[i][type]["values"] === 'object' && settings[i][type]["values"].getSteamID64) { + values["rgShowcaseConfig[9][0][accountid]"] = settings[i][type]["values"].getSteamID64(); + } else { + values["rgShowcaseConfig[9][0][accountid]"] = new SteamID(settings[i][type]["values"]).getSteamID64(); + } } break; case 'review': - out.push({ - "name": "profile_showcase[]", - "value": "10" - }); - out.push({ - "name": "rgShowcaseConfig[10][0][appid]", - "value": settings[i][type]["values"]["appid"] - }); + values["profile_showcase[10]"] = 10; + + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[10][0][appid]"] = settings[i][type]["values"]; + } break; case 'workshop': - out.push({ - "name": "profile_showcase[]", - "value": "11" - }); - out.push({ - "name": "rgShowcaseConfig[11][0][appid]", - "value": settings[i][type]["values"]["appid"] - }); - out.push({ - "name": "rgShowcaseConfig[11][0][publishedfileid]", - "value": settings[i][type]["values"]["publishedfileid"] - }); + values["profile_showcase[11]"] = 11; + + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[11][0][appid]"] = settings[i][type]["values"]["appid"]; + values["rgShowcaseConfig[11][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; + } break; case 'guide': - out.push({ - "name": "profile_showcase[]", - "value": "15" - }); - out.push({ - "name": "rgShowcaseConfig[15][0][appid]", - "value": settings[i][type]["values"]["appid"] - }); - out.push({ - "name": "rgShowcaseConfig[15][0][publishedfileid]", - "value": settings[i][type]["values"]["publishedfileid"] - }); + values["profile_showcase[15]"] = 15; + + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[15][0][appid]"] = settings[i][type]["values"]["appid"]; + values["rgShowcaseConfig[15][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; + } break; case 'achievements': - out.push({ - "name": "profile_showcase[]", - "value": "17" - }); - if (settings[i][type]["values"].hasOwnProperty("achievements")) { + values["profile_showcase[17]"] = 17; + + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("achievements")) { for (var n = 0; n < 7; n++) { - var defaultval = ["", ""]; if (settings[i][type]["values"]["achievements"][n] != undefined) { - defaultval = [settings[i][type]["values"]["achievements"][n]["appid"], settings[i][type]["values"]["achievements"][n]["title"]]; + values["rgShowcaseConfig[17][" + n + "][appid]"] = settings[i][type]["values"]["achievements"][n]["appid"]; + values["rgShowcaseConfig[17][" + n + "][title]"] = settings[i][type]["values"]["achievements"][n]["title"]; } - out.push({ - "name": "rgShowcaseConfig[17][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[17][" + n + "][title]", - "value": defaultval[1] - }); } } break; case 'games': - out.push({ - "name": "profile_showcase[]", - "value": "2" - }); + values["profile_showcase[2]"] = 2; - if (settings[i][type]["values"].hasOwnProperty("games")) { + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("games")) { showcaseconfig.supplied = true; showcaseconfig.numberofrequests = 4; showcaseconfig.showcasetype = 2; @@ -372,90 +307,62 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { break; case 'ownguides': - out.push({ - "name": "profile_showcase[]", - "value": "16" - }); - - for (var n = 0; n < 4; n++) { - var defaultval = ["", ""]; - if (settings[i][type]["values"][n] != undefined) { - defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; + values["profile_showcase[16]"] = 16; + + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[16][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; + values["rgShowcaseConfig[16][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; + } } - out.push({ - "name": "rgShowcaseConfig[16][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[16][" + n + "][publishedfileid]", - "value": defaultval[1] - }); } break; case 'ownguides': - out.push({ - "name": "profile_showcase[]", - "value": "12" - }); - - for (var n = 0; n < 5; n++) { - var defaultval = ["", ""]; - if (settings[i][type]["values"][n] != undefined) { - defaultval = [settings[i][type]["values"][n]["appid"], settings[i][type]["values"][n]["publishedfileid"]]; + values["profile_showcase[12]"] = 12; + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 5; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[12][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; + values["rgShowcaseConfig[12][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; + } } - out.push({ - "name": "rgShowcaseConfig[12][" + n + "][appid]", - "value": defaultval[0] - }); - out.push({ - "name": "rgShowcaseConfig[12][" + n + "][publishedfileid]", - "value": defaultval[1] - }); } break; } if (showcaseconfig.supplied) { for (var n = 0; n < showcaseconfig.numberofrequests; n++) { - num_of_requests++; var requestdata; - if (showcaseconfig.itemarray[n] == undefined) { - requestdata = { - appid: 0, - item_contextid: 0, - item_assetid: 0, - customization_type: showcaseconfig.showcasetype, - slot: n, - sessionid: formd[0].value - }; - } else { + if (showcaseconfig.itemarray[n] != undefined) { + num_of_requests++; requestdata = { appid: showcaseconfig.itemarray[n]["appid"], item_contextid: showcaseconfig.itemarray[n]["item_contextid"], item_assetid: showcaseconfig.itemarray[n]["item_assetid"], customization_type: showcaseconfig.showcasetype, slot: n, - sessionid: formd[0].value + sessionid: values.sessionID }; - } + setTimeout(self._myProfile.bind(self, "ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - setTimeout(self._myProfile.bind(self,"ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + if ((err || response.statusCode != 200) && this.showerrors) { + if (err) { + err.message += " | Happened while updating specific showcase items."; + } - if (err || response.statusCode != 200 && this.showerrors) { - if(err){ - err.message += " | Happened while updating specific showcase items."; + if (callback && !this.error) { + callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); + } + this.error = true; + return; } - if (callback && !this.error) { - callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); - } - this.error = true; - return; - } - }.bind(errorcontrol)), num_of_requests * 1500); - } + + }.bind(errorcontrol)), num_of_requests * 1500); + } } } @@ -464,13 +371,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } } - var parameters = []; - for(let i = 0; i < out.length; i++){ - parameters.push(encodeURIComponent(out[i].name) + "=" + encodeURIComponent(out[i].value)); - } - parameters = parameters.join("&"); - - self._myProfile("edit", parameters, function(err, response, body) { + self._myProfile("edit", values, function(err, response, body) { if (settings.customURL) { delete self._profileURL; } From 1b6364e2061e1ba0e77a789e38bb7baed79404fc Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 16:50:09 +0200 Subject: [PATCH 12/18] Added missing curly braces --- components/profile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/components/profile.js b/components/profile.js index e470f787..bc3b31f1 100644 --- a/components/profile.js +++ b/components/profile.js @@ -363,6 +363,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { }.bind(errorcontrol)), num_of_requests * 1500); } + } } } From bc0034964fb384405f993c6e152965e3459331ff Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 20:49:37 +0200 Subject: [PATCH 13/18] Check for the maximum number of possible showcases Now ignore additional showcases when a specific number of showcases was already set. + Additional whitespace + some `consistency` --- components/profile.js | 382 ++++++++++++++++++++++-------------------- 1 file changed, 197 insertions(+), 185 deletions(-) diff --git a/components/profile.js b/components/profile.js index bc3b31f1..797bb9a1 100644 --- a/components/profile.js +++ b/components/profile.js @@ -58,6 +58,8 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { values[item.name] = item.value; }); + var maxshowcases = $(".profile_showcase_selector").length; + for (var i in settings) { if (!settings.hasOwnProperty(i)) { continue; @@ -112,260 +114,270 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { case 'showcases': - var num_of_requests = 0; + var numofrequests = 0; + //When supplying a new showcases array, remove the old showcase (order) for (var val in values) { if (val.indexOf("[") !== -1) { if (val.split("[")[0] == "profile_showcase") delete values[val]; } - } + for (var type in settings[i]) { - //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... - var showcaseconfig = { - "supplied": false, - "numberofrequests": 0, - "showcasetype": 0, - "itemarray": [] - }; - //Controls if the callback function is called when a request changing f.e. a single item or game in a showcase fails - var errorcontrol = { - error: false, - showerrors: false - }; - if (settings[i][type].hasOwnProperty("values")) { - if (settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")) { - errorcontrol.showerrors = settings[i][type]["values"]["showshowcaseconfigerrors"]; - } - } - switch (settings[i][type].showcase) { - case 'infobox': - values["profile_showcase[8]"] = 8; + if(maxshowcases > 0){ - if (settings[i][type].hasOwnProperty("values")){ - if (settings[i][type]["values"].hasOwnProperty("title")){ - values["rgShowcaseConfig[8][0][title]"] = settings[i][type]["values"]["title"]; - } - if (settings[i][type]["values"].hasOwnProperty("notes")) { - values["rgShowcaseConfig[8][0][notes]"] = settings[i][type]["values"]["notes"]; - } - } + maxshowcases--; - break; + //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... + var showcaseconfig = { + "supplied": false, + "numberofrequests": 0, + "showcasetype": 0, + "itemarray": [] + }; - case 'artwork': - values["profile_showcase[13]"] = 13; + //Controls if the callback function is called when a request changing f.e. a single item or game in a showcase fails + var errorcontrol = { + "error": false, + "showerrors": false + }; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 4; n++) { - values["profile_showcase[13][" + n + "][publishedfileid]"] = settings[i][type]["values"][n] || ""; - } + if (settings[i][type].hasOwnProperty("values")) { + if (settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")) { + errorcontrol["showerrors"] = settings[i][type]["values"]["showshowcaseconfigerrors"]; } - break; + } - case 'trade': - values["profile_showcase[4]"] = 4; + switch (settings[i][type].showcase) { - if (settings[i][type].hasOwnProperty("values")) { + case 'infobox': + values["profile_showcase[8]"] = 8; - if (settings[i][type]["values"].hasOwnProperty("notes")) { - values["rgShowcaseConfig[4][6][notes]"] = settings[i][type]["values"]["notes"]; + if (settings[i][type].hasOwnProperty("values")){ + if (settings[i][type]["values"].hasOwnProperty("title")){ + values["rgShowcaseConfig[8][0][title]"] = settings[i][type]["values"]["title"]; + } + if (settings[i][type]["values"].hasOwnProperty("notes")) { + values["rgShowcaseConfig[8][0][notes]"] = settings[i][type]["values"]["notes"]; + } } - if (settings[i][type]["values"].hasOwnProperty("items")) { - showcaseconfig.supplied = true; - showcaseconfig.numberofrequests = 6; - showcaseconfig.showcasetype = 4; - showcaseconfig.itemarray = settings[i][type]["values"]["items"]; + break; + + case 'artwork': + values["profile_showcase[13]"] = 13; + + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + values["profile_showcase[13][" + n + "][publishedfileid]"] = settings[i][type]["values"][n] || ""; + } } - } - break; + break; - case 'items': - values["profile_showcase[3]"] = 3; + case 'trade': + values["profile_showcase[4]"] = 4; - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("items")) { - showcaseconfig.supplied = true; - showcaseconfig.numberofrequests = 10; - showcaseconfig.showcasetype = 3; - showcaseconfig.itemarray = settings[i][type]["values"]["items"]; - } - break; + if (settings[i][type].hasOwnProperty("values")) { - case 'game': - values["profile_showcase[6]"] = 6; + if (settings[i][type]["values"].hasOwnProperty("notes")) { + values["rgShowcaseConfig[4][6][notes]"] = settings[i][type]["values"]["notes"]; + } - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[6][0][appid]"] = settings[i][type]["values"]; - } - break; + if (settings[i][type]["values"].hasOwnProperty("items")) { + showcaseconfig["supplied"] = true; + showcaseconfig["numberofrequests"] = 6; + showcaseconfig["showcasetype"] = 4; + showcaseconfig["itemarray"] = settings[i][type]["values"]["items"]; + } + } + break; - case 'badge': - values["profile_showcase[5]"] = 5; + case 'items': + values["profile_showcase[3]"] = 3; - if (settings[i][type].hasOwnProperty("values")) { + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("items")) { + showcaseconfig["supplied"] = true; + showcaseconfig["numberofrequests"] = 10; + showcaseconfig["showcasetype"] = 3; + showcaseconfig["itemarray"] = settings[i][type]["values"]["items"]; + } + break; + + case 'game': + values["profile_showcase[6]"] = 6; - if (settings[i][type]["values"].hasOwnProperty("style")) { - var styles = ["rare", "selected", null, "recent", "random"]; - values["profile_showcase_style_5"] = styles.indexOf(settings[i][type]["values"]["style"]); + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[6][0][appid]"] = settings[i][type]["values"]; } + break; + + case 'badge': + values["profile_showcase[5]"] = 5; + + if (settings[i][type].hasOwnProperty("values")) { - if (settings[i][type]["values"].hasOwnProperty("badges")) { - var types = ["badgeid", "appid", "border_color"]; - for (var n = 0; n < 6; n++) { - for (var m = 0; m < 3; m++){ - if (settings[i][type]["values"]["badges"][n] != undefined) { - if (settings[i][type]["values"]["badges"][n].hasOwnProperty(types[m])){ - values["rgShowcaseConfig[5][" + n + "][" + types[m] + "]"] = settings[i][type]["values"]["badges"][n][types[m]] || values["rgShowcaseConfig[5][" + n + "][" + types[m] + "]"] || ""; + if (settings[i][type]["values"].hasOwnProperty("style")) { + var styles = ["rare", "selected", null, "recent", "random"]; + values["profile_showcase_style_5"] = styles.indexOf(settings[i][type]["values"]["style"]); + } + + if (settings[i][type]["values"].hasOwnProperty("badges")) { + var types = ["badgeid", "appid", "border_color"]; + for (var n = 0; n < 6; n++) { + for (var t in type){ + if (settings[i][type]["values"]["badges"][n] != undefined) { + if (settings[i][type]["values"]["badges"][n].hasOwnProperty(types[t])){ + values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] = settings[i][type]["values"]["badges"][n][types[t]] || values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] || ""; + } } } } } } - } - break; + break; - case 'rareachievements': - values["profile_showcase[1]"] = 1; - break; + case 'rareachievements': + values["profile_showcase[1]"] = 1; + break; - case 'screenshot': - values["profile_showcase[7]"] = 7; + case 'screenshot': + values["profile_showcase[7]"] = 7; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 4; n++) { - if (settings[i][type]["values"][n] != undefined) { - values["rgShowcaseConfig[7][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]; + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[7][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]; + } } } - } - break; + break; - case 'group': - values["profile_showcase[9]"] = 9; + case 'group': + values["profile_showcase[9]"] = 9; - if (settings[i][type].hasOwnProperty("values")) { - if (typeof settings[i][type]["values"] === 'object' && settings[i][type]["values"].getSteamID64) { - values["rgShowcaseConfig[9][0][accountid]"] = settings[i][type]["values"].getSteamID64(); - } else { - values["rgShowcaseConfig[9][0][accountid]"] = new SteamID(settings[i][type]["values"]).getSteamID64(); + if (settings[i][type].hasOwnProperty("values")) { + if (typeof settings[i][type]["values"] === 'object' && settings[i][type]["values"].getSteamID64) { + values["rgShowcaseConfig[9][0][accountid]"] = settings[i][type]["values"].getSteamID64(); + } else { + values["rgShowcaseConfig[9][0][accountid]"] = new SteamID(settings[i][type]["values"]).getSteamID64(); + } } - } - break; + break; - case 'review': - values["profile_showcase[10]"] = 10; + case 'review': + values["profile_showcase[10]"] = 10; - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[10][0][appid]"] = settings[i][type]["values"]; - } - break; + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[10][0][appid]"] = settings[i][type]["values"]; + } + break; - case 'workshop': - values["profile_showcase[11]"] = 11; + case 'workshop': + values["profile_showcase[11]"] = 11; - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[11][0][appid]"] = settings[i][type]["values"]["appid"]; - values["rgShowcaseConfig[11][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; - } - break; + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[11][0][appid]"] = settings[i][type]["values"]["appid"]; + values["rgShowcaseConfig[11][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; + } + break; - case 'guide': - values["profile_showcase[15]"] = 15; + case 'guide': + values["profile_showcase[15]"] = 15; - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[15][0][appid]"] = settings[i][type]["values"]["appid"]; - values["rgShowcaseConfig[15][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; - } - break; + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[15][0][appid]"] = settings[i][type]["values"]["appid"]; + values["rgShowcaseConfig[15][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; + } + break; - case 'achievements': - values["profile_showcase[17]"] = 17; + case 'achievements': + values["profile_showcase[17]"] = 17; - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("achievements")) { - for (var n = 0; n < 7; n++) { - if (settings[i][type]["values"]["achievements"][n] != undefined) { - values["rgShowcaseConfig[17][" + n + "][appid]"] = settings[i][type]["values"]["achievements"][n]["appid"]; - values["rgShowcaseConfig[17][" + n + "][title]"] = settings[i][type]["values"]["achievements"][n]["title"]; + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("achievements")) { + for (var n = 0; n < 7; n++) { + if (settings[i][type]["values"]["achievements"][n] != undefined) { + values["rgShowcaseConfig[17][" + n + "][appid]"] = settings[i][type]["values"]["achievements"][n]["appid"]; + values["rgShowcaseConfig[17][" + n + "][title]"] = settings[i][type]["values"]["achievements"][n]["title"]; + } } } - } - break; + break; - case 'games': - values["profile_showcase[2]"] = 2; + case 'games': + values["profile_showcase[2]"] = 2; - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("games")) { - showcaseconfig.supplied = true; - showcaseconfig.numberofrequests = 4; - showcaseconfig.showcasetype = 2; - showcaseconfig.itemarray = settings[i][type]["values"]["games"]; - } - break; + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("games")) { + showcaseconfig["supplied"] = true; + showcaseconfig["numberofrequests"] = 4; + showcaseconfig["showcasetype"] = 2; + showcaseconfig["itemarray"] = settings[i][type]["values"]["games"]; + } + break; - case 'ownguides': - values["profile_showcase[16]"] = 16; + case 'ownguides': + values["profile_showcase[16]"] = 16; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 4; n++) { - if (settings[i][type]["values"][n] != undefined) { - values["rgShowcaseConfig[16][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; - values["rgShowcaseConfig[16][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[16][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; + values["rgShowcaseConfig[16][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; + } } } - } - break; - - case 'ownguides': - values["profile_showcase[12]"] = 12; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 5; n++) { - if (settings[i][type]["values"][n] != undefined) { - values["rgShowcaseConfig[12][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; - values["rgShowcaseConfig[12][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; + break; + + case 'ownguides': + values["profile_showcase[12]"] = 12; + + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 5; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[12][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; + values["rgShowcaseConfig[12][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; + } } } - } - break; - } + break; + } - if (showcaseconfig.supplied) { - for (var n = 0; n < showcaseconfig.numberofrequests; n++) { - var requestdata; - if (showcaseconfig.itemarray[n] != undefined) { - num_of_requests++; - requestdata = { - appid: showcaseconfig.itemarray[n]["appid"], - item_contextid: showcaseconfig.itemarray[n]["item_contextid"], - item_assetid: showcaseconfig.itemarray[n]["item_assetid"], - customization_type: showcaseconfig.showcasetype, - slot: n, - sessionid: values.sessionID - }; - - setTimeout(self._myProfile.bind(self, "ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - - if ((err || response.statusCode != 200) && this.showerrors) { - if (err) { - err.message += " | Happened while updating specific showcase items."; - } + if (showcaseconfig["supplied"]) { + for (var n = 0; n < showcaseconfig["numberofrequests"]; n++) { + var requestdata; + if (showcaseconfig["itemarray"][n] != undefined) { + numofrequests++; + requestdata = { + appid: showcaseconfig["itemarray"][n]["appid"], + item_contextid: showcaseconfig["itemarray"][n]["item_contextid"], + item_assetid: showcaseconfig["itemarray"][n]["item_assetid"], + customization_type: showcaseconfig["showcasetype"], + slot: n, + sessionid: values.sessionID + }; + + setTimeout(self._myProfile.bind(self, "ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + + if ((err || response.statusCode != 200) && this.showerrors) { + if (err) { + err.message += " | Happened while updating specific showcase items."; + } - if (callback && !this.error) { - callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); + if (callback && !this.error) { + callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); + } + this.error = true; + return; } - this.error = true; - return; - } - }.bind(errorcontrol)), num_of_requests * 1500); + }.bind(errorcontrol)), numofrequests * 1500); + } } } } - } break; From 1773948a545f57db7bfc6070f0b45335e1daa834 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 21:32:21 +0200 Subject: [PATCH 14/18] fixed ownworkshop --- components/profile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/profile.js b/components/profile.js index 797bb9a1..30a0473e 100644 --- a/components/profile.js +++ b/components/profile.js @@ -330,7 +330,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } break; - case 'ownguides': + case 'ownworkshop': values["profile_showcase[12]"] = 12; if (settings[i][type].hasOwnProperty("values")) { From 1073e706511ddde9f5e067d6ef577a4cd9b1f458 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Sun, 22 Jul 2018 23:34:08 +0200 Subject: [PATCH 15/18] Changed name to remainingshowcases + break the loop at that point Additional whitespace changes --- components/profile.js | 375 +++++++++++++++++++++--------------------- 1 file changed, 188 insertions(+), 187 deletions(-) diff --git a/components/profile.js b/components/profile.js index 30a0473e..a339d6c3 100644 --- a/components/profile.js +++ b/components/profile.js @@ -58,7 +58,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { values[item.name] = item.value; }); - var maxshowcases = $(".profile_showcase_selector").length; + var remainingshowcases = $(".profile_showcase_selector").length; for (var i in settings) { if (!settings.hasOwnProperty(i)) { @@ -126,255 +126,256 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { for (var type in settings[i]) { - if(maxshowcases > 0){ - - maxshowcases--; - - //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... - var showcaseconfig = { - "supplied": false, - "numberofrequests": 0, - "showcasetype": 0, - "itemarray": [] - }; - - //Controls if the callback function is called when a request changing f.e. a single item or game in a showcase fails - var errorcontrol = { - "error": false, - "showerrors": false - }; + if (remainingshowcases === 0) { + break; + } - if (settings[i][type].hasOwnProperty("values")) { - if (settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")) { - errorcontrol["showerrors"] = settings[i][type]["values"]["showshowcaseconfigerrors"]; - } + remainingshowcases--; + + //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... + var showcaseconfig = { + "supplied": false, + "numberofrequests": 0, + "showcasetype": 0, + "itemarray": [] + }; + + //Controls if the callback function is called when a request changing f.e. a single item or game in a showcase fails + var errorcontrol = { + "error": false, + "showerrors": false + }; + + if (settings[i][type].hasOwnProperty("values")) { + if (settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")) { + errorcontrol["showerrors"] = settings[i][type]["values"]["showshowcaseconfigerrors"]; } + } - switch (settings[i][type].showcase) { + switch (settings[i][type].showcase) { - case 'infobox': - values["profile_showcase[8]"] = 8; + case 'infobox': + values["profile_showcase[8]"] = 8; - if (settings[i][type].hasOwnProperty("values")){ - if (settings[i][type]["values"].hasOwnProperty("title")){ - values["rgShowcaseConfig[8][0][title]"] = settings[i][type]["values"]["title"]; - } - if (settings[i][type]["values"].hasOwnProperty("notes")) { - values["rgShowcaseConfig[8][0][notes]"] = settings[i][type]["values"]["notes"]; - } + if (settings[i][type].hasOwnProperty("values")) { + if (settings[i][type]["values"].hasOwnProperty("title")) { + values["rgShowcaseConfig[8][0][title]"] = settings[i][type]["values"]["title"]; + } + if (settings[i][type]["values"].hasOwnProperty("notes")) { + values["rgShowcaseConfig[8][0][notes]"] = settings[i][type]["values"]["notes"]; } + } - break; + break; - case 'artwork': - values["profile_showcase[13]"] = 13; + case 'artwork': + values["profile_showcase[13]"] = 13; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 4; n++) { - values["profile_showcase[13][" + n + "][publishedfileid]"] = settings[i][type]["values"][n] || ""; - } + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + values["profile_showcase[13][" + n + "][publishedfileid]"] = settings[i][type]["values"][n] || ""; } - break; - - case 'trade': - values["profile_showcase[4]"] = 4; + } + break; - if (settings[i][type].hasOwnProperty("values")) { + case 'trade': + values["profile_showcase[4]"] = 4; - if (settings[i][type]["values"].hasOwnProperty("notes")) { - values["rgShowcaseConfig[4][6][notes]"] = settings[i][type]["values"]["notes"]; - } + if (settings[i][type].hasOwnProperty("values")) { - if (settings[i][type]["values"].hasOwnProperty("items")) { - showcaseconfig["supplied"] = true; - showcaseconfig["numberofrequests"] = 6; - showcaseconfig["showcasetype"] = 4; - showcaseconfig["itemarray"] = settings[i][type]["values"]["items"]; - } + if (settings[i][type]["values"].hasOwnProperty("notes")) { + values["rgShowcaseConfig[4][6][notes]"] = settings[i][type]["values"]["notes"]; } - break; - case 'items': - values["profile_showcase[3]"] = 3; - - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("items")) { + if (settings[i][type]["values"].hasOwnProperty("items")) { showcaseconfig["supplied"] = true; - showcaseconfig["numberofrequests"] = 10; - showcaseconfig["showcasetype"] = 3; + showcaseconfig["numberofrequests"] = 6; + showcaseconfig["showcasetype"] = 4; showcaseconfig["itemarray"] = settings[i][type]["values"]["items"]; } - break; + } + break; - case 'game': - values["profile_showcase[6]"] = 6; + case 'items': + values["profile_showcase[3]"] = 3; - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[6][0][appid]"] = settings[i][type]["values"]; - } - break; + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("items")) { + showcaseconfig["supplied"] = true; + showcaseconfig["numberofrequests"] = 10; + showcaseconfig["showcasetype"] = 3; + showcaseconfig["itemarray"] = settings[i][type]["values"]["items"]; + } + break; - case 'badge': - values["profile_showcase[5]"] = 5; + case 'game': + values["profile_showcase[6]"] = 6; - if (settings[i][type].hasOwnProperty("values")) { + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[6][0][appid]"] = settings[i][type]["values"]; + } + break; - if (settings[i][type]["values"].hasOwnProperty("style")) { - var styles = ["rare", "selected", null, "recent", "random"]; - values["profile_showcase_style_5"] = styles.indexOf(settings[i][type]["values"]["style"]); - } + case 'badge': + values["profile_showcase[5]"] = 5; + + if (settings[i][type].hasOwnProperty("values")) { + + if (settings[i][type]["values"].hasOwnProperty("style")) { + var styles = ["rare", "selected", null, "recent", "random"]; + values["profile_showcase_style_5"] = styles.indexOf(settings[i][type]["values"]["style"]); + } - if (settings[i][type]["values"].hasOwnProperty("badges")) { - var types = ["badgeid", "appid", "border_color"]; - for (var n = 0; n < 6; n++) { - for (var t in type){ - if (settings[i][type]["values"]["badges"][n] != undefined) { - if (settings[i][type]["values"]["badges"][n].hasOwnProperty(types[t])){ - values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] = settings[i][type]["values"]["badges"][n][types[t]] || values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] || ""; - } + if (settings[i][type]["values"].hasOwnProperty("badges")) { + var types = ["badgeid", "appid", "border_color"]; + for (var n = 0; n < 6; n++) { + for (var t in type) { + if (settings[i][type]["values"]["badges"][n] != undefined) { + if (settings[i][type]["values"]["badges"][n].hasOwnProperty(types[t])) { + values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] = settings[i][type]["values"]["badges"][n][types[t]] || values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] || ""; } } } } } + } - break; + break; - case 'rareachievements': - values["profile_showcase[1]"] = 1; - break; + case 'rareachievements': + values["profile_showcase[1]"] = 1; + break; - case 'screenshot': - values["profile_showcase[7]"] = 7; + case 'screenshot': + values["profile_showcase[7]"] = 7; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 4; n++) { - if (settings[i][type]["values"][n] != undefined) { - values["rgShowcaseConfig[7][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]; - } + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[7][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]; } } - break; + } + break; - case 'group': - values["profile_showcase[9]"] = 9; + case 'group': + values["profile_showcase[9]"] = 9; - if (settings[i][type].hasOwnProperty("values")) { - if (typeof settings[i][type]["values"] === 'object' && settings[i][type]["values"].getSteamID64) { - values["rgShowcaseConfig[9][0][accountid]"] = settings[i][type]["values"].getSteamID64(); - } else { - values["rgShowcaseConfig[9][0][accountid]"] = new SteamID(settings[i][type]["values"]).getSteamID64(); - } + if (settings[i][type].hasOwnProperty("values")) { + if (typeof settings[i][type]["values"] === 'object' && settings[i][type]["values"].getSteamID64) { + values["rgShowcaseConfig[9][0][accountid]"] = settings[i][type]["values"].getSteamID64(); + } else { + values["rgShowcaseConfig[9][0][accountid]"] = new SteamID(settings[i][type]["values"]).getSteamID64(); } - break; + } + break; - case 'review': - values["profile_showcase[10]"] = 10; + case 'review': + values["profile_showcase[10]"] = 10; - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[10][0][appid]"] = settings[i][type]["values"]; - } - break; + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[10][0][appid]"] = settings[i][type]["values"]; + } + break; - case 'workshop': - values["profile_showcase[11]"] = 11; + case 'workshop': + values["profile_showcase[11]"] = 11; - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[11][0][appid]"] = settings[i][type]["values"]["appid"]; - values["rgShowcaseConfig[11][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; - } - break; + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[11][0][appid]"] = settings[i][type]["values"]["appid"]; + values["rgShowcaseConfig[11][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; + } + break; - case 'guide': - values["profile_showcase[15]"] = 15; + case 'guide': + values["profile_showcase[15]"] = 15; - if (settings[i][type].hasOwnProperty("values")) { - values["rgShowcaseConfig[15][0][appid]"] = settings[i][type]["values"]["appid"]; - values["rgShowcaseConfig[15][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; - } - break; + if (settings[i][type].hasOwnProperty("values")) { + values["rgShowcaseConfig[15][0][appid]"] = settings[i][type]["values"]["appid"]; + values["rgShowcaseConfig[15][0][publishedfileid]"] = settings[i][type]["values"]["publishedfileid"]; + } + break; - case 'achievements': - values["profile_showcase[17]"] = 17; + case 'achievements': + values["profile_showcase[17]"] = 17; - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("achievements")) { - for (var n = 0; n < 7; n++) { - if (settings[i][type]["values"]["achievements"][n] != undefined) { - values["rgShowcaseConfig[17][" + n + "][appid]"] = settings[i][type]["values"]["achievements"][n]["appid"]; - values["rgShowcaseConfig[17][" + n + "][title]"] = settings[i][type]["values"]["achievements"][n]["title"]; - } + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("achievements")) { + for (var n = 0; n < 7; n++) { + if (settings[i][type]["values"]["achievements"][n] != undefined) { + values["rgShowcaseConfig[17][" + n + "][appid]"] = settings[i][type]["values"]["achievements"][n]["appid"]; + values["rgShowcaseConfig[17][" + n + "][title]"] = settings[i][type]["values"]["achievements"][n]["title"]; } } - break; + } + break; - case 'games': - values["profile_showcase[2]"] = 2; + case 'games': + values["profile_showcase[2]"] = 2; - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("games")) { - showcaseconfig["supplied"] = true; - showcaseconfig["numberofrequests"] = 4; - showcaseconfig["showcasetype"] = 2; - showcaseconfig["itemarray"] = settings[i][type]["values"]["games"]; - } - break; + if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("games")) { + showcaseconfig["supplied"] = true; + showcaseconfig["numberofrequests"] = 4; + showcaseconfig["showcasetype"] = 2; + showcaseconfig["itemarray"] = settings[i][type]["values"]["games"]; + } + break; - case 'ownguides': - values["profile_showcase[16]"] = 16; + case 'ownguides': + values["profile_showcase[16]"] = 16; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 4; n++) { - if (settings[i][type]["values"][n] != undefined) { - values["rgShowcaseConfig[16][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; - values["rgShowcaseConfig[16][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; - } + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 4; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[16][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; + values["rgShowcaseConfig[16][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; } } - break; + } + break; - case 'ownworkshop': - values["profile_showcase[12]"] = 12; + case 'ownworkshop': + values["profile_showcase[12]"] = 12; - if (settings[i][type].hasOwnProperty("values")) { - for (var n = 0; n < 5; n++) { - if (settings[i][type]["values"][n] != undefined) { - values["rgShowcaseConfig[12][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; - values["rgShowcaseConfig[12][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; - } + if (settings[i][type].hasOwnProperty("values")) { + for (var n = 0; n < 5; n++) { + if (settings[i][type]["values"][n] != undefined) { + values["rgShowcaseConfig[12][" + n + "][appid]"] = settings[i][type]["values"][n]["appid"]; + values["rgShowcaseConfig[12][" + n + "][publishedfileid]"] = settings[i][type]["values"][n]["publishedfileid"]; } } - break; - } + } + break; + } - if (showcaseconfig["supplied"]) { - for (var n = 0; n < showcaseconfig["numberofrequests"]; n++) { - var requestdata; - if (showcaseconfig["itemarray"][n] != undefined) { - numofrequests++; - requestdata = { - appid: showcaseconfig["itemarray"][n]["appid"], - item_contextid: showcaseconfig["itemarray"][n]["item_contextid"], - item_assetid: showcaseconfig["itemarray"][n]["item_assetid"], - customization_type: showcaseconfig["showcasetype"], - slot: n, - sessionid: values.sessionID - }; - - setTimeout(self._myProfile.bind(self, "ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - - if ((err || response.statusCode != 200) && this.showerrors) { - if (err) { - err.message += " | Happened while updating specific showcase items."; - } + if (showcaseconfig["supplied"]) { + for (var n = 0; n < showcaseconfig["numberofrequests"]; n++) { + var requestdata; + if (showcaseconfig["itemarray"][n] != undefined) { + numofrequests++; + requestdata = { + appid: showcaseconfig["itemarray"][n]["appid"], + item_contextid: showcaseconfig["itemarray"][n]["item_contextid"], + item_assetid: showcaseconfig["itemarray"][n]["item_assetid"], + customization_type: showcaseconfig["showcasetype"], + slot: n, + sessionid: values.sessionID + }; + + setTimeout(self._myProfile.bind(self, "ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + + if ((err || response.statusCode != 200) && this.showerrors) { + if (err) { + err.message += " | Happened while updating specific showcase items."; + } - if (callback && !this.error) { - callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); - } - this.error = true; - return; + if (callback && !this.error) { + callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); } + this.error = true; + return; + } - }.bind(errorcontrol)), numofrequests * 1500); - } + }.bind(errorcontrol)), numofrequests * 1500); } } } From 0b082471c9b5bbddb7503fe344a371bcd7b9bc75 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Tue, 24 Jul 2018 21:48:13 +0200 Subject: [PATCH 16/18] Removed editing Showcases in editProfile(), added ediShowcaseItem() instead ediShowcaseItem() takes 4 parameters, the showcase, the slot, the item and a possible callback. If a callback is submitted the callback is called, if not a Promise is returned. (Promise is returned in all cases, but only resolved or rejected if there is no callback) --- components/profile.js | 112 ++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 64 deletions(-) diff --git a/components/profile.js b/components/profile.js index a339d6c3..bd075d1c 100644 --- a/components/profile.js +++ b/components/profile.js @@ -32,6 +32,54 @@ SteamCommunity.prototype.setupProfile = function(callback) { }); }; +SteamCommunity.prototype.editShowcaseItem = function(showcase, slot, item, callback) { + let self = this; + //The possible options, with the maximum number of slots and the corresponding type + let allowedoptions = { + "trade": { + "maxslots": 6, + "type": 4 + }, + "items": { + "maxslots": 10, + "type": 3 + }, + "games": { + "maxslots": 4, + "type": 2 + } + }; + + return new Promise((resolve, reject) => { + + if(!allowedoptions.hasOwnProperty(showcase)){ + let err = new Error("The submitted showcase type has no editable items."); + return callback ? callback(err) : reject(err); + } + if(slot < 1 || slot > allowedoptions[showcase]["maxslots"]){ + let err = new Error("The submitted slot is outside of range. (Allowed range: 1-"+allowedoptions[showcase]["maxslots"]+")"); + return callback ? callback(err) : reject(err); + } + if(!(item.hasOwnProperty("appid") || item.hasOwnProperty("item_contextid") || item.hasOwnProperty("item_assetid"))){ + let err = new Error("The submitted item is not valid."); + return callback ? callback(err) : reject(err); + } + let requestdata = item; + requestdata["slot"] = slot - 1; + requestdata["customization_type"] = allowedoptions[showcase]["type"]; + requestdata["sessionid"] = self.getSessionID(); + self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + + if (err || response.statusCode != 200) { + err = err || new Error("HTTP error " + response.statusCode); + return callback ? callback(err) : reject(err); + } + return callback ? callback(null) : resolve() + + }); + }); +}; + SteamCommunity.prototype.editProfile = function(settings, callback) { var self = this; this._myProfile("edit", null, function(err, response, body) { @@ -132,14 +180,6 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { remainingshowcases--; - //Variable used to easily make request to`ajaxsetshowcaseconfig` for showcases like trade, items, ... - var showcaseconfig = { - "supplied": false, - "numberofrequests": 0, - "showcasetype": 0, - "itemarray": [] - }; - //Controls if the callback function is called when a request changing f.e. a single item or game in a showcase fails var errorcontrol = { "error": false, @@ -182,29 +222,14 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { values["profile_showcase[4]"] = 4; if (settings[i][type].hasOwnProperty("values")) { - if (settings[i][type]["values"].hasOwnProperty("notes")) { values["rgShowcaseConfig[4][6][notes]"] = settings[i][type]["values"]["notes"]; } - - if (settings[i][type]["values"].hasOwnProperty("items")) { - showcaseconfig["supplied"] = true; - showcaseconfig["numberofrequests"] = 6; - showcaseconfig["showcasetype"] = 4; - showcaseconfig["itemarray"] = settings[i][type]["values"]["items"]; - } } break; case 'items': values["profile_showcase[3]"] = 3; - - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("items")) { - showcaseconfig["supplied"] = true; - showcaseconfig["numberofrequests"] = 10; - showcaseconfig["showcasetype"] = 3; - showcaseconfig["itemarray"] = settings[i][type]["values"]["items"]; - } break; case 'game': @@ -310,13 +335,6 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { case 'games': values["profile_showcase[2]"] = 2; - - if (settings[i][type].hasOwnProperty("values") && settings[i][type]["values"].hasOwnProperty("games")) { - showcaseconfig["supplied"] = true; - showcaseconfig["numberofrequests"] = 4; - showcaseconfig["showcasetype"] = 2; - showcaseconfig["itemarray"] = settings[i][type]["values"]["games"]; - } break; case 'ownguides': @@ -345,40 +363,6 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { } break; } - - if (showcaseconfig["supplied"]) { - for (var n = 0; n < showcaseconfig["numberofrequests"]; n++) { - var requestdata; - if (showcaseconfig["itemarray"][n] != undefined) { - numofrequests++; - requestdata = { - appid: showcaseconfig["itemarray"][n]["appid"], - item_contextid: showcaseconfig["itemarray"][n]["item_contextid"], - item_assetid: showcaseconfig["itemarray"][n]["item_assetid"], - customization_type: showcaseconfig["showcasetype"], - slot: n, - sessionid: values.sessionID - }; - - setTimeout(self._myProfile.bind(self, "ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - - if ((err || response.statusCode != 200) && this.showerrors) { - if (err) { - err.message += " | Happened while updating specific showcase items."; - } - - if (callback && !this.error) { - callback(err || new Error("HTTP error " + response.statusCode + " | Happened while updating specific showcase items.")); - } - this.error = true; - return; - } - - - }.bind(errorcontrol)), numofrequests * 1500); - } - } - } } break; From 5e31a54f2bd7113aa5c939ce2f2bebff8d014a9d Mon Sep 17 00:00:00 2001 From: NetroScript Date: Wed, 25 Jul 2018 14:52:13 +0200 Subject: [PATCH 17/18] Removed obsolent variables, changed editShowcaseItem to callback only Additionally fixed small mistake (`var t in type` instead of `var t in types`) --- components/profile.js | 64 ++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/components/profile.js b/components/profile.js index bd075d1c..6eb179b2 100644 --- a/components/profile.js +++ b/components/profile.js @@ -33,9 +33,9 @@ SteamCommunity.prototype.setupProfile = function(callback) { }; SteamCommunity.prototype.editShowcaseItem = function(showcase, slot, item, callback) { - let self = this; + const self = this; //The possible options, with the maximum number of slots and the corresponding type - let allowedoptions = { + const allowedoptions = { "trade": { "maxslots": 6, "type": 4 @@ -50,33 +50,30 @@ SteamCommunity.prototype.editShowcaseItem = function(showcase, slot, item, callb } }; - return new Promise((resolve, reject) => { + if(!allowedoptions.hasOwnProperty(showcase)){ + const err = new Error("The submitted showcase type has no editable items."); + return callback ? callback(err) : undefined; + } + if(slot < 1 || slot > allowedoptions[showcase]["maxslots"]){ + const err = new Error("The submitted slot is outside of range. (Allowed range: 1-"+allowedoptions[showcase]["maxslots"]+")"); + return callback ? callback(err) : undefined; + } + if(!(item.hasOwnProperty("appid") || item.hasOwnProperty("item_contextid") || item.hasOwnProperty("item_assetid"))){ + const err = new Error("The submitted item is not valid."); + return callback ? callback(err) : undefined; + } + const requestdata = item; + requestdata["slot"] = slot - 1; + requestdata["customization_type"] = allowedoptions[showcase]["type"]; + requestdata["sessionid"] = self.getSessionID(); + self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { - if(!allowedoptions.hasOwnProperty(showcase)){ - let err = new Error("The submitted showcase type has no editable items."); - return callback ? callback(err) : reject(err); - } - if(slot < 1 || slot > allowedoptions[showcase]["maxslots"]){ - let err = new Error("The submitted slot is outside of range. (Allowed range: 1-"+allowedoptions[showcase]["maxslots"]+")"); - return callback ? callback(err) : reject(err); - } - if(!(item.hasOwnProperty("appid") || item.hasOwnProperty("item_contextid") || item.hasOwnProperty("item_assetid"))){ - let err = new Error("The submitted item is not valid."); - return callback ? callback(err) : reject(err); + if (err || response.statusCode != 200) { + err = err || new Error("HTTP error " + response.statusCode); + return callback ? callback(err) : undefined; } - let requestdata = item; - requestdata["slot"] = slot - 1; - requestdata["customization_type"] = allowedoptions[showcase]["type"]; - requestdata["sessionid"] = self.getSessionID(); - self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + return callback ? callback(null) : undefined; - if (err || response.statusCode != 200) { - err = err || new Error("HTTP error " + response.statusCode); - return callback ? callback(err) : reject(err); - } - return callback ? callback(null) : resolve() - - }); }); }; @@ -162,7 +159,6 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { case 'showcases': - var numofrequests = 0; //When supplying a new showcases array, remove the old showcase (order) for (var val in values) { @@ -180,18 +176,6 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { remainingshowcases--; - //Controls if the callback function is called when a request changing f.e. a single item or game in a showcase fails - var errorcontrol = { - "error": false, - "showerrors": false - }; - - if (settings[i][type].hasOwnProperty("values")) { - if (settings[i][type]["values"].hasOwnProperty("showshowcaseconfigerrors")) { - errorcontrol["showerrors"] = settings[i][type]["values"]["showshowcaseconfigerrors"]; - } - } - switch (settings[i][type].showcase) { case 'infobox': @@ -253,7 +237,7 @@ SteamCommunity.prototype.editProfile = function(settings, callback) { if (settings[i][type]["values"].hasOwnProperty("badges")) { var types = ["badgeid", "appid", "border_color"]; for (var n = 0; n < 6; n++) { - for (var t in type) { + for (var t in types) { if (settings[i][type]["values"]["badges"][n] != undefined) { if (settings[i][type]["values"]["badges"][n].hasOwnProperty(types[t])) { values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] = settings[i][type]["values"]["badges"][n][types[t]] || values["rgShowcaseConfig[5][" + n + "][" + types[t] + "]"] || ""; From 0356f54029ea0d2b9bf32203e7e86312371b9a58 Mon Sep 17 00:00:00 2001 From: NetroScript Date: Wed, 25 Jul 2018 18:45:41 +0200 Subject: [PATCH 18/18] Removed leftover `this` from Promise, create new object instead of using reference Additionally changing spacing around `if` clauses. `Object.assign()` may not be a deep clone of the item object. But because only new properties are added directly to requestdata, the original item object is not modified. (Only if item had a property like `item.prop = {"test": true}` and you would change `requestdata.prop.test = false` the property of item would be changed too, but if you would change f.e. `requestdata.prop = "test"` the item object would be unmodified, so I would say `Object.assign()` is okay for this case). --- components/profile.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/components/profile.js b/components/profile.js index 6eb179b2..17c0cf8c 100644 --- a/components/profile.js +++ b/components/profile.js @@ -33,7 +33,6 @@ SteamCommunity.prototype.setupProfile = function(callback) { }; SteamCommunity.prototype.editShowcaseItem = function(showcase, slot, item, callback) { - const self = this; //The possible options, with the maximum number of slots and the corresponding type const allowedoptions = { "trade": { @@ -50,23 +49,23 @@ SteamCommunity.prototype.editShowcaseItem = function(showcase, slot, item, callb } }; - if(!allowedoptions.hasOwnProperty(showcase)){ + if (!allowedoptions.hasOwnProperty(showcase)) { const err = new Error("The submitted showcase type has no editable items."); return callback ? callback(err) : undefined; } - if(slot < 1 || slot > allowedoptions[showcase]["maxslots"]){ + if (slot < 1 || slot > allowedoptions[showcase]["maxslots"]) { const err = new Error("The submitted slot is outside of range. (Allowed range: 1-"+allowedoptions[showcase]["maxslots"]+")"); return callback ? callback(err) : undefined; } - if(!(item.hasOwnProperty("appid") || item.hasOwnProperty("item_contextid") || item.hasOwnProperty("item_assetid"))){ + if (!(item.hasOwnProperty("appid") || item.hasOwnProperty("item_contextid") || item.hasOwnProperty("item_assetid"))) { const err = new Error("The submitted item is not valid."); return callback ? callback(err) : undefined; } - const requestdata = item; + const requestdata = Object.assign({}, item); requestdata["slot"] = slot - 1; requestdata["customization_type"] = allowedoptions[showcase]["type"]; - requestdata["sessionid"] = self.getSessionID(); - self._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { + requestdata["sessionid"] = this.getSessionID(); + this._myProfile("ajaxsetshowcaseconfig", requestdata, function (err, response, body) { if (err || response.statusCode != 200) { err = err || new Error("HTTP error " + response.statusCode);