Merge branch 'master' into deepsource-fix-dc58783a
commit
e2d939c593
11
README.md
11
README.md
|
@ -9,8 +9,9 @@
|
|||
Unofficial Node JS module for scraping F95Zone platform
|
||||
|
||||
# Guidelines for errors
|
||||
+ If you can, return a meaningful value
|
||||
+ Return `null` only if the function should return a complex object (including strings)
|
||||
+ Return an empty array if the function should return an array
|
||||
+ Return `false`, `-1` when the function should retrn `boolean` or `number`
|
||||
+ Throw an exception only if it is an error or if a wrong value could mess up the functioning of the library
|
||||
|
||||
- If you can, return a meaningful value
|
||||
- Return `null` only if the function should return a complex object (including strings)
|
||||
- Return an empty array if the function should return an array
|
||||
- Return `false`, `-1` when the function should retrn `boolean` or `number`
|
||||
- Throw an exception only if it is an error or if a wrong value could mess up the functioning of the library
|
||||
|
|
|
@ -27,7 +27,8 @@ module.exports.getGameInfo = async function (browser, url) {
|
|||
// Verify the correctness of the URL
|
||||
const exists = await urlHelper.urlExists(url);
|
||||
if (!exists) throw new URIError(url + " is not a valid URL");
|
||||
if (!urlHelper.isF95URL(url)) throw new Error(url + " is not a valid F95Zone URL");
|
||||
if (!urlHelper.isF95URL(url))
|
||||
throw new Error(url + " is not a valid F95Zone URL");
|
||||
|
||||
const page = await preparePage(browser); // Set new isolated page
|
||||
await page.setCookie(...shared.cookies); // Set cookies to avoid login
|
||||
|
@ -203,7 +204,7 @@ async function getGamePreviewSource(page) {
|
|||
(selector) => {
|
||||
// Get the firs image available
|
||||
const img = document.querySelector(selector);
|
||||
|
||||
|
||||
if (img) return img.getAttribute("src");
|
||||
else return null;
|
||||
},
|
||||
|
@ -278,7 +279,7 @@ async function parsePrefixes(page, info) {
|
|||
|
||||
// Clean the prefix
|
||||
const prefix = value.toUpperCase().replace("[", "").replace("]", "").trim();
|
||||
|
||||
|
||||
// Getting infos...
|
||||
if (shared.statuses.includes(prefix)) info.status = capitalize(prefix);
|
||||
else if (shared.engines.includes(prefix)) info.engine = capitalize(prefix);
|
||||
|
@ -309,7 +310,8 @@ async function getLastChangelog(page) {
|
|||
let parsedText = HTMLParser.parse(changelogHTML).structuredText;
|
||||
|
||||
// Clean the text
|
||||
if (parsedText.startsWith("Spoiler")) parsedText = parsedText.replace("Spoiler", "");
|
||||
if (parsedText.startsWith("Spoiler"))
|
||||
parsedText = parsedText.replace("Spoiler", "");
|
||||
if (parsedText.startsWith(":")) parsedText = parsedText.replace(":", "");
|
||||
return parsedText.trim();
|
||||
}
|
||||
|
@ -450,7 +452,7 @@ function extractGameHostingData(platform, text) {
|
|||
|
||||
/**
|
||||
* Capitalize a string
|
||||
* @param {String} string
|
||||
* @param {String} string
|
||||
*/
|
||||
function capitalize(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
|
|
|
@ -124,10 +124,7 @@ async function getThreadURL(page, handle) {
|
|||
if (isF95URL(relativeURLThread)) return relativeURLThread;
|
||||
|
||||
// ... else compose the URL and return
|
||||
const urlThread = new URL(
|
||||
relativeURLThread,
|
||||
urlK.F95_BASE_URL
|
||||
).toString();
|
||||
const urlThread = new URL(relativeURLThread, urlK.F95_BASE_URL).toString();
|
||||
return urlThread;
|
||||
}
|
||||
//#endregion Private methods
|
||||
|
|
|
@ -51,7 +51,7 @@ class Shared {
|
|||
* @type Boolean
|
||||
*/
|
||||
static #_isolation = false;
|
||||
/**
|
||||
/**
|
||||
* Logger object used to write to both file and console.
|
||||
* @type log4js.Logger
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue