Updated getProfileBackground output a bit

This commit is contained in:
Alex Corn 2018-07-10 23:24:41 -04:00
parent 1b3117b8dc
commit 411d74036f

View File

@ -1,7 +1,10 @@
var SteamCommunity = require('../index.js');
var SteamID = require('steamid');
var CEconItem = require('../classes/CEconItem.js');
var Helpers = require('./helpers.js');
const Cheerio = require('cheerio');
const SteamID = require('steamid');
const SteamCommunity = require('../index.js');
const CEconItem = require('../classes/CEconItem.js');
const Helpers = require('./helpers.js');
SteamCommunity.prototype.addFriend = function(userID, callback) {
if(typeof userID === 'string') {
@ -227,8 +230,7 @@ SteamCommunity.prototype.getProfileBackground = function(userID, callback) {
userID = new SteamID(userID);
}
var self = this;
this.httpRequest("http://steamcommunity.com/profiles/" + userID.getSteamID64(), function (err, response, body) {
this.httpRequest("https://steamcommunity.com/profiles/" + userID.getSteamID64(), (err, response, body) => {
if (err) {
callback(err);
return;
@ -236,17 +238,23 @@ SteamCommunity.prototype.getProfileBackground = function(userID, callback) {
var $ = Cheerio.load(body);
var $privateProfileInfo = $('.profile_private_info');
if ($privateProfileInfo.length > 0) {
callback(new Error($privateProfileInfo.text().trim()));
return;
}
if ($('body').hasClass('has_profile_background')) {
var backgroundUrl = $('div.profile_background_image_content').css('background-image');
var matcher = backgroundUrl.match(/\(([^)]+)\)/);
if (matcher.length != 2 || !matcher[1].length) {
callback(new Error("Unknown error occurred"));
callback(new Error("Malformed response"));
} else {
callback(null, matcher[1]);
}
} else {
callback("User does not have a background image");
callback(null, null);
}
}, "steamcommunity");
};