Skip to content

Commit

Permalink
* fixing sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
4n4n4s committed Nov 10, 2023
1 parent ae9e79a commit 731785c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Available options/variables and their default values:
| PS_PASSWORD | | PlayStation password for login. Overrides PASSWORD. |
| PS_OTPKEY | | PlayStation MFA OTP key. |
| PS_LOCALE | en-us | Configurable locale to use the store. Examples are en-us, en-gb, de-at, ... |
| PS_PLUS_GAMES | 1 | Claim monthly ps plus games. Requires PS Plus Essential or higher subscription. |
| PS_PLUS_GAMES | 0 | Claim monthly ps plus games. Requires PS Plus Essential or higher subscription. |
| PS_GAME_CATALOG | 0 | Claim over 400 game catalog games. Requires PS Extra or higher. |
| PS_CLASSICS_CATALOG | 0 | Currently not implemented! Requires PS Extra or higher. |

Expand Down
8 changes: 4 additions & 4 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export const cfg = {
ps_email: process.env.PS_EMAIL || process.env.EMAIL,
ps_password: process.env.PS_PASSWORD || process.env.PASSWORD,
ps_otpkey: process.env.PS_OTPKEY,
ps_locale: "en-us" || process.env.PS_LOCALE,
ps_plus_games: true || process.env.PS_PLUS_GAMES == '1',
ps_game_catalog: false || process.env.PS_GAME_CATALOG == '1',
ps_classics_catalog: false || process.env.PS_CLASSICS_CATALOG == '1',
ps_locale: process.env.PS_LOCALE || "en-us",
ps_plus_games: process.env.PS_PLUS_GAMES == '1',
ps_game_catalog: process.env.PS_GAME_CATALOG == '1',
ps_classics_catalog: process.env.PS_CLASSICS_CATALOG == '1',
};
20 changes: 8 additions & 12 deletions playstation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
stealth,
} from "./util.js";
import path from "path";
import { existsSync, writeFileSync } from "fs";
import { existsSync } from "fs";
import { cfg } from "./config.js";

// ### SETUP
Expand All @@ -36,11 +36,10 @@ export async function setup() {
// channel: 'chrome', // https://playwright.dev/docs/browsers#google-chrome--microsoft-edge
headless: cfg.headless,
viewport: { width: cfg.width, height: cfg.height },
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36', // see replace of Headless in util.newStealthContext. TODO Windows UA enough to avoid 'device not supported'? update if browser is updated?
// userAgent for firefox: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36',
locale: "en-US", // ignore OS locale to be sure to have english text for locators
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
recordHar: cfg.record ? { path: `data/record/eg-${datetime()}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined,
recordHar: cfg.record ? { path: `data/record/eg-${datetime()}.har` } : undefined,
args: [ // https://peter.sh/experiments/chromium-command-line-switches
// don't want to see bubble 'Restore pages? Chrome didn't shut down correctly.'
// '--restore-last-session', // does not apply for crash/killed
Expand Down Expand Up @@ -250,7 +249,7 @@ async function claimGame(url) {
return;
}

var prefix;
let prefix;
if (url.includes("store.playstation.com")) {
const gameDiv = await page.locator(".psw-l-anchor").first();
if (gameDiv.isVisible()) {
Expand Down Expand Up @@ -385,11 +384,8 @@ async function claimGameCatalog() {

const catalogGameUrls = await Promise.all(
catalogGames.map(async (catalogGame) => {
var urlSlug = await catalogGame.getAttribute("href");

urlSlug = urlSlug.replace("en-gb", cfg.ps_locale).replace("en-us", cfg.ps_locale).substring(0, urlSlug.indexOf("?"));
//console.log(urlSlug);
return urlSlug; // url may have anchor tag, remove it
const urlSlug = await catalogGame.getAttribute("href");
return urlSlug.replace("en-gb", cfg.ps_locale).replace("en-us", cfg.ps_locale).substring(0, urlSlug.indexOf("?"));
})
);
console.log("Total catalog games:", catalogGameUrls.length);
Expand All @@ -403,7 +399,7 @@ async function claimGameCatalog() {

function isClaimedUrl(url) {
try {
var status = db.data[user][url.split("/").filter((x) => !!x).pop()]["status"];
const status = db.data[user][url.split("/").filter((x) => !!x).pop()]["status"];
return status === "existed" || status === "claimed";
} catch (error) {
return false;
Expand Down

0 comments on commit 731785c

Please sign in to comment.