From 731785cd12543df8bdb338757674d4c36107a3d9 Mon Sep 17 00:00:00 2001 From: 4n4n4s Date: Fri, 10 Nov 2023 17:02:52 +0000 Subject: [PATCH] * fixing sonar issues --- README.md | 2 +- config.js | 8 ++++---- playstation.js | 20 ++++++++------------ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 41a8465b..b47c045e 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/config.js b/config.js index 297cb904..ec99307f 100644 --- a/config.js +++ b/config.js @@ -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', }; diff --git a/playstation.js b/playstation.js index 9a33bd12..25650ee1 100644 --- a/playstation.js +++ b/playstation.js @@ -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 @@ -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 @@ -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()) { @@ -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); @@ -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;