Style bugfixes

pull/29/head
MillenniumEarl 2020-10-16 09:45:58 +02:00
parent 987a9f08f0
commit 98067e0636
6 changed files with 59 additions and 45 deletions

View File

@ -268,7 +268,7 @@ module.exports.getGameDataFromURL = async function (url) {
// Check URL // Check URL
if (!urlExists(url)) return null; if (!urlExists(url)) return null;
if (!isF95URL(url)) throw url + " is not a valid F95Zone URL"; if (!isF95URL(url)) throw new Error(url + " is not a valid F95Zone URL");
// Gets the search results of the game being searched for // Gets the search results of the game being searched for
if (_browser === null && !shared.isolation) _browser = await prepareBrowser(); if (_browser === null && !shared.isolation) _browser = await prepareBrowser();
@ -508,9 +508,8 @@ async function loginF95(browser, username, password) {
const c = await page.cookies(); const c = await page.cookies();
fs.writeFileSync(shared.cookiesCachePath, JSON.stringify(c)); fs.writeFileSync(shared.cookiesCachePath, JSON.stringify(c));
result.message = "Authentication successful"; result.message = "Authentication successful";
} } else if (
// Obtain the error message // Obtain the error message
else if (
await page.evaluate( await page.evaluate(
/* istanbul ignore next */ (selector) => /* istanbul ignore next */ (selector) =>
document.querySelector(selector) !== null, document.querySelector(selector) !== null,

View File

@ -4,17 +4,17 @@
* Object obtained in response to an attempt to login to the portal. * Object obtained in response to an attempt to login to the portal.
*/ */
class LoginResult { class LoginResult {
constructor() { constructor() {
/** /**
* Result of the login operation * Result of the login operation
* @type Boolean * @type Boolean
*/ */
this.success = false; this.success = false;
/** /**
* Login response message * Login response message
* @type String * @type String
*/ */
this.message = ''; this.message = '';
} }
} }
module.exports = LoginResult; module.exports = LoginResult;

View File

@ -1,7 +1,7 @@
module.exports = Object.freeze({ module.exports = Object.freeze({
F95_BASE_URL: 'https://f95zone.to', F95_BASE_URL: 'https://f95zone.to',
F95_SEARCH_URL: 'https://f95zone.to/search', F95_SEARCH_URL: 'https://f95zone.to/search',
F95_LATEST_UPDATES: 'https://f95zone.to/latest', F95_LATEST_UPDATES: 'https://f95zone.to/latest',
F95_LOGIN_URL: 'https://f95zone.to/login', F95_LOGIN_URL: 'https://f95zone.to/login',
F95_WATCHED_THREADS: 'https://f95zone.to/watched/threads', F95_WATCHED_THREADS: 'https://f95zone.to/watched/threads',
}); });

View File

@ -2,15 +2,21 @@
// Public modules from npm // Public modules from npm
const HTMLParser = require("node-html-parser"); const HTMLParser = require("node-html-parser");
const puppeteer = require("puppeteer"); const puppeteer = require("puppeteer"); // skipcq: JS-0128
// Modules from file // Modules from file
const shared = require("./shared.js"); const shared = require("./shared.js");
const selectors = require("./constants/css-selectors.js"); const selectors = require("./constants/css-selectors.js");
const { preparePage } = require("./puppeteer-helper.js"); const {
preparePage
} = require("./puppeteer-helper.js");
const GameDownload = require("./classes/game-download.js"); const GameDownload = require("./classes/game-download.js");
const GameInfo = require("./classes/game-info.js"); const GameInfo = require("./classes/game-info.js");
const { isStringAValidURL, isF95URL, urlExists } = require("./urls-helper.js"); const {
isStringAValidURL,
isF95URL,
urlExists
} = require("./urls-helper.js");
/** /**
* @protected * @protected
@ -24,7 +30,7 @@ module.exports.getGameInfo = async function (browser, url) {
if (shared.debug) console.log("Obtaining game info"); if (shared.debug) console.log("Obtaining game info");
// Verify the correctness of the URL // Verify the correctness of the URL
if (!isF95URL(url)) throw url + " is not a valid F95Zone URL"; if (!isF95URL(url)) throw new Error(url + " is not a valid F95Zone URL");
const exists = await urlExists(url); const exists = await urlExists(url);
if (!exists) return null; if (!exists) return null;
@ -54,12 +60,12 @@ module.exports.getGameInfo = async function (browser, url) {
info.overview = overview; info.overview = overview;
info.tags = await tags; info.tags = await tags;
info.f95url = url; info.f95url = url;
info.version = info.isMod info.version = info.isMod ?
? parsedInfos["MOD VERSION"] parsedInfos["MOD VERSION"] :
: parsedInfos["VERSION"]; parsedInfos["VERSION"];
info.lastUpdate = info.isMod info.lastUpdate = info.isMod ?
? parsedInfos["UPDATED"] parsedInfos["UPDATED"] :
: parsedInfos["THREAD UPDATED"]; parsedInfos["THREAD UPDATED"];
info.previewSource = await previewSource; info.previewSource = await previewSource;
info.changelog = (await changelog || "Unknown changelog"); info.changelog = (await changelog || "Unknown changelog");
//info.downloadInfo = await downloadData; //info.downloadInfo = await downloadData;
@ -132,7 +138,8 @@ async function getMainPostStructuredText(page) {
// The info are plain text so we need to parse the HTML code // The info are plain text so we need to parse the HTML code
const bodyHTML = await page.evaluate( const bodyHTML = await page.evaluate(
/* istanbul ignore next */ (mainPost) => mainPost.innerHTML, /* istanbul ignore next */
(mainPost) => mainPost.innerHTML,
post post
); );
return HTMLParser.parse(bodyHTML).structuredText; return HTMLParser.parse(bodyHTML).structuredText;
@ -147,8 +154,9 @@ async function getMainPostStructuredText(page) {
async function getGameAuthor(page) { async function getGameAuthor(page) {
// Get the game/mod name (without square brackets) // Get the game/mod name (without square brackets)
const titleHTML = await page.evaluate( const titleHTML = await page.evaluate(
/* istanbul ignore next */ (selector) => /* istanbul ignore next */
document.querySelector(selector).innerHTML, (selector) =>
document.querySelector(selector).innerHTML,
selectors.GAME_TITLE selectors.GAME_TITLE
); );
const structuredTitle = HTMLParser.parse(titleHTML); const structuredTitle = HTMLParser.parse(titleHTML);
@ -196,7 +204,8 @@ function parseConversationPage(text) {
*/ */
async function getGamePreviewSource(page) { async function getGamePreviewSource(page) {
const src = await page.evaluate( const src = await page.evaluate(
/* istanbul ignore next */ (selector) => { /* istanbul ignore next */
(selector) => {
// Get the firs image available // Get the firs image available
const img = document.querySelector(selector); const img = document.querySelector(selector);
@ -219,8 +228,9 @@ async function getGamePreviewSource(page) {
async function getGameTitle(page) { async function getGameTitle(page) {
// Get the game/mod name (without square brackets) // Get the game/mod name (without square brackets)
const titleHTML = await page.evaluate( const titleHTML = await page.evaluate(
/* istanbul ignore next */ (selector) => /* istanbul ignore next */
document.querySelector(selector).innerHTML, (selector) =>
document.querySelector(selector).innerHTML,
selectors.GAME_TITLE selectors.GAME_TITLE
); );
const structuredTitle = HTMLParser.parse(titleHTML); const structuredTitle = HTMLParser.parse(titleHTML);
@ -243,7 +253,8 @@ async function getGameTags(page) {
// Get the game tags // Get the game tags
for (const handle of await page.$$(selectors.GAME_TAGS)) { for (const handle of await page.$$(selectors.GAME_TAGS)) {
const tag = await page.evaluate( const tag = await page.evaluate(
/* istanbul ignore next */ (element) => element.innerText, /* istanbul ignore next */
(element) => element.innerText,
handle handle
); );
tags.push(tag.toUpperCase()); tags.push(tag.toUpperCase());
@ -266,7 +277,8 @@ async function parsePrefixes(page, info) {
info.status = "Ongoing"; info.status = "Ongoing";
for (const handle of await page.$$(selectors.GAME_TITLE_PREFIXES)) { for (const handle of await page.$$(selectors.GAME_TITLE_PREFIXES)) {
const value = await page.evaluate( const value = await page.evaluate(
/* istanbul ignore next */ (element) => element.innerText, /* istanbul ignore next */
(element) => element.innerText,
handle handle
); );
@ -310,6 +322,7 @@ async function getLastChangelog(page) {
* @param {puppeteer.Page} page Page containing the links to be extrapolated * @param {puppeteer.Page} page Page containing the links to be extrapolated
* @returns {Promise<GameDownload[]>} List of objects used for game download * @returns {Promise<GameDownload[]>} List of objects used for game download
*/ */
// skipcq: JS-0128
async function getGameDownloadLink(page) { async function getGameDownloadLink(page) {
// Most used hosting platforms // Most used hosting platforms
const hostingPlatforms = [ const hostingPlatforms = [
@ -337,7 +350,8 @@ async function getGameDownloadLink(page) {
if (container !== null) break; if (container !== null) break;
const upperText = ( const upperText = (
await page.evaluate( await page.evaluate(
/* istanbul ignore next */ (e) => e.innerText, /* istanbul ignore next */
(e) => e.innerText,
candidate candidate
) )
).toUpperCase(); ).toUpperCase();
@ -355,7 +369,8 @@ async function getGameDownloadLink(page) {
// Extract the HTML text from the container // Extract the HTML text from the container
const searchText = ( const searchText = (
await page.evaluate( await page.evaluate(
/* istanbul ignore next */ (e) => e.innerHTML, /* istanbul ignore next */
(e) => e.innerHTML,
container container
) )
).toLowerCase(); ).toLowerCase();
@ -398,8 +413,8 @@ function extractGameHostingData(platform, text) {
// Find the end of the container // Find the end of the container
if (endIndex === -1) if (endIndex === -1)
endIndex = endIndex =
text.indexOf(CONTAINER_SPAN_CLOSE, startIndex) + text.indexOf(CONTAINER_SPAN_CLOSE, startIndex) +
CONTAINER_SPAN_CLOSE.length; CONTAINER_SPAN_CLOSE.length;
text = text.substring(startIndex, endIndex); text = text.substring(startIndex, endIndex);

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
// Public modules from npm // Public modules from npm
const puppeteer = require("puppeteer"); const puppeteer = require("puppeteer"); // skipcq: JS-0128
// Modules from file // Modules from file
const shared = require("./shared.js"); const shared = require("./shared.js");

View File

@ -27,7 +27,7 @@ module.exports.isF95URL = function (url) {
*/ */
module.exports.isStringAValidURL = function (url) { module.exports.isStringAValidURL = function (url) {
try { try {
new URL(url); new URL(url); // skipcq: JS-0078
return true; return true;
} catch (err) { } catch (err) {
return false; return false;