steamutils 1.5.24 → 1.5.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +102 -94
- package/package.json +2 -1
- package/utils.js +36 -6
package/index.js
CHANGED
@@ -7,7 +7,7 @@ import SteamID from "steamid";
|
|
7
7
|
import URL from "url";
|
8
8
|
import Url from "url-parse";
|
9
9
|
import qs from "qs";
|
10
|
-
import { console_log, downloadImage, getCleanObject, getImageSize, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
10
|
+
import { console_log, downloadImage, formatMarketHistoryDate, getCleanObject, getImageSize, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
11
11
|
import { Header, request } from "./axios.js";
|
12
12
|
import { getTableHasHeaders, querySelectorAll, table2json } from "./cheerio.js";
|
13
13
|
import { getJSObjectFronXML } from "./xml2json.js";
|
@@ -6261,110 +6261,118 @@ export default class SteamUser {
|
|
6261
6261
|
const result = await this._httpRequestAjax({
|
6262
6262
|
url: `market/mylistings/render/?count=100`,
|
6263
6263
|
});
|
6264
|
+
|
6264
6265
|
if (result instanceof ResponseError) {
|
6265
6266
|
return result;
|
6266
6267
|
}
|
6268
|
+
|
6267
6269
|
const data = result?.data;
|
6268
|
-
if (data?.success
|
6269
|
-
|
6270
|
-
const list = [];
|
6271
|
-
$(".market_listing_row").each(function () {
|
6272
|
-
try {
|
6273
|
-
const $1 = $(this);
|
6274
|
-
const [sElementPrefix, listingid, appid, contextid, itemid] = $1
|
6275
|
-
.find(".market_listing_cancel_button > a")
|
6276
|
-
.attr("href")
|
6277
|
-
.split("(")[1]
|
6278
|
-
.split(")")[0]
|
6279
|
-
.split(",")
|
6280
|
-
.map((r) => r.trim().replaceAll(`'`, "").replaceAll(`"`, ""));
|
6281
|
-
const image = $1.find(`#mylisting_${listingid}_image`).attr("src");
|
6282
|
-
const buyer_pays_price = StringUtils.cleanSpace($1.find(`.market_listing_price span[title="This is the price the buyer pays."]`).text().replaceAll(`(`, "").replaceAll(`)`, ""));
|
6283
|
-
const receive_price = StringUtils.cleanSpace($1.find(`.market_listing_price span[title="This is how much you will receive."]`).text().replaceAll(`(`, "").replaceAll(`)`, ""));
|
6284
|
-
const item_name = $1.find(".market_listing_item_name_link").text() || $1.find(".market_listing_item_name").text();
|
6285
|
-
const game_name = $1.find(".market_listing_game_name").text();
|
6286
|
-
const date_combined = StringUtils.cleanSpace($1.find(".market_listing_game_name + .market_listing_listed_date_combined").text());
|
6287
|
-
list.push({
|
6288
|
-
listingid,
|
6289
|
-
appid,
|
6290
|
-
contextid,
|
6291
|
-
itemid,
|
6292
|
-
buyer_pays_price,
|
6293
|
-
receive_price,
|
6294
|
-
item_name,
|
6295
|
-
game_name,
|
6296
|
-
date_combined,
|
6297
|
-
image,
|
6298
|
-
});
|
6299
|
-
} catch (e) {}
|
6300
|
-
});
|
6301
|
-
const assets = Object.values(data.assets["730"]?.["2"] || {});
|
6302
|
-
return { list, assets, success: true };
|
6270
|
+
if (data?.success !== true) {
|
6271
|
+
return null;
|
6303
6272
|
}
|
6273
|
+
|
6274
|
+
const $ = cheerio.load(data.results_html);
|
6275
|
+
const list = [];
|
6276
|
+
$(".market_listing_row").each(function () {
|
6277
|
+
try {
|
6278
|
+
const $row = $(this);
|
6279
|
+
const [sElementPrefix, listingid, appid, contextid, itemid] = $row
|
6280
|
+
.find(".market_listing_cancel_button > a")
|
6281
|
+
.attr("href")
|
6282
|
+
.split("(")[1]
|
6283
|
+
.split(")")[0]
|
6284
|
+
.split(",")
|
6285
|
+
.map((r) => r.trim().replaceAll(`'`, "").replaceAll(`"`, ""));
|
6286
|
+
const image = $row.find(`#mylisting_${listingid}_image`).attr("src");
|
6287
|
+
const buyer_pays_price = StringUtils.cleanSpace($row.find(`.market_listing_price span[title="This is the price the buyer pays."]`).text().replaceAll(`(`, "").replaceAll(`)`, ""));
|
6288
|
+
const receive_price = StringUtils.cleanSpace($row.find(`.market_listing_price span[title="This is how much you will receive."]`).text().replaceAll(`(`, "").replaceAll(`)`, ""));
|
6289
|
+
const item_name = $row.find(".market_listing_item_name_link").text() || $row.find(".market_listing_item_name").text();
|
6290
|
+
const game_name = $row.find(".market_listing_game_name").text();
|
6291
|
+
const date_combined = formatMarketHistoryDate(StringUtils.cleanSpace($row.find(".market_listing_game_name + .market_listing_listed_date_combined").text()));
|
6292
|
+
list.push({
|
6293
|
+
listingid,
|
6294
|
+
appid,
|
6295
|
+
contextid,
|
6296
|
+
itemid,
|
6297
|
+
buyer_pays_price,
|
6298
|
+
receive_price,
|
6299
|
+
item_name,
|
6300
|
+
game_name,
|
6301
|
+
date_combined,
|
6302
|
+
image,
|
6303
|
+
});
|
6304
|
+
} catch (e) {}
|
6305
|
+
});
|
6306
|
+
const assets = Object.values(data.assets["730"]?.["2"] || {});
|
6307
|
+
return { list, assets, success: true };
|
6304
6308
|
}
|
6305
6309
|
|
6306
6310
|
async getMyMarketHistory({ start = 0, count = 100 } = {}) {
|
6307
6311
|
const result = await this._httpRequestAjax({
|
6308
6312
|
url: `market/myhistory/render/?query=&start=${start}&count=${count}`,
|
6309
6313
|
});
|
6314
|
+
|
6310
6315
|
if (result instanceof ResponseError) {
|
6311
6316
|
return result;
|
6312
6317
|
}
|
6318
|
+
|
6313
6319
|
const data = result?.data;
|
6314
|
-
if (data?.success
|
6315
|
-
|
6316
|
-
|
6317
|
-
|
6318
|
-
|
6319
|
-
|
6320
|
-
|
6321
|
-
|
6322
|
-
|
6323
|
-
|
6324
|
-
|
6325
|
-
|
6326
|
-
|
6320
|
+
if (data?.success !== true) {
|
6321
|
+
return null;
|
6322
|
+
}
|
6323
|
+
|
6324
|
+
const hovers = StringUtils.cleanSpace(data.hovers);
|
6325
|
+
const assetById = data.assets?.[730]?.[2] || {};
|
6326
|
+
const assestByListingId = {};
|
6327
|
+
hovers.split("CreateItemHoverFromContainer").forEach(function (text) {
|
6328
|
+
text = text.trim();
|
6329
|
+
if (!text.startsWith("(")) {
|
6330
|
+
return;
|
6331
|
+
}
|
6332
|
+
const texts = text.split(",");
|
6333
|
+
const listingId = texts[1]?.substringBetweenOrNull("history_row_", "_");
|
6334
|
+
const assestId = texts[4]?.trim()?.removeSurrounding("'");
|
6335
|
+
if (!listingId || !assestId || !assetById[assestId]) {
|
6336
|
+
return;
|
6337
|
+
}
|
6338
|
+
assestByListingId[listingId] = assestId;
|
6339
|
+
});
|
6340
|
+
|
6341
|
+
const $ = cheerio.load(data.results_html);
|
6342
|
+
const list = [...$(".market_listing_row")]
|
6343
|
+
.map(function (el) {
|
6344
|
+
el = $(el);
|
6345
|
+
const id = el.attr("id");
|
6346
|
+
const listingid = id.substringBetweenOrNull("history_row_", "_");
|
6347
|
+
if (!listingid) {
|
6327
6348
|
return;
|
6328
6349
|
}
|
6329
|
-
|
6330
|
-
|
6331
|
-
|
6332
|
-
|
6333
|
-
|
6334
|
-
.
|
6335
|
-
|
6336
|
-
|
6337
|
-
const listingid = id.substringBetweenOrNull("history_row_", "_");
|
6338
|
-
if (!listingid) {
|
6339
|
-
return;
|
6340
|
-
}
|
6341
|
-
const gainOrLoss = StringUtils.cleanSpace(el.find(".market_listing_gainorloss").text());
|
6342
|
-
const image = el.find(`.market_listing_item_img`).attr("src");
|
6343
|
-
const price = parseInt(el.find(`.market_table_value .market_listing_price`).text().replaceAll(`(`, "").replaceAll(`)`, "").replaceAll(`₫`, "").replaceAll(`.`, "").replaceAll(`,`, "").trim()) || "";
|
6344
|
-
const item_name = el.find(".market_listing_item_name").text();
|
6345
|
-
const game_name = el.find(".market_listing_game_name").text();
|
6346
|
-
const listedOn = StringUtils.cleanSpace(el.find(".market_listing_listed_date + .market_listing_listed_date").text().replaceAll(`Listed:`, ""));
|
6347
|
-
const actedOn = StringUtils.cleanSpace(el.find(".market_listing_whoactedwith + .market_listing_listed_date").text().replaceAll(`Listed:`, ""));
|
6348
|
-
const status = StringUtils.cleanSpace(el.find(".market_listing_whoactedwith").text());
|
6350
|
+
const gainOrLoss = StringUtils.cleanSpace(el.find(".market_listing_gainorloss").text());
|
6351
|
+
const image = el.find(`.market_listing_item_img`).attr("src");
|
6352
|
+
const price = parseInt(el.find(`.market_table_value .market_listing_price`).text().replaceAll(`(`, "").replaceAll(`)`, "").replaceAll(`₫`, "").replaceAll(`.`, "").replaceAll(`,`, "").trim()) || "";
|
6353
|
+
const item_name = el.find(".market_listing_item_name").text();
|
6354
|
+
const game_name = el.find(".market_listing_game_name").text();
|
6355
|
+
const listedOn = formatMarketHistoryDate(StringUtils.cleanSpace(el.find(".market_listing_listed_date + .market_listing_listed_date").text().replaceAll(`Listed:`, "")));
|
6356
|
+
const actedOn = formatMarketHistoryDate(StringUtils.cleanSpace(el.find(".market_listing_whoactedwith + .market_listing_listed_date").text().replaceAll(`Listed:`, "")));
|
6357
|
+
const status = StringUtils.cleanSpace(el.find(".market_listing_whoactedwith").text());
|
6349
6358
|
|
6350
|
-
|
6351
|
-
|
6352
|
-
|
6353
|
-
|
6354
|
-
|
6355
|
-
|
6356
|
-
|
6357
|
-
|
6358
|
-
|
6359
|
-
|
6360
|
-
|
6361
|
-
|
6362
|
-
|
6363
|
-
|
6364
|
-
|
6365
|
-
|
6366
|
-
|
6367
|
-
}
|
6359
|
+
return {
|
6360
|
+
id,
|
6361
|
+
listingid,
|
6362
|
+
price,
|
6363
|
+
item_name,
|
6364
|
+
game_name,
|
6365
|
+
listedOn,
|
6366
|
+
actedOn,
|
6367
|
+
image,
|
6368
|
+
gainOrLoss,
|
6369
|
+
status,
|
6370
|
+
...(!!assestByListingId[listingid] && { assetId: assestByListingId[listingid] }),
|
6371
|
+
};
|
6372
|
+
})
|
6373
|
+
.filter(Boolean);
|
6374
|
+
const assets = Object.values(assetById);
|
6375
|
+
return { ...data, list, assets, success: true };
|
6368
6376
|
}
|
6369
6377
|
|
6370
6378
|
async getPlayerReports(token) {
|
@@ -6432,8 +6440,8 @@ export default class SteamUser {
|
|
6432
6440
|
}
|
6433
6441
|
|
6434
6442
|
async beginFileUpload(filePath) {
|
6435
|
-
const {
|
6436
|
-
const
|
6443
|
+
const { imageSize } = await import("image-size");
|
6444
|
+
const dimensions = imageSize(filePath);
|
6437
6445
|
const stats = fs.statSync(filePath);
|
6438
6446
|
|
6439
6447
|
let sha1 = "";
|
@@ -6446,9 +6454,9 @@ export default class SteamUser {
|
|
6446
6454
|
file_size: stats.size,
|
6447
6455
|
file_name: path.basename(filePath),
|
6448
6456
|
file_sha: sha1,
|
6449
|
-
file_image_width:
|
6450
|
-
file_image_height:
|
6451
|
-
file_type:
|
6457
|
+
file_image_width: dimensions.width,
|
6458
|
+
file_image_height: dimensions.height,
|
6459
|
+
file_type: dimensions.type, // Returns "jpg", "png", "webp", etc.
|
6452
6460
|
sessionid: this.getSessionid(),
|
6453
6461
|
};
|
6454
6462
|
|
@@ -7257,8 +7265,8 @@ export default class SteamUser {
|
|
7257
7265
|
}
|
7258
7266
|
|
7259
7267
|
data.communityitemid = Number(data.communityitemid);
|
7260
|
-
if(!data.communityitemid){
|
7261
|
-
return
|
7268
|
+
if (!data.communityitemid) {
|
7269
|
+
return;
|
7262
7270
|
}
|
7263
7271
|
return data;
|
7264
7272
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "steamutils",
|
3
|
-
"version": "1.5.
|
3
|
+
"version": "1.5.26",
|
4
4
|
"main": "index.js",
|
5
5
|
"dependencies": {
|
6
6
|
"alpha-common-utils": "^1.0.6",
|
@@ -10,6 +10,7 @@
|
|
10
10
|
"crypto-js": "^4.2.0",
|
11
11
|
"csgo-friendcode": "^3.0.3",
|
12
12
|
"form-data": "^4.0.1",
|
13
|
+
"image-size": "^2.0.0",
|
13
14
|
"jimp": "^1.6.0",
|
14
15
|
"jsqr": "^1.4.0",
|
15
16
|
"lodash": "^4.17.21",
|
package/utils.js
CHANGED
@@ -932,13 +932,15 @@ export async function loginWithCredentials({ username, password, timeoutMs = 120
|
|
932
932
|
let error = null;
|
933
933
|
const maxRetry = 3;
|
934
934
|
for (let i = 0; i < maxRetry; i++) {
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
935
|
+
if (!authenticated) {
|
936
|
+
try {
|
937
|
+
await session.submitSteamGuardCode(SteamTotp.generateAuthCode(sharedSecret));
|
938
|
+
error = null;
|
939
|
+
} catch (e) {
|
940
|
+
error = e;
|
941
|
+
}
|
942
|
+
await sleep(1000);
|
940
943
|
}
|
941
|
-
await sleep(1000);
|
942
944
|
}
|
943
945
|
if (error) {
|
944
946
|
console.error(error);
|
@@ -986,6 +988,20 @@ export async function loginWithCredentials({ username, password, timeoutMs = 120
|
|
986
988
|
return onResolve(e);
|
987
989
|
});
|
988
990
|
|
991
|
+
session.on("error", (err) => {
|
992
|
+
console.error(`An error occurred: ${err.message}`);
|
993
|
+
return onResolve({
|
994
|
+
error: `An error occurred: ${err.message}`,
|
995
|
+
});
|
996
|
+
});
|
997
|
+
|
998
|
+
session.on("timeout", () => {
|
999
|
+
console.log("This login attempt has timed out.");
|
1000
|
+
return onResolve({
|
1001
|
+
error: "This login attempt has timed out.",
|
1002
|
+
});
|
1003
|
+
});
|
1004
|
+
|
989
1005
|
function onResolve(data) {
|
990
1006
|
clearTimeout(timeout);
|
991
1007
|
return resolve(data);
|
@@ -1232,3 +1248,17 @@ export function getGameDetailScore(scoreString) {
|
|
1232
1248
|
}
|
1233
1249
|
// console.log("No match found", scoreString);
|
1234
1250
|
}
|
1251
|
+
|
1252
|
+
export function formatMarketHistoryDate(dateStr) {
|
1253
|
+
const momentObj = moment(dateStr, "DD MMM", true);
|
1254
|
+
if (!momentObj.isValid()) {
|
1255
|
+
return dateStr;
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
const now = moment();
|
1259
|
+
while (momentObj.isAfter(now)) {
|
1260
|
+
momentObj.subtract(1, "years");
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
return momentObj.format("DD MMM YYYY");
|
1264
|
+
}
|