steamutils 1.2.95 → 1.2.97

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/SteamClient.js +1 -1
  2. package/index.js +31 -17
  3. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -76,7 +76,7 @@ export const LOCS = {
76
76
 
77
77
  const AppID = 730
78
78
  export let CSGO_VER = 13960
79
- const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, 'free_packages.json'))).packages
79
+ export const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, 'free_packages.json'))).packages
80
80
 
81
81
  SteamUtils.getAppVersion(AppID).then(function (ver) {
82
82
  CSGO_VER = ver
package/index.js CHANGED
@@ -1614,6 +1614,7 @@ class SteamUser {
1614
1614
  }
1615
1615
 
1616
1616
  async _httpRequest(params) {
1617
+ const isRedirect = typeof params.isRedirect === "boolean" ? params.isRedirect : true
1617
1618
  params = this._formatHttpRequest(params)
1618
1619
 
1619
1620
  if (!this._cookies) {
@@ -1675,19 +1676,23 @@ class SteamUser {
1675
1676
 
1676
1677
  switch (response.status) {
1677
1678
  case 302: {
1678
- redirectURL = response.headers.location
1679
+ if(isRedirect){
1680
+ redirectURL = response.headers.location
1679
1681
 
1680
- if (redirectURL?.startsWith('https://steamcommunity.com/id/')) {
1681
- const customURL = redirectURL.split('/')[4];
1682
- if (customURL) {
1683
- this._myProfile = `id/${customURL}`
1682
+ if (redirectURL?.startsWith('https://steamcommunity.com/id/')) {
1683
+ const customURL = redirectURL.split('/')[4];
1684
+ if (customURL) {
1685
+ this._myProfile = `id/${customURL}`
1686
+ }
1687
+ } else if (redirectURL?.startsWith('https://steamcommunity.com/login/')) {
1688
+ console.error('Login first', this._steamid_user)
1689
+ return null
1684
1690
  }
1685
- } else if (redirectURL?.startsWith('https://steamcommunity.com/login/')) {
1686
- console.error('Login first', this._steamid_user)
1687
- return null
1688
- }
1689
1691
 
1690
- console.log(`Redirect ${config.url} to ${redirectURL}`)
1692
+ console.log(`Redirect ${config.url} to ${redirectURL}`)
1693
+ } else {
1694
+ return response
1695
+ }
1691
1696
  break
1692
1697
  }
1693
1698
  case 200: {
@@ -4355,15 +4360,24 @@ class SteamUser {
4355
4360
  }
4356
4361
  }
4357
4362
 
4358
- async addFreeLicense(appID) {
4359
- const {data} = await this._httpRequestAjax({
4360
- url: `https://store.steampowered.com/checkout/addfreelicense/${appID}`,
4361
- data: {
4362
- ajax: true,
4363
- },
4363
+ async addFreeLicense(packageID) {//packageID not appID
4364
+ const form = new FormData();
4365
+ form.append('ajax', "true");
4366
+ form.append('sessionid', this.getSessionid());
4367
+
4368
+ const result = await this._httpRequestAjax({
4369
+ // url: `https://checkout.steampowered.com/checkout/addfreelicense/${appID}`,
4370
+ // url: `https://store.steampowered.com/checkout/addfreelicense/${appID}`,
4371
+ url: `https://store.steampowered.com/freelicense/addfreelicense/${packageID}`,
4372
+ data: form,
4364
4373
  method: 'POST',
4374
+ headers: {
4375
+ 'Content-Type': 'multipart/form-data',
4376
+ },
4365
4377
  })
4366
- return Array.isArray(data) && !data.length
4378
+
4379
+ const data = result.data
4380
+ return result.status === 200 && Array.isArray(data) && !data.length//empty array
4367
4381
  }
4368
4382
 
4369
4383
  async addSubFreeLicense(subid) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.95",
3
+ "version": "1.2.97",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.5.1",