steamutils 1.5.24 → 1.5.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +97 -89
  2. package/package.json +1 -1
  3. package/utils.js +1248 -1234
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 === true) {
6269
- const $ = cheerio.load(data.results_html);
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 === true) {
6315
- const hovers = StringUtils.cleanSpace(data.hovers);
6316
- const assetById = data.assets?.[730]?.[2] || {};
6317
- const assestByListingId = {};
6318
- hovers.split("CreateItemHoverFromContainer").forEach(function (text) {
6319
- text = text.trim();
6320
- if (!text.startsWith("(")) {
6321
- return;
6322
- }
6323
- const texts = text.split(",");
6324
- const listingId = texts[1]?.substringBetweenOrNull("history_row_", "_");
6325
- const assestId = texts[4]?.trim()?.removeSurrounding("'");
6326
- if (!listingId || !assestId || !assetById[assestId]) {
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
- assestByListingId[listingId] = assestId;
6330
- });
6331
-
6332
- const $ = cheerio.load(data.results_html);
6333
- const list = [...$(".market_listing_row")]
6334
- .map(function (el) {
6335
- el = $(el);
6336
- const id = el.attr("id");
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
- return {
6351
- id,
6352
- listingid,
6353
- price,
6354
- item_name,
6355
- game_name,
6356
- listedOn,
6357
- actedOn,
6358
- image,
6359
- gainOrLoss,
6360
- status,
6361
- ...(!!assestByListingId[listingid] && { assetId: assestByListingId[listingid] }),
6362
- };
6363
- })
6364
- .filter(Boolean);
6365
- const assets = Object.values(assetById);
6366
- return { ...data, list, assets, success: true };
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) {
@@ -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.24",
3
+ "version": "1.5.25",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",