Use new endpoints for trade confirmations

This commit is contained in:
Alex Corn 2023-06-20 21:42:28 -04:00
parent 3531560083
commit 6e19ffd93b
No known key found for this signature in database
GPG Key ID: E51989A3E7A27FDF
2 changed files with 44 additions and 55 deletions

View File

@ -3,7 +3,7 @@ var SteamCommunity = require('../index.js');
module.exports = CConfirmation; 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.toString(); this.id = data.id.toString();
this.type = data.type; this.type = data.type;
@ -11,7 +11,9 @@ function CConfirmation(community, data) {
this.key = data.key; this.key = data.key;
this.title = data.title; this.title = data.title;
this.receiving = data.receiving; this.receiving = data.receiving;
this.sending = data.sending;
this.time = data.time; this.time = data.time;
this.timestamp = data.timestamp;
this.icon = data.icon; this.icon = data.icon;
this.offerID = this.type == SteamCommunity.ConfirmationType.Trade ? this.creator : null; this.offerID = this.type == SteamCommunity.ConfirmationType.Trade ? this.creator : null;
} }
@ -19,7 +21,7 @@ function CConfirmation(community, data) {
CConfirmation.prototype.getOfferID = function(time, key, callback) { CConfirmation.prototype.getOfferID = function(time, key, callback) {
if (this.type && this.creator) { if (this.type && this.creator) {
if (this.type != SteamCommunity.ConfirmationType.Trade) { if (this.type != SteamCommunity.ConfirmationType.Trade) {
callback(new Error("Not a trade confirmation")); callback(new Error('Not a trade confirmation'));
return; return;
} }

View File

@ -4,6 +4,7 @@ var SteamTotp = require('steam-totp');
var Async = require('async'); var Async = require('async');
var CConfirmation = require('../classes/CConfirmation.js'); var CConfirmation = require('../classes/CConfirmation.js');
var EConfirmationType = require('../resources/EConfirmationType.js');
/** /**
* Get a list of your account's currently outstanding confirmations. * Get a list of your account's currently outstanding confirmations.
@ -14,53 +15,37 @@ var CConfirmation = require('../classes/CConfirmation.js');
SteamCommunity.prototype.getConfirmations = function(time, key, callback) { SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
var self = this; var self = this;
request(this, "conf", key, time, "conf", null, false, function(err, body) { // The official Steam app uses the tag 'list', but 'conf' still works so let's use that for backward compatibility.
if(err) { request(this, 'getlist', key, time, 'conf', null, true, function(err, body) {
if (err.message == "Invalid protocol: steammobile:") { if (err) {
err.message = "Not Logged In";
self._notifySessionExpired(err);
}
callback(err); callback(err);
return; return;
} }
var $ = Cheerio.load(body); if (!body.success) {
var empty = $('#mobileconf_empty'); if (body.needauth) {
if(empty.length > 0) { var err = new Error('Not Logged In');
if(!$(empty).hasClass('mobileconf_done')) { self._notifySessionExpired(err);
// An error occurred callback(err);
callback(new Error(empty.find('div:nth-of-type(2)').text())); return;
} else {
callback(null, []);
} }
callback(new Error('Failed to get confirmation list'));
return; return;
} }
// We have something to confirm var confs = (body.conf || []).map(conf => new CConfirmation(self, {
var confirmations = $('#mobileconf_list'); id: conf.id,
if(!confirmations) { type: conf.type,
callback(new Error("Malformed response")); creator: conf.creator_id,
return; key: conf.nonce,
} title: `${conf.type_name || 'Confirm'} - ${conf.headline || ''}`,
receiving: conf.type == EConfirmationType.Trade ? ((conf.summary || [])[1] || '') : '',
var confs = []; sending: (conf.summary || [])[0] || '',
Array.prototype.forEach.call(confirmations.find('.mobileconf_list_entry'), function(conf) { time: (new Date(conf.creation_time * 1000)).toISOString(), // for backward compatibility
conf = $(conf); timestamp: conf.creation_time,
icon: conf.icon || ''
var img = conf.find('.mobileconf_list_entry_icon img'); }));
confs.push(new CConfirmation(self, {
"id": conf.data('confid'),
"type": conf.data('type'),
"creator": conf.data('creator'),
"key": conf.data('key'),
"title": conf.find('.mobileconf_list_entry_description>div:nth-of-type(1)').text().trim(),
"receiving": conf.find('.mobileconf_list_entry_description>div:nth-of-type(2)').text().trim(),
"time": conf.find('.mobileconf_list_entry_description>div:nth-of-type(3)').text().trim(),
"icon": img.length < 1 ? '' : $(img).attr('src')
}));
});
callback(null, confs); callback(null, confs);
}); });
@ -76,22 +61,23 @@ SteamCommunity.prototype.getConfirmations = function(time, key, callback) {
* Get the trade offer ID associated with a particular confirmation * Get the trade offer ID associated with a particular confirmation
* @param {int} confID - The ID of the confirmation in question * @param {int} confID - The ID of the confirmation in question
* @param {int} time - The unix timestamp with which the following key was generated * @param {int} time - The unix timestamp with which the following key was generated
* @param {string} key - The confirmation key that was generated using the preceeding time and the tag "details" (this key can be reused) * @param {string} key - The confirmation key that was generated using the preceeding time and the tag "detail" (this key can be reused)
* @param {SteamCommunity~getConfirmationOfferID} callback * @param {SteamCommunity~getConfirmationOfferID} callback
*/ */
SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, callback) { SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, callback) {
request(this, "details/" + confID, key, time, "details", null, true, function(err, body) { // The official Steam app uses the tag 'detail', but 'details' still works so let's use that for backward compatibility
if(err) { request(this, 'detailspage/' + confID, key, time, 'details', null, false, function(err, body) {
if (err) {
callback(err); callback(err);
return; return;
} }
if(!body.success) { if (typeof body != 'string') {
callback(new Error("Cannot load confirmation details")); callback(new Error("Cannot load confirmation details"));
return; return;
} }
var $ = Cheerio.load(body.html); var $ = Cheerio.load(body);
var offer = $('.tradeoffer'); var offer = $('.tradeoffer');
if(offer.length < 1) { if(offer.length < 1) {
callback(null, null); callback(null, null);
@ -118,31 +104,32 @@ SteamCommunity.prototype.getConfirmationOfferID = function(confID, time, key, ca
* @param {SteamCommunity~genericErrorCallback} callback - Called when the request is complete * @param {SteamCommunity~genericErrorCallback} callback - Called when the request is complete
*/ */
SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time, key, accept, callback) { SteamCommunity.prototype.respondToConfirmation = function(confID, confKey, time, key, accept, callback) {
request(this, (confID instanceof Array) ? "multiajaxop" : "ajaxop", key, time, accept ? "allow" : "cancel", { // The official app uses tags reject/accept, but cancel/allow still works so use these for backward compatibility
"op": accept ? "allow" : "cancel", request(this, (confID instanceof Array) ? 'multiajaxop' : 'ajaxop', key, time, accept ? 'allow' : 'cancel', {
"cid": confID, op: accept ? 'allow' : 'cancel',
"ck": confKey cid: confID,
ck: confKey
}, true, function(err, body) { }, true, function(err, body) {
if(!callback) { if (!callback) {
return; return;
} }
if(err) { if (err) {
callback(err); callback(err);
return; return;
} }
if(body.success) { if (body.success) {
callback(null); callback(null);
return; return;
} }
if(body.message) { if (body.message) {
callback(new Error(body.message)); callback(new Error(body.message));
return; return;
} }
callback(new Error("Could not act on confirmation")); callback(new Error('Could not act on confirmation'));
}); });
}; };
@ -252,7 +239,7 @@ function request(community, url, key, time, tag, params, json, callback) {
params.a = community.steamID.getSteamID64(); params.a = community.steamID.getSteamID64();
params.k = key; params.k = key;
params.t = time; params.t = time;
params.m = "android"; params.m = "react";
params.tag = tag; params.tag = tag;
var req = { var req = {