mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2026-09-05 23:04:53 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e299623452 | ||
|
|
29b31009ce | ||
|
|
d4d0d7da26 | ||
|
|
3c8488d441 | ||
|
|
fbfff1398b | ||
|
|
6cd06c3adf | ||
|
|
d35e3c107c |
2
.idea/steamcommunity.iml
generated
2
.idea/steamcommunity.iml
generated
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="JAVA_MODULE" version="4">
|
<module type="WEB_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ module.exports = CConfirmation;
|
|||||||
function CConfirmation(community, data) {
|
function CConfirmation(community, data) {
|
||||||
Object.defineProperty(this, "_community", {"value": community});
|
Object.defineProperty(this, "_community", {"value": community});
|
||||||
|
|
||||||
this.id = data.id;
|
this.id = data.id.toString();
|
||||||
this.type = data.type;
|
this.type = data.type;
|
||||||
this.creator = data.creator;
|
this.creator = data.creator.toString();
|
||||||
this.key = data.key;
|
this.key = data.key;
|
||||||
this.title = data.title;
|
this.title = data.title;
|
||||||
this.receiving = data.receiving;
|
this.receiving = data.receiving;
|
||||||
|
|||||||
@@ -190,3 +190,13 @@ CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableO
|
|||||||
CSteamUser.prototype.getProfileBackground = function(callback) {
|
CSteamUser.prototype.getProfileBackground = function(callback) {
|
||||||
this._community.getUserProfileBackground(this.steamID, 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 Cheerio = require('cheerio');
|
||||||
|
const Crypto = require('crypto');
|
||||||
|
const imageSize = require('image-size');
|
||||||
const SteamID = require('steamid');
|
const SteamID = require('steamid');
|
||||||
|
|
||||||
const SteamCommunity = require('../index.js');
|
const SteamCommunity = require('../index.js');
|
||||||
@@ -508,3 +510,158 @@ SteamCommunity.prototype.getUserInventoryContents = function(userID, appID, cont
|
|||||||
return quickDescriptionLookup[key];
|
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');
|
||||||
|
|
||||||
|
var filename = Date.now() + '_image.' + imageDetails.type;
|
||||||
|
|
||||||
|
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: filename,
|
||||||
|
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: filename,
|
||||||
|
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');
|
||||||
|
};
|
||||||
|
|||||||
15
package.json
15
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "steamcommunity",
|
"name": "steamcommunity",
|
||||||
"version": "3.40.2",
|
"version": "3.41.0",
|
||||||
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
"description": "Provides an interface for logging into and interacting with the Steam Community website",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"steam",
|
"steam",
|
||||||
@@ -21,13 +21,14 @@
|
|||||||
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
|
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"request": "^2.86.0",
|
"async": "^2.6.3",
|
||||||
"node-bignumber": "^1.2.1",
|
|
||||||
"steamid": "^1.0.0",
|
|
||||||
"xml2js": "^0.4.11",
|
|
||||||
"cheerio": "0.22.0",
|
"cheerio": "0.22.0",
|
||||||
"async": "^2.1.4",
|
"image-size": "^0.8.2",
|
||||||
"steam-totp": "^1.3.0"
|
"node-bignumber": "^1.2.1",
|
||||||
|
"request": "^2.88.0",
|
||||||
|
"steam-totp": "^1.5.0",
|
||||||
|
"steamid": "^1.1.3",
|
||||||
|
"xml2js": "^0.4.22"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=4.0.0"
|
"node": ">=4.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user