node-steamcommunity/components/users.js

750 lines
19 KiB
JavaScript
Raw Permalink Normal View History

const Cheerio = require('cheerio');
2019-09-24 16:06:37 +08:00
const Crypto = require('crypto');
const imageSize = require('image-size');
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) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: 'https://steamcommunity.com/actions/AddFriendAjax',
2021-07-22 16:42:48 +08:00
form: {
accept_invite: 0,
sessionID: this.getSessionID(),
steamid: userID.toString()
},
2021-07-22 16:42:48 +08:00
json: true
}, (err, response, body) => {
if (!callback) {
return;
}
if (err) {
2021-07-22 16:42:48 +08:00
return callback(err);
}
2021-07-22 16:42:48 +08:00
if (body.success) {
callback(null);
} else {
2021-07-22 16:42:48 +08:00
callback(new Error('Unknown error'));
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: 'https://steamcommunity.com/actions/AddFriendAjax',
2021-07-22 16:42:48 +08:00
form: {
accept_invite: 1,
sessionID: this.getSessionID(),
steamid: userID.toString()
}
}, (err, response, body) => {
if (!callback) {
return;
}
callback(err || null);
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
SteamCommunity.prototype.removeFriend = function(userID, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: 'https://steamcommunity.com/actions/RemoveFriendAjax',
2021-07-22 16:42:48 +08:00
form: {
sessionID: this.getSessionID(),
steamid: userID.toString()
}
2021-07-22 16:42:48 +08:00
}, (err, response, body) => {
if (!callback) {
return;
}
callback(err || null);
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
SteamCommunity.prototype.blockCommunication = function(userID, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: 'https://steamcommunity.com/actions/BlockUserAjax',
2021-07-22 16:42:48 +08:00
form: {
sessionID: this.getSessionID(),
steamid: userID.toString()
}
2021-07-22 16:42:48 +08:00
}, (err, response, body) => {
if (!callback) {
return;
}
callback(err || null);
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
SteamCommunity.prototype.unblockCommunication = function(userID, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
2021-07-22 16:42:48 +08:00
let form = {action: 'unignore'};
form['friends[' + userID.toString() + ']'] = 1;
2021-07-22 16:42:48 +08:00
this._myProfile('friends/blocked/', form, (err, response, body) => {
if (!callback) {
return;
}
2021-07-22 16:42:48 +08:00
if (err || response.statusCode >= 400) {
callback(err || new Error(`HTTP error ${response.statusCode}`));
return;
}
callback(null);
});
};
SteamCommunity.prototype.postUserComment = function(userID, message, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: `https://steamcommunity.com/comment/Profile/post/${userID.toString()}/-1`,
2021-07-22 16:42:48 +08:00
form: {
comment: message,
count: 1,
sessionid: this.getSessionID()
},
2021-07-22 16:42:48 +08:00
json: true
}, (err, response, body) => {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
2021-07-22 16:42:48 +08:00
if (body.success) {
const $ = Cheerio.load(body.comments_html);
const commentID = $('.commentthread_comment').attr('id').split('_')[1];
callback(null, commentID);
2021-07-22 16:42:48 +08:00
} else if (body.error) {
callback(new Error(body.error));
} else {
2021-07-22 16:42:48 +08:00
callback(new Error('Unknown error'));
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
SteamCommunity.prototype.deleteUserComment = function(userID, commentID, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: `https://steamcommunity.com/comment/Profile/delete/${userID.toString()}/-1`,
2021-07-22 16:42:48 +08:00
form: {
gidcomment: commentID,
start: 0,
count: 1,
sessionid: this.getSessionID(),
feature2: -1
},
2021-07-22 16:42:48 +08:00
json: true
}, (err, response, body) => {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
2021-07-22 16:42:48 +08:00
if (body.success && !body.comments_html.includes(commentID)) {
callback(null);
2021-07-22 16:42:48 +08:00
} else if (body.error) {
callback(new Error(body.error));
2021-07-22 16:42:48 +08:00
} else if (body.comments_html.includes(commentID)) {
callback(new Error('Failed to delete comment'));
} else {
2021-07-22 16:42:48 +08:00
callback(new Error('Unknown error'));
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
SteamCommunity.prototype.getUserComments = function(userID, options, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
if (typeof options === 'function') {
callback = options;
options = {};
}
2021-07-22 16:42:48 +08:00
let form = Object.assign({
start: 0,
count: 0,
feature2: -1,
sessionid: this.getSessionID()
2021-07-22 13:48:46 +08:00
}, options);
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: `https://steamcommunity.com/comment/Profile/render/${userID.toString()}/-1`,
2021-07-22 16:42:48 +08:00
form,
json: true
}, (err, response, body) => {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
2021-07-22 16:42:48 +08:00
if (body.success) {
const $ = Cheerio.load(body.comments_html);
2021-07-22 16:42:48 +08:00
const comments = $('.commentthread_comment.responsive_body_text[id]').map((i, elem) => {
let $elem = $(elem),
$commentContent = $elem.find('.commentthread_comment_text');
return {
2021-07-22 16:42:48 +08:00
id: $elem.attr('id').split('_')[1],
author: {
2021-07-22 16:42:48 +08:00
steamID: new SteamID('[U:1:' + $elem.find('[data-miniprofile]').data('miniprofile') + ']'),
name: $elem.find('bdi').text(),
avatar: $elem.find('.playerAvatar img[src]').attr('src'),
state: $elem.find('.playerAvatar').attr('class').split(' ').pop()
},
2021-07-22 16:42:48 +08:00
date: new Date($elem.find('.commentthread_comment_timestamp').data('timestamp') * 1000),
2021-07-22 15:25:47 +08:00
text: $commentContent.text().trim(),
html: $commentContent.html().trim()
2021-07-29 14:55:56 +08:00
};
}).get();
callback(null, comments, body.total_count);
2021-07-22 16:42:48 +08:00
} else if (body.error) {
callback(new Error(body.error));
} else {
2021-07-22 16:42:48 +08:00
callback(new Error('Unknown error'));
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
SteamCommunity.prototype.inviteUserToGroup = function(userID, groupID, callback) {
2021-07-22 16:42:48 +08:00
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: 'https://steamcommunity.com/actions/GroupInvite',
2021-07-22 16:42:48 +08:00
form: {
group: groupID.toString(),
invitee: userID.toString(),
json: 1,
sessionID: this.getSessionID(),
type: 'groupInvite'
},
2021-07-22 16:42:48 +08:00
json: true
}, (err, response, body) => {
if (!callback) {
return;
}
if (err) {
callback(err);
return;
}
2021-07-22 16:42:48 +08:00
if (body.results == 'OK') {
callback(null);
2021-07-22 16:42:48 +08:00
} else if (body.results) {
callback(new Error(body.results));
} else {
2021-07-22 16:42:48 +08:00
callback(new Error('Unknown error'));
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
2015-09-07 11:22:10 +08:00
2016-07-07 07:20:42 +08:00
SteamCommunity.prototype.getUserAliases = function(userID, callback) {
if (typeof userID === 'string') {
2016-07-07 07:20:42 +08:00
userID = new SteamID(userID);
}
this.httpRequestGet({
2023-06-27 16:31:25 +08:00
url: `https://steamcommunity.com/profiles/${userID.getSteamID64()}/ajaxaliases`,
2021-07-22 16:42:48 +08:00
json: true
}, (err, response, body) => {
2016-07-07 07:20:42 +08:00
if (err) {
callback(err);
return;
}
if (typeof body !== 'object') {
2021-07-22 16:42:48 +08:00
callback(new Error('Malformed response'));
2016-07-07 07:20:42 +08:00
return;
}
2021-07-22 16:42:48 +08:00
callback(null, body.map((entry) => {
entry.timechanged = Helpers.decodeSteamTime(entry.timechanged);
return entry;
}));
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
2016-07-07 07:20:42 +08:00
};
/**
* Get the background URL of user's profile.
* @param {SteamID|string} userID - The user's SteamID as a SteamID object or a string which can parse into one
* @param {function} callback
*/
SteamCommunity.prototype.getUserProfileBackground = function(userID, callback) {
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
2021-07-22 16:42:48 +08:00
this.httpRequest(`https://steamcommunity.com/profiles/${userID.getSteamID64()}`, (err, response, body) => {
if (err) {
callback(err);
return;
}
2021-07-22 16:42:48 +08:00
let $ = Cheerio.load(body);
2021-07-22 16:42:48 +08:00
let $privateProfileInfo = $('.profile_private_info');
if ($privateProfileInfo.length > 0) {
callback(new Error($privateProfileInfo.text().trim()));
return;
}
if ($('body').hasClass('has_profile_background')) {
2021-07-22 16:42:48 +08:00
let backgroundUrl = $('div.profile_background_image_content').css('background-image');
let matcher = backgroundUrl.match(/\(([^)]+)\)/);
if (matcher.length != 2 || !matcher[1].length) {
2021-07-22 16:42:48 +08:00
callback(new Error('Malformed response'));
} else {
callback(null, matcher[1]);
}
} else {
callback(null, null);
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
2015-09-07 11:22:10 +08:00
SteamCommunity.prototype.getUserInventoryContexts = function(userID, callback) {
if (typeof userID === 'string') {
2015-09-07 11:22:10 +08:00
userID = new SteamID(userID);
}
if (typeof userID === 'function') {
2015-09-07 11:22:10 +08:00
callback = userID;
userID = this.steamID;
}
if (!userID) {
2021-07-22 16:42:48 +08:00
callback(new Error('No SteamID specified and not logged in'));
2015-09-07 11:22:10 +08:00
return;
}
2021-07-22 16:42:48 +08:00
this.httpRequest(`https://steamcommunity.com/profiles/${userID.getSteamID64()}/inventory/`, (err, response, body) => {
if (err) {
callback(err);
2015-09-07 11:22:10 +08:00
return;
}
2021-07-22 16:42:48 +08:00
let match = body.match(/var g_rgAppContextData = ([^\n]+);\r?\n/);
if (!match) {
callback(new Error('Malformed response'));
2015-09-07 11:22:10 +08:00
return;
}
2021-07-22 16:42:48 +08:00
let data;
2015-09-07 11:22:10 +08:00
try {
data = JSON.parse(match[1]);
2021-07-29 15:15:47 +08:00
} catch (e) {
2021-07-22 16:42:48 +08:00
callback(new Error('Malformed response'));
2015-09-07 11:22:10 +08:00
return;
}
if (Object.keys(data).length == 0) {
if (body.match(/inventory is currently private\./)) {
callback(new Error('Private inventory'));
return;
}
if (body.match(/profile_private_info/)) {
callback(new Error('Private profile'));
return;
}
// If they truly have no items in their inventory, Steam will send g_rgAppContextData as [] instead of {}.
data = {};
}
2015-09-07 11:22:10 +08:00
callback(null, data);
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
2015-09-07 11:22:10 +08:00
};
2015-09-07 12:00:19 +08:00
/**
* Get the contents of a user's inventory context.
* @deprecated Use getUserInventoryContents instead
* @param {SteamID|string} userID - The user's SteamID as a SteamID object or a string which can parse into one
* @param {int} appID - The Steam application ID of the game for which you want an inventory
* @param {int} contextID - The ID of the "context" within the game you want to retrieve
* @param {boolean} tradableOnly - true to get only tradable items and currencies
* @param {function} callback
*/
2015-09-07 12:00:19 +08:00
SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, tradableOnly, callback) {
if (typeof userID === 'string') {
userID = new SteamID(userID);
}
2021-07-22 16:42:48 +08:00
const get = (inventory, currency, start) => {
this.httpRequest({
2023-06-27 16:31:25 +08:00
url: `https://steamcommunity.com${endpoint}/inventory/json/${appID}/${contextID}`,
2021-07-22 16:42:48 +08:00
headers: {
Referer: `https://steamcommunity.com${endpoint}/inventory`
},
2021-07-22 16:42:48 +08:00
qs: {
start: start,
trading: tradableOnly ? 1 : undefined
},
2021-07-22 16:42:48 +08:00
json: true
}, (err, response, body) => {
if (err) {
callback(err);
return;
}
if (!body || !body.success || !body.rgInventory || !body.rgDescriptions || !body.rgCurrency) {
if (body) {
2021-07-22 16:42:48 +08:00
callback(new Error(body.Error || 'Malformed response'));
} else {
2021-07-22 16:42:48 +08:00
callback(new Error('Malformed response'));
}
return;
}
2021-07-29 14:55:56 +08:00
for (let i in body.rgInventory) {
inventory.push(new CEconItem(body.rgInventory[i], body.rgDescriptions, contextID));
}
2021-07-29 14:55:56 +08:00
for (let i in body.rgCurrency) {
2022-11-04 23:48:35 +08:00
currency.push(new CEconItem(body.rgCurrency[i], body.rgDescriptions, contextID));
}
if (body.more) {
2021-07-29 14:55:56 +08:00
let match = response.request.uri.href.match(/\/(profiles|id)\/([^/]+)\//);
2021-07-22 16:42:48 +08:00
if (match) {
endpoint = `/${match[1]}/${match[2]}`;
}
get(inventory, currency, body.more_start);
} else {
callback(null, inventory, currency);
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
let endpoint = `/profiles/${userID.getSteamID64()}`;
get([], []);
};
/**
* Get the contents of a user's inventory context.
* @param {SteamID|string} userID - The user's SteamID as a SteamID object or a string which can parse into one
* @param {int} appID - The Steam application ID of the game for which you want an inventory
* @param {int} contextID - The ID of the "context" within the game you want to retrieve
* @param {boolean} tradableOnly - true to get only tradable items and currencies
* @param {string} [language] - The language of item descriptions to return. Omit for default (which may either be English or your account's chosen language)
* @param {function} callback
*/
SteamCommunity.prototype.getUserInventoryContents = function(userID, appID, contextID, tradableOnly, language, callback) {
if (typeof language === 'function') {
callback = language;
2021-07-22 16:42:48 +08:00
language = 'english';
}
if (!userID) {
2021-07-22 16:42:48 +08:00
callback(new Error('The user\'s SteamID is invalid or missing.'));
return;
}
if (typeof userID === 'string') {
2015-09-07 12:00:19 +08:00
userID = new SteamID(userID);
}
2021-07-22 16:42:48 +08:00
// A bit of optimization; objects are hash tables so it's more efficient to look up by key than to iterate an array
let quickDescriptionLookup = {};
const getDescription = (descriptions, classID, instanceID) => {
let key = classID + '_' + (instanceID || '0'); // instanceID can be undefined, in which case it's 0.
if (quickDescriptionLookup[key]) {
return quickDescriptionLookup[key];
}
2015-09-07 12:00:19 +08:00
2021-07-22 16:42:48 +08:00
for (let i = 0; i < descriptions.length; i++) {
quickDescriptionLookup[descriptions[i].classid + '_' + (descriptions[i].instanceid || '0')] = descriptions[i];
}
return quickDescriptionLookup[key];
};
const get = (inventory, currency, start) => {
this.httpRequest({
2023-06-27 16:31:25 +08:00
url: `https://steamcommunity.com/inventory/${userID.getSteamID64()}/${appID}/${contextID}`,
2021-07-22 16:42:48 +08:00
headers: {
Referer: `https://steamcommunity.com/profiles/${userID.getSteamID64()}/inventory`
2016-12-13 13:50:29 +08:00
},
2021-07-22 16:42:48 +08:00
qs: {
l: language, // Default language
count: 2000, // Max items per 'page'
2021-07-22 16:42:48 +08:00
start_assetid: start
2015-09-07 12:00:19 +08:00
},
2021-07-22 16:42:48 +08:00
json: true
}, (err, response, body) => {
if (err) {
2021-07-22 16:42:48 +08:00
if (err.message == 'HTTP error 403' && body === null) {
// 403 with a body of "null" means the inventory/profile is private.
2021-07-22 16:42:48 +08:00
if (this.steamID && userID.getSteamID64() == this.steamID.getSteamID64()) {
// We can never get private profile error for our own inventory!
2021-07-22 16:42:48 +08:00
this._notifySessionExpired(err);
}
2021-07-22 16:42:48 +08:00
callback(new Error('This profile is private.'));
return;
}
2021-07-22 16:42:48 +08:00
if (err.message == 'HTTP error 500' && body && body.error) {
err = new Error(body.error);
2021-07-22 16:42:48 +08:00
let match = body.error.match(/^(.+) \((\d+)\)$/);
if (match) {
err.message = match[1];
err.eresult = match[2];
callback(err);
return;
}
}
callback(err);
2015-09-07 12:00:19 +08:00
return;
}
if (body && body.success && body.total_inventory_count === 0) {
// Empty inventory
callback(null, [], [], 0);
return;
}
if (!body || !body.success || !body.assets || !body.descriptions) {
if (body) {
// Dunno if the error/Error property even exists on this new endpoint
2021-07-22 16:42:48 +08:00
callback(new Error(body.error || body.Error || 'Malformed response'));
} else {
2021-07-22 16:42:48 +08:00
callback(new Error('Malformed response'));
}
2015-09-07 12:00:19 +08:00
return;
}
2021-07-22 16:42:48 +08:00
for (let i = 0; i < body.assets.length; i++) {
let description = getDescription(body.descriptions, body.assets[i].classid, body.assets[i].instanceid);
if (!tradableOnly || (description && description.tradable)) {
body.assets[i].pos = pos++;
(body.assets[i].currencyid ? currency : inventory).push(new CEconItem(body.assets[i], description, contextID));
2015-09-07 12:00:19 +08:00
}
}
if (body.more_items) {
get(inventory, currency, body.last_assetid);
2015-09-07 12:00:19 +08:00
} else {
callback(null, inventory, currency, body.total_inventory_count);
2015-09-07 12:00:19 +08:00
}
2021-07-22 16:42:48 +08:00
}, 'steamcommunity');
};
2021-07-22 16:42:48 +08:00
let pos = 1;
get([], []);
};
2019-09-24 16:06:37 +08:00
/**
* Upload an image to Steam and send it to another user over Steam chat.
* @param {SteamID|string} userID - Either a SteamID object or a string that can parse into one
* @param {Buffer} imageContentsBuffer - The image contents, as a Buffer
* @param {{spoiler?: boolean}} [options]
* @param {function} callback
*/
SteamCommunity.prototype.sendImageToUser = function(userID, imageContentsBuffer, options, callback) {
if (typeof options == 'function') {
callback = options;
options = {};
}
options = options || {};
if (!userID) {
callback(new Error('The user\'s SteamID is invalid or missing'));
return;
}
if (typeof userID == 'string') {
userID = new SteamID(userID);
}
if (!Buffer.isBuffer(imageContentsBuffer)) {
callback(new Error('The image contents must be a Buffer containing an image'));
return;
}
2021-07-22 16:42:48 +08:00
let imageDetails = null;
2019-09-24 16:06:37 +08:00
try {
imageDetails = imageSize(imageContentsBuffer);
} catch (ex) {
callback(ex);
return;
}
2021-07-22 16:42:48 +08:00
let imageHash = Crypto.createHash('sha1');
2019-09-24 16:06:37 +08:00
imageHash.update(imageContentsBuffer);
imageHash = imageHash.digest('hex');
2021-07-22 16:42:48 +08:00
let filename = Date.now() + '_image.' + imageDetails.type;
2019-09-24 16:06:37 +08:00
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: 'https://steamcommunity.com/chat/beginfileupload/?l=english',
2019-09-24 16:06:37 +08:00
headers: {
referer: 'https://steamcommunity.com/chat/'
},
formData: { // it's multipart
sessionid: this.getSessionID(),
l: 'english',
file_size: imageContentsBuffer.length,
file_name: filename,
2019-09-24 16:06:37 +08:00
file_sha: imageHash,
file_image_width: imageDetails.width,
file_image_height: imageDetails.height,
file_type: 'image/' + (imageDetails.type == 'jpg' ? 'jpeg' : imageDetails.type)
},
json: true
}, (err, res, body) => {
if (err) {
if (body && body.success) {
2021-07-22 16:42:48 +08:00
let err2 = Helpers.eresultError(body.success);
2019-09-24 16:06:37 +08:00
if (body.message) {
err2.message = body.message;
}
callback(err2);
} else {
callback(err);
}
return;
}
if (body.success != 1) {
callback(Helpers.eresultError(body.success));
return;
}
2021-07-22 16:42:48 +08:00
let hmac = body.hmac;
let timestamp = body.timestamp;
let startResult = body.result;
2019-09-24 16:06:37 +08:00
if (!startResult || !startResult.ugcid || !startResult.url_host || !startResult.request_headers) {
callback(new Error('Malformed response'));
return;
}
// Okay, now we need to PUT the file to the provided URL
2021-07-22 16:42:48 +08:00
let uploadUrl = (startResult.use_https ? 'https' : 'http') + '://' + startResult.url_host + startResult.url_path;
let headers = {};
2019-09-24 16:06:37 +08:00
startResult.request_headers.forEach((header) => {
headers[header.name.toLowerCase()] = header.value;
});
this.httpRequest({
2023-06-27 16:31:25 +08:00
url: uploadUrl,
2019-09-24 16:06:37 +08:00
method: 'PUT',
headers,
body: imageContentsBuffer
}, (err, res, body) => {
if (err) {
callback(err);
return;
}
// Now we need to commit the upload
this.httpRequestPost({
2023-06-27 16:31:25 +08:00
url: 'https://steamcommunity.com/chat/commitfileupload/',
2019-09-24 16:06:37 +08:00
headers: {
referer: 'https://steamcommunity.com/chat/'
},
formData: { // it's multipart again
sessionid: this.getSessionID(),
l: 'english',
file_name: filename,
2019-09-24 16:06:37 +08:00
file_sha: imageHash,
success: '1',
ugcid: startResult.ugcid,
file_type: 'image/' + (imageDetails.type == 'jpg' ? 'jpeg' : imageDetails.type),
file_image_width: imageDetails.width,
file_image_height: imageDetails.height,
timestamp,
hmac,
friend_steamid: userID.getSteamID64(),
spoiler: options.spoiler ? '1' : '0'
},
json: true
}, (err, res, body) => {
if (err) {
callback(err);
return;
}
if (body.success != 1) {
callback(Helpers.eresultError(body.success));
return;
}
if (body.result.success != 1) {
// lol valve
callback(Helpers.eresultError(body.result.success));
return;
}
if (!body.result.details || !body.result.details.url) {
callback(new Error('Malformed response'));
return;
}
callback(null, body.result.details.url);
}, 'steamcommunity');
}, 'steamcommunity');
}, 'steamcommunity');
};