mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-03-24 14:10:07 +08:00
Updated help.js methods to use new http interface
This commit is contained in:
parent
e9bc778e2a
commit
96e3e7ebc0
@ -1,3 +1,7 @@
|
|||||||
|
const StdLib = require('@doctormckay/stdlib');
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const {HttpResponse} = require('@doctormckay/stdlib/http');
|
||||||
|
|
||||||
const SteamCommunity = require('../index.js');
|
const SteamCommunity = require('../index.js');
|
||||||
|
|
||||||
const HELP_SITE_DOMAIN = 'https://help.steampowered.com';
|
const HELP_SITE_DOMAIN = 'https://help.steampowered.com';
|
||||||
@ -5,18 +9,24 @@ const HELP_SITE_DOMAIN = 'https://help.steampowered.com';
|
|||||||
/**
|
/**
|
||||||
* Restore a previously removed steam package from your steam account.
|
* Restore a previously removed steam package from your steam account.
|
||||||
* @param {int|string} packageID
|
* @param {int|string} packageID
|
||||||
* @param {function} callback
|
* @param {function} [callback]
|
||||||
|
* @return Promise<void>
|
||||||
*/
|
*/
|
||||||
SteamCommunity.prototype.restorePackage = function(packageID, callback) {
|
SteamCommunity.prototype.restorePackage = function(packageID, callback) {
|
||||||
this.httpRequestPost({
|
return StdLib.Promises.callbackPromise(null, callback, true, async (resolve, reject) => {
|
||||||
uri: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRestore',
|
let result = await this.httpRequest({
|
||||||
form: {
|
method: 'POST',
|
||||||
packageid: packageID,
|
url: `${HELP_SITE_DOMAIN}/wizard/AjaxDoPackageRestore`,
|
||||||
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
form: {
|
||||||
wizard_ajax: 1
|
packageid: packageID,
|
||||||
},
|
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
||||||
json: true
|
wizard_ajax: 1
|
||||||
}, wizardAjaxHandler(callback));
|
},
|
||||||
|
source: 'steamcommunity'
|
||||||
|
});
|
||||||
|
|
||||||
|
wizardAjaxHandler(result, resolve, reject);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,38 +35,32 @@ SteamCommunity.prototype.restorePackage = function(packageID, callback) {
|
|||||||
* @param {function} callback
|
* @param {function} callback
|
||||||
*/
|
*/
|
||||||
SteamCommunity.prototype.removePackage = function(packageID, callback) {
|
SteamCommunity.prototype.removePackage = function(packageID, callback) {
|
||||||
this.httpRequestPost({
|
return StdLib.Promises.callbackPromise(null, callback, true, async (resolve, reject) => {
|
||||||
uri: HELP_SITE_DOMAIN + '/wizard/AjaxDoPackageRemove',
|
let result = await this.httpRequest({
|
||||||
form: {
|
method: 'POST',
|
||||||
packageid: packageID,
|
url: `${HELP_SITE_DOMAIN}/wizard/AjaxDoPackageRemove`,
|
||||||
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
form: {
|
||||||
wizard_ajax: 1
|
packageid: packageID,
|
||||||
},
|
sessionid: this.getSessionID(HELP_SITE_DOMAIN),
|
||||||
json: true
|
wizard_ajax: 1
|
||||||
}, wizardAjaxHandler(callback));
|
},
|
||||||
|
source: 'steamcommunity'
|
||||||
|
});
|
||||||
|
|
||||||
|
wizardAjaxHandler(result, resolve, reject);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a handler for wizard ajax HTTP requests.
|
*
|
||||||
* @param {function} callback
|
* @param {HttpResponse} result
|
||||||
* @returns {(function(*=, *, *): void)|*}
|
* @param {function} resolve
|
||||||
|
* @param {function} reject
|
||||||
*/
|
*/
|
||||||
function wizardAjaxHandler(callback) {
|
function wizardAjaxHandler(result, resolve, reject) {
|
||||||
return (err, res, body) => {
|
if (!result.jsonBody || !result.jsonBody.success) {
|
||||||
if (!callback) {
|
return reject(new Error((result.jsonBody || {}).errorMsg || 'Unexpected error'));
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (err) {
|
resolve();
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!body.success) {
|
|
||||||
callback(new Error(body.errorMsg || 'Unexpected error'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
4
index.js
4
index.js
@ -132,9 +132,9 @@ SteamCommunity.prototype.setCookies = function(cookies) {
|
|||||||
this._verifyMobileAccessToken();
|
this._verifyMobileAccessToken();
|
||||||
};
|
};
|
||||||
|
|
||||||
SteamCommunity.prototype.getSessionID = function() {
|
SteamCommunity.prototype.getSessionID = function(domain = 'steamcommunity.com') {
|
||||||
let sessionIdCookie = this._jar.cookies
|
let sessionIdCookie = this._jar.cookies
|
||||||
.filter(c => c.domain == 'steamcommunity.com')
|
.filter(c => c.domain == domain)
|
||||||
.find(c => c.name == 'sessionid');
|
.find(c => c.name == 'sessionid');
|
||||||
if (sessionIdCookie) {
|
if (sessionIdCookie) {
|
||||||
return sessionIdCookie.content;
|
return sessionIdCookie.content;
|
||||||
|
Loading…
Reference in New Issue
Block a user