From a39e77ca95fbe69255f332e92bffff36d96349c9 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Tue, 4 Jul 2023 16:53:52 +0200 Subject: [PATCH 1/5] Force english page to fix scraping details and add Posted fallback to prevent error --- classes/CSteamSharedFile.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/classes/CSteamSharedFile.js b/classes/CSteamSharedFile.js index 277dbb9..1abe0a7 100644 --- a/classes/CSteamSharedFile.js +++ b/classes/CSteamSharedFile.js @@ -31,7 +31,7 @@ SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) { }; // Get DOM of sharedfile - this.httpRequestGet(`https://steamcommunity.com/sharedfiles/filedetails/?id=${sharedFileId}`, (err, res, body) => { + this.httpRequestGet(`https://steamcommunity.com/sharedfiles/filedetails/?id=${sharedFileId}&l=english`, (err, res, body) => { // Request page in english so that the Posted scraping below works try { /* --------------------- Preprocess output --------------------- */ @@ -77,9 +77,11 @@ SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) { // Find postDate and convert to timestamp - let posted = detailsStatsObj["Posted"].trim(); + let posted = detailsStatsObj["Posted"] || null; // Set to null if "posted" could not be found as Steam translates dates and parsing it below will return a wrong result - sharedfile.postDate = Helpers.decodeSteamTime(posted); + if (posted) { + sharedfile.postDate = Helpers.decodeSteamTime(posted.trim()); // Only parse if posted is defined to avoid errors + } // Find resolution if artwork or screenshot From bdd74972ec3da65730bf8e863bbd26404b5e3502 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Wed, 26 Jul 2023 13:20:35 +0200 Subject: [PATCH 2/5] Improve sharedfile type detection --- classes/CSteamSharedFile.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/classes/CSteamSharedFile.js b/classes/CSteamSharedFile.js index 1abe0a7..5803272 100644 --- a/classes/CSteamSharedFile.js +++ b/classes/CSteamSharedFile.js @@ -120,18 +120,20 @@ SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) { // Determine type by looking at the second breadcrumb. Find the first separator as it has a unique name and go to the next element which holds our value of interest - let breadcrumb = $(".breadcrumbs > .breadcrumb_separator").next().get(0).children[0].data || ""; + let breadcrumb = $(".breadcrumbs > .breadcrumb_separator").next().get(0) || $(".breadcrumbs").get(0).children[1]; // Some artworks only have one breadcrumb like "username's Artwork" so let's check that as a backup - if (breadcrumb.includes("Screenshot")) { - sharedfile.type = ESharedFileType.Screenshot; - } + if (breadcrumb) { // If neither could be found then leave type at null + if (breadcrumb.children[0].data.includes("Screenshot")) { + sharedfile.type = ESharedFileType.Screenshot; + } - if (breadcrumb.includes("Artwork")) { - sharedfile.type = ESharedFileType.Artwork; - } + if (breadcrumb.children[0].data.includes("Artwork")) { + sharedfile.type = ESharedFileType.Artwork; + } - if (breadcrumb.includes("Guide")) { - sharedfile.type = ESharedFileType.Guide; + if (breadcrumb.children[0].data.includes("Guide")) { + sharedfile.type = ESharedFileType.Guide; + } } From c520ab1be764edfb9c26b34b79a966cb0c4e7744 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Thu, 28 Sep 2023 12:54:35 +0200 Subject: [PATCH 3/5] Fix checking for a rejected request --- components/sharedfiles.js | 72 +++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/components/sharedfiles.js b/components/sharedfiles.js index b4fa2c7..4f75f17 100644 --- a/components/sharedfiles.js +++ b/components/sharedfiles.js @@ -20,14 +20,25 @@ SteamCommunity.prototype.deleteSharedFileComment = function(userID, sharedFileId "form": { "gidcomment": cid, "count": 10, + "json": 1, "sessionid": this.getSessionID() - } + }, + "json": true }, function(err, response, body) { if (!callback) { return; } - callback(err); + if (err) { + callback(err); + return; + } + + if (body.success) { + callback(null); + } else { + callback(new Error(body.error)); + } }, "steamcommunity"); }; @@ -45,7 +56,7 @@ SteamCommunity.prototype.favoriteSharedFile = function(sharedFileId, appid, call "appid": appid, "sessionid": this.getSessionID() } - }, function(err, response, body) { + }, function(err, response, body) { // Steam does not seem to return any errors for this request if (!callback) { return; } @@ -71,14 +82,25 @@ SteamCommunity.prototype.postSharedFileComment = function(userID, sharedFileId, "form": { "comment": message, "count": 10, + "json": 1, "sessionid": this.getSessionID() - } + }, + "json": true }, function(err, response, body) { if (!callback) { return; } - callback(err); + if (err) { + callback(err); + return; + } + + if (body.success) { + callback(null); + } else { + callback(new Error(body.error)); + } }, "steamcommunity"); }; @@ -97,14 +119,28 @@ SteamCommunity.prototype.subscribeSharedFileComments = function(userID, sharedFi "uri": `https://steamcommunity.com/comment/PublishedFile_Public/subscribe/${userID.toString()}/${sharedFileId}/`, "form": { "count": 10, + "json": 1, "sessionid": this.getSessionID() - } + }, + "json": true }, function(err, response, body) { // eslint-disable-line if (!callback) { return; } - callback(err); + if (err) { + callback(err); + return; + } + + if (body.success && body.success != SteamCommunity.EResult.OK) { + let err = new Error(body.message || SteamCommunity.EResult[body.success]); + err.eresult = err.code = body.success; + callback(err); + return; + } + + callback(null); }, "steamcommunity"); }; @@ -122,7 +158,7 @@ SteamCommunity.prototype.unfavoriteSharedFile = function(sharedFileId, appid, ca "appid": appid, "sessionid": this.getSessionID() } - }, function(err, response, body) { + }, function(err, response, body) { // Steam does not seem to return any errors for this request if (!callback) { return; } @@ -146,13 +182,27 @@ SteamCommunity.prototype.unsubscribeSharedFileComments = function(userID, shared "uri": `https://steamcommunity.com/comment/PublishedFile_Public/unsubscribe/${userID.toString()}/${sharedFileId}/`, "form": { "count": 10, + "json": 1, "sessionid": this.getSessionID() - } + }, + "json": true }, function(err, response, body) { // eslint-disable-line if (!callback) { return; } - callback(err); + if (err) { + callback(err); + return; + } + + if (body.success && body.success != SteamCommunity.EResult.OK) { + let err = new Error(body.message || SteamCommunity.EResult[body.success]); + err.eresult = err.code = body.success; + callback(err); + return; + } + + callback(null); }, "steamcommunity"); -}; +}; \ No newline at end of file From 238c36db670f0b68cd0106e1d3e3561819a493a7 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:21:46 +0200 Subject: [PATCH 4/5] Use eresultError() helper --- components/sharedfiles.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/components/sharedfiles.js b/components/sharedfiles.js index 4f75f17..9e95e20 100644 --- a/components/sharedfiles.js +++ b/components/sharedfiles.js @@ -2,6 +2,8 @@ var SteamID = require('steamid'); var SteamCommunity = require('../index.js'); +const Helpers = require('./helpers.js'); + /** * Deletes a comment from a sharedfile's comment section @@ -134,9 +136,7 @@ SteamCommunity.prototype.subscribeSharedFileComments = function(userID, sharedFi } if (body.success && body.success != SteamCommunity.EResult.OK) { - let err = new Error(body.message || SteamCommunity.EResult[body.success]); - err.eresult = err.code = body.success; - callback(err); + callback(Helpers.eresultError(body.success)); return; } @@ -197,9 +197,7 @@ SteamCommunity.prototype.unsubscribeSharedFileComments = function(userID, shared } if (body.success && body.success != SteamCommunity.EResult.OK) { - let err = new Error(body.message || SteamCommunity.EResult[body.success]); - err.eresult = err.code = body.success; - callback(err); + callback(Helpers.eresultError(body.success)); return; } From dccab0aab234af6e97155ac7b0570d9b78ab9c6d Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:02:18 +0200 Subject: [PATCH 5/5] Instantly return error if sharedfile is private and cannot be accessed --- classes/CSteamSharedFile.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/classes/CSteamSharedFile.js b/classes/CSteamSharedFile.js index 5803272..1d1cbf4 100644 --- a/classes/CSteamSharedFile.js +++ b/classes/CSteamSharedFile.js @@ -32,6 +32,11 @@ SteamCommunity.prototype.getSteamSharedFile = function(sharedFileId, callback) { // Get DOM of sharedfile this.httpRequestGet(`https://steamcommunity.com/sharedfiles/filedetails/?id=${sharedFileId}&l=english`, (err, res, body) => { // Request page in english so that the Posted scraping below works + if (err) { + callback(err); + return; + } + try { /* --------------------- Preprocess output --------------------- */