mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-01-31 11:30:11 +08:00
Merge branch 'master' into v4
# Conflicts: # index.js # package.json
This commit is contained in:
commit
6b0f958cfd
@ -9,8 +9,6 @@ This module provides an easy interface for the Steam Community website. This mod
|
||||
|
||||
It supports Steam Guard and CAPTCHAs.
|
||||
|
||||
This reports anonymous usage statistics to the author. [See here](https://github.com/DoctorMcKay/node-stats-reporter) for more information.
|
||||
|
||||
**Have a question about the module or coding in general? *Do not create a GitHub issue.* GitHub issues are for feature
|
||||
requests and bug reports. Instead, post in the [dedicated forum](https://dev.doctormckay.com/forum/8-node-steamcommunity/).
|
||||
Such issues may be ignored!**
|
||||
|
@ -66,6 +66,22 @@ function CEconItem(item, description, contextID) {
|
||||
this.market_fee_app = parseInt(match[1], 10);
|
||||
}
|
||||
|
||||
// Restore cache_expiration, if we can (for CS:GO items)
|
||||
if (this.appid == 730 && this.contextid == 2 && this.owner_descriptions) {
|
||||
let description = this.owner_descriptions.find(d => d.value && d.value.indexOf('Tradable After ') == 0);
|
||||
if (description) {
|
||||
let date = new Date(description.value.substring(15).replace(/[,()]/g, ''));
|
||||
if (date) {
|
||||
this.cache_expiration = date.toISOString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have item_expiration, also set cache_expiration to the same value
|
||||
if (this.item_expiration) {
|
||||
this.cache_expiration = this.item_expiration;
|
||||
}
|
||||
|
||||
if (this.actions === "") {
|
||||
this.actions = [];
|
||||
}
|
||||
|
@ -191,3 +191,13 @@ CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableO
|
||||
CSteamUser.prototype.getProfileBackground = function(callback) {
|
||||
this._community.getUserProfileBackground(this.steamID, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Upload an image to Steam and send it to the target user over chat.
|
||||
* @param {Buffer} imageContentsBuffer - The image contents, as a Buffer
|
||||
* @param {{spoiler?: boolean}} [options]
|
||||
* @param {function} callback
|
||||
*/
|
||||
CSteamUser.prototype.sendImage = function(imageContentsBuffer, options, callback) {
|
||||
this._community.sendImageToUser(this.steamID, imageContentsBuffer, options, callback);
|
||||
};
|
||||
|
@ -1,4 +1,6 @@
|
||||
const Cheerio = require('cheerio');
|
||||
const Crypto = require('crypto');
|
||||
const imageSize = require('image-size');
|
||||
const SteamID = require('steamid');
|
||||
|
||||
const SteamCommunity = require('../index.js');
|
||||
@ -397,17 +399,22 @@ SteamCommunity.prototype.getUserInventory = function(userID, appID, contextID, t
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.getUserInventoryContents = function(userID, appID, contextID, tradableOnly, language, callback) {
|
||||
if (typeof language === 'function') {
|
||||
callback = language;
|
||||
language = "english";
|
||||
}
|
||||
|
||||
if (!userID) {
|
||||
callback(new Error("The user's SteamID is invalid or missing."));
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
if (typeof userID === 'string') {
|
||||
userID = new SteamID(userID);
|
||||
}
|
||||
|
||||
if (typeof language === 'function') {
|
||||
callback = language;
|
||||
language = "english";
|
||||
}
|
||||
|
||||
var pos = 1;
|
||||
get([], []);
|
||||
|
||||
@ -503,3 +510,156 @@ SteamCommunity.prototype.getUserInventoryContents = function(userID, appID, cont
|
||||
return quickDescriptionLookup[key];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
var imageDetails = null;
|
||||
try {
|
||||
imageDetails = imageSize(imageContentsBuffer);
|
||||
} catch (ex) {
|
||||
callback(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
var imageHash = Crypto.createHash('sha1');
|
||||
imageHash.update(imageContentsBuffer);
|
||||
imageHash = imageHash.digest('hex');
|
||||
|
||||
this.httpRequestPost({
|
||||
uri: 'https://steamcommunity.com/chat/beginfileupload/?l=english',
|
||||
headers: {
|
||||
referer: 'https://steamcommunity.com/chat/'
|
||||
},
|
||||
formData: { // it's multipart
|
||||
sessionid: this.getSessionID(),
|
||||
l: 'english',
|
||||
file_size: imageContentsBuffer.length,
|
||||
file_name: 'image.' + imageDetails.type,
|
||||
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) {
|
||||
var err2 = Helpers.eresultError(body.success);
|
||||
if (body.message) {
|
||||
err2.message = body.message;
|
||||
}
|
||||
callback(err2);
|
||||
} else {
|
||||
callback(err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (body.success != 1) {
|
||||
callback(Helpers.eresultError(body.success));
|
||||
return;
|
||||
}
|
||||
|
||||
var hmac = body.hmac;
|
||||
var timestamp = body.timestamp;
|
||||
var startResult = body.result;
|
||||
|
||||
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
|
||||
var uploadUrl = (startResult.use_https ? 'https' : 'http') + '://' + startResult.url_host + startResult.url_path;
|
||||
var headers = {};
|
||||
startResult.request_headers.forEach((header) => {
|
||||
headers[header.name.toLowerCase()] = header.value;
|
||||
});
|
||||
|
||||
this.httpRequest({
|
||||
uri: uploadUrl,
|
||||
method: 'PUT',
|
||||
headers,
|
||||
body: imageContentsBuffer
|
||||
}, (err, res, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we need to commit the upload
|
||||
this.httpRequestPost({
|
||||
uri: 'https://steamcommunity.com/chat/commitfileupload/',
|
||||
headers: {
|
||||
referer: 'https://steamcommunity.com/chat/'
|
||||
},
|
||||
formData: { // it's multipart again
|
||||
sessionid: this.getSessionID(),
|
||||
l: 'english',
|
||||
file_name: 'image.' + imageDetails.type,
|
||||
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');
|
||||
};
|
||||
|
35
index.js
35
index.js
@ -1,5 +1,3 @@
|
||||
require('@doctormckay/stats-reporter').setup(require('./package.json'));
|
||||
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const hex2b64 = require('node-bignumber').hex2b64;
|
||||
const Request = require('request');
|
||||
@ -7,6 +5,8 @@ const RSA = require('node-bignumber').Key;
|
||||
const SteamID = require('steamid');
|
||||
const Util = require('util');
|
||||
|
||||
const Helpers = require('./components/helpers.js');
|
||||
|
||||
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
|
||||
|
||||
Util.inherits(SteamCommunity, EventEmitter);
|
||||
@ -433,7 +433,7 @@ SteamCommunity.prototype.loggedIn = function(callback) {
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.getTradeURL = function(callback) {
|
||||
this._myProfile("/tradeoffers/privacy", null, (err, response, body) => {
|
||||
this._myProfile("tradeoffers/privacy", null, (err, response, body) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
@ -450,7 +450,7 @@ SteamCommunity.prototype.getTradeURL = function(callback) {
|
||||
};
|
||||
|
||||
SteamCommunity.prototype.changeTradeURL = function(callback) {
|
||||
this._myProfile("/tradeoffers/newtradeurl", {"sessionid": this.getSessionID()}, (err, response, body) => {
|
||||
this._myProfile("tradeoffers/newtradeurl", {"sessionid": this.getSessionID()}, (err, response, body) => {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
@ -465,6 +465,33 @@ SteamCommunity.prototype.changeTradeURL = function(callback) {
|
||||
}, "steamcommunity");
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear your profile name (alias) history.
|
||||
* @param {function} callback
|
||||
*/
|
||||
SteamCommunity.prototype.clearPersonaNameHistory = function(callback) {
|
||||
this._myProfile("ajaxclearaliashistory/", {"sessionid": this.getSessionID()}, (err, res, body) => {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (res.statusCode != 200) {
|
||||
return callback(new Error("HTTP error " + res.statusCode));
|
||||
}
|
||||
|
||||
try {
|
||||
body = JSON.parse(body);
|
||||
callback(Helpers.eresultError(body.success));
|
||||
} catch (ex) {
|
||||
return callback(new Error("Malformed response"));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
||||
var self = this;
|
||||
|
||||
|
@ -22,14 +22,14 @@
|
||||
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"@doctormckay/stats-reporter": "^1.0.4",
|
||||
"@doctormckay/stdlib": "^1.10.0",
|
||||
"cheerio": "^0.22.0",
|
||||
"cheerio": "0.22.0",
|
||||
"image-size": "^0.8.2",
|
||||
"node-bignumber": "^1.2.1",
|
||||
"request": "^2.88.0",
|
||||
"steam-totp": "^2.1.0",
|
||||
"steamid": "^1.1.0",
|
||||
"xml2js": "^0.4.19"
|
||||
"steamid": "^1.1.3",
|
||||
"xml2js": "^0.4.22"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
|
Loading…
Reference in New Issue
Block a user