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 | |
|---|---|---|---|
|
|
6eec88d196 | ||
|
|
3921ce17d0 | ||
|
|
4441d6f6e0 | ||
|
|
870de6817e | ||
|
|
d5dbb230df | ||
|
|
5e9c06bdc4 | ||
|
|
8d163d0d85 |
@@ -1,7 +1,9 @@
|
|||||||
var SteamCommunity = require('../index.js');
|
const Cheerio = require('cheerio');
|
||||||
var SteamID = require('steamid');
|
const FS = require('fs');
|
||||||
var Cheerio = require('cheerio');
|
const SteamID = require('steamid');
|
||||||
var fs = require('fs');
|
|
||||||
|
const Helpers = require('./helpers.js');
|
||||||
|
const SteamCommunity = require('../index.js');
|
||||||
|
|
||||||
SteamCommunity.PrivacyState = {
|
SteamCommunity.PrivacyState = {
|
||||||
"Private": 1,
|
"Private": 1,
|
||||||
@@ -10,9 +12,9 @@ SteamCommunity.PrivacyState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var CommentPrivacyState = {
|
var CommentPrivacyState = {
|
||||||
"1": "commentselfonly",
|
"1": 2, // private
|
||||||
"2": "commentfriendsonly",
|
"2": 0, // friends only
|
||||||
"3": "commentanyone"
|
"3": 1 // anyone
|
||||||
};
|
};
|
||||||
|
|
||||||
SteamCommunity.prototype.setupProfile = function(callback) {
|
SteamCommunity.prototype.setupProfile = function(callback) {
|
||||||
@@ -148,10 +150,9 @@ SteamCommunity.prototype.editProfile = function(settings, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
||||||
var self = this;
|
this._myProfile("edit/settings", null, (err, response, body) => {
|
||||||
this._myProfile("edit/settings", null, function(err, response, body) {
|
if (err || response.statusCode != 200) {
|
||||||
if(err || response.statusCode != 200) {
|
if (callback) {
|
||||||
if(callback) {
|
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,8 +160,8 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var $ = Cheerio.load(body);
|
var $ = Cheerio.load(body);
|
||||||
var form = $('#editForm');
|
var existingSettings = $('.ProfileReactRoot[data-privacysettings]').data('privacysettings');
|
||||||
if(!form) {
|
if (!existingSettings) {
|
||||||
if(callback) {
|
if(callback) {
|
||||||
callback(new Error("Malformed response"));
|
callback(new Error("Malformed response"));
|
||||||
}
|
}
|
||||||
@@ -168,46 +169,71 @@ SteamCommunity.prototype.profileSettings = function(settings, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var values = {};
|
// PrivacySettings => {PrivacyProfile, PrivacyInventory, PrivacyInventoryGifts, PrivacyOwnedGames, PrivacyPlaytime}
|
||||||
form.serializeArray().forEach(function(item) {
|
// eCommentPermission
|
||||||
values[item.name] = item.value;
|
var privacy = existingSettings.PrivacySettings;
|
||||||
});
|
var commentPermission = existingSettings.eCommentPermission;
|
||||||
|
|
||||||
for(var i in settings) {
|
for (var i in settings) {
|
||||||
if(!settings.hasOwnProperty(i)) {
|
if (!settings.hasOwnProperty(i)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(i) {
|
switch (i) {
|
||||||
case 'profile':
|
case 'profile':
|
||||||
values.privacySetting = settings[i];
|
privacy.PrivacyProfile = settings[i];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'comments':
|
case 'comments':
|
||||||
values.commentSetting = CommentPrivacyState[settings[i]];
|
commentPermission = CommentPrivacyState[settings[i]];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'inventory':
|
case 'inventory':
|
||||||
values.inventoryPrivacySetting = settings[i];
|
privacy.PrivacyInventory = settings[i];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'inventoryGifts':
|
case 'inventoryGifts':
|
||||||
values.inventoryGiftPrivacy = settings[i] ? 1 : 0;
|
privacy.PrivacyInventoryGifts = settings[i] ? SteamCommunity.PrivacyState.Private : SteamCommunity.PrivacyState.Public;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'gameDetails':
|
||||||
|
privacy.PrivacyOwnedGames = settings[i];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'playtime':
|
||||||
|
privacy.PrivacyPlaytime = settings[i] ? SteamCommunity.PrivacyState.Private : SteamCommunity.PrivacyState.Public;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self._myProfile("edit/settings", values, function(err, response, body) {
|
this._myProfile({
|
||||||
if(err || response.statusCode != 200) {
|
"method": "POST",
|
||||||
if(callback) {
|
"endpoint": "ajaxsetprivacy/",
|
||||||
|
"json": true,
|
||||||
|
"formData": { // it's multipart because lolvalve
|
||||||
|
"sessionid": this.getSessionID(),
|
||||||
|
"Privacy": JSON.stringify(privacy),
|
||||||
|
"eCommentPermission": commentPermission
|
||||||
|
}
|
||||||
|
}, null, function(err, response, body) {
|
||||||
|
if (err || response.statusCode != 200) {
|
||||||
|
if (callback) {
|
||||||
callback(err || new Error("HTTP error " + response.statusCode));
|
callback(err || new Error("HTTP error " + response.statusCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(callback) {
|
if (body.success != 1) {
|
||||||
callback(null);
|
if (callback) {
|
||||||
|
callback(new Error(body.success ? "Error " + body.success : "Request was not successful"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback(null, body.Privacy);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -256,7 +282,7 @@ SteamCommunity.prototype.uploadAvatar = function(image, format, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(image, function(err, file) {
|
FS.readFile(image, function(err, file) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if(callback) {
|
if(callback) {
|
||||||
callback(err);
|
callback(err);
|
||||||
|
|||||||
12
index.js
12
index.js
@@ -1,9 +1,9 @@
|
|||||||
require('@doctormckay/stats-reporter').setup(require('./package.json'));
|
require('@doctormckay/stats-reporter').setup(require('./package.json'));
|
||||||
|
|
||||||
var Request = require('request');
|
const hex2b64 = require('node-bignumber').hex2b64;
|
||||||
var RSA = require('node-bignumber').Key;
|
const Request = require('request');
|
||||||
var hex2b64 = require('node-bignumber').hex2b64;
|
const RSA = require('node-bignumber').Key;
|
||||||
var SteamID = require('steamid');
|
const SteamID = require('steamid');
|
||||||
|
|
||||||
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
|
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36";
|
||||||
|
|
||||||
@@ -460,11 +460,13 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
|
|||||||
function completeRequest(url) {
|
function completeRequest(url) {
|
||||||
var options = endpoint.endpoint ? endpoint : {};
|
var options = endpoint.endpoint ? endpoint : {};
|
||||||
options.uri = "https://steamcommunity.com" + url + "/" + (endpoint.endpoint || endpoint);
|
options.uri = "https://steamcommunity.com" + url + "/" + (endpoint.endpoint || endpoint);
|
||||||
options.method = "GET";
|
|
||||||
|
|
||||||
if (form) {
|
if (form) {
|
||||||
options.method = "POST";
|
options.method = "POST";
|
||||||
options.form = form;
|
options.form = form;
|
||||||
|
options.followAllRedirects = true;
|
||||||
|
} else if (!options.method) {
|
||||||
|
options.method = "GET";
|
||||||
}
|
}
|
||||||
|
|
||||||
self.httpRequest(options, callback, "steamcommunity");
|
self.httpRequest(options, callback, "steamcommunity");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "steamcommunity",
|
"name": "steamcommunity",
|
||||||
"version": "3.35.2",
|
"version": "3.36.2",
|
||||||
"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",
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@doctormckay/stats-reporter": "^1.0.2",
|
"@doctormckay/stats-reporter": "^1.0.2",
|
||||||
"request": "^2.81.0",
|
"request": "^2.86.0",
|
||||||
"node-bignumber": "^1.2.1",
|
"node-bignumber": "^1.2.1",
|
||||||
"steamid": "^1.0.0",
|
"steamid": "^1.0.0",
|
||||||
"xml2js": "^0.4.11",
|
"xml2js": "^0.4.11",
|
||||||
|
|||||||
Reference in New Issue
Block a user