diff --git a/classes/CSteamSharedFile.js b/classes/CSteamSharedFile.js index 277dbb9..1d1cbf4 100644 --- a/classes/CSteamSharedFile.js +++ b/classes/CSteamSharedFile.js @@ -31,7 +31,12 @@ 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 + if (err) { + callback(err); + return; + } + try { /* --------------------- Preprocess output --------------------- */ @@ -77,9 +82,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 @@ -118,18 +125,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; + } } diff --git a/components/sharedfiles.js b/components/sharedfiles.js index b4fa2c7..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 @@ -20,14 +22,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 +58,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 +84,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 +121,26 @@ 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) { + callback(Helpers.eresultError(body.success)); + 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,25 @@ 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) { + callback(Helpers.eresultError(body.success)); + return; + } + + callback(null); }, "steamcommunity"); -}; +}; \ No newline at end of file