From 5c963a14c95f48fce8caaabafe0c8ccfff6967ea Mon Sep 17 00:00:00 2001 From: MillenniumEarl Date: Sat, 7 Nov 2020 18:55:20 +0100 Subject: [PATCH] Bugfixes --- app/example.js | 2 +- app/scripts/classes/game-info.js | 3 +-- app/scripts/classes/user-data.js | 20 ++++++++++---------- app/scripts/network-helper.js | 3 +-- app/scripts/user-scraper.js | 24 ++++++++++++++++-------- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/example.js b/app/example.js index 38ef905..995ee9b 100644 --- a/app/example.js +++ b/app/example.js @@ -37,7 +37,7 @@ async function main() { // Get user data console.log("Fetching user data..."); const userdata = await F95API.getUserData(); - console.log(`${userdata.username} follows ${userdata.watchedThreads.length} threads`); + console.log(`${userdata.username} follows ${userdata.watchedGameThreads.length} threads`); for(const gamename of gameList) { console.log(`Searching '${gamename}'...`); diff --git a/app/scripts/classes/game-info.js b/app/scripts/classes/game-info.js index f133b90..78883d0 100644 --- a/app/scripts/classes/game-info.js +++ b/app/scripts/classes/game-info.js @@ -93,6 +93,7 @@ class GameInfo { /* istanbul ignore next */ toJSON() { return { + id: this.id, name: this.name, author: this.author, url: this.url, @@ -106,10 +107,8 @@ class GameInfo { previewSrc: this.previewSrc, version: this.version, lastUpdate: this.lastUpdate, - lastPlayed: this.lastPlayed, isMod: this.isMod, changelog: this.changelog, - gameDir: this.gameDir, }; } diff --git a/app/scripts/classes/user-data.js b/app/scripts/classes/user-data.js index bdc2457..233c641 100644 --- a/app/scripts/classes/user-data.js +++ b/app/scripts/classes/user-data.js @@ -6,20 +6,20 @@ class UserData { constructor() { /** - * User name. - * @type String - */ + * User name. + * @type String + */ this.username = ""; /** - * Path to the user's profile picture. - * @type String - */ + * Path to the user's profile picture. + * @type String + */ this.avatarSrc = null; /** - * List of followed thread URLs. - * @type String[] - */ - this.watchedThreads = []; + * List of followed game thread URLs. + * @type String[] + */ + this.watchedGameThreads = []; } } diff --git a/app/scripts/network-helper.js b/app/scripts/network-helper.js index 7e3ae4a..e713a5c 100644 --- a/app/scripts/network-helper.js +++ b/app/scripts/network-helper.js @@ -19,7 +19,6 @@ const LoginResult = require("./classes/login-result.js"); const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) " + "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15"; axiosCookieJarSupport(axios); -const cookieJar = new tough.CookieJar(); const commonConfig = { headers: { @@ -27,7 +26,7 @@ const commonConfig = { "Connection": "keep-alive" }, withCredentials: true, - jar: cookieJar // Used to store the token in the PC + jar: new tough.CookieJar() // Used to store the token in the PC }; /** diff --git a/app/scripts/user-scraper.js b/app/scripts/user-scraper.js index c9c96e3..c0d14c2 100644 --- a/app/scripts/user-scraper.js +++ b/app/scripts/user-scraper.js @@ -17,13 +17,13 @@ const UserData = require("./classes/user-data.js"); module.exports.getUserData = async function() { // Fetch data const data = await fetchUsernameAndAvatar(); - const urls = await fetchWatchedThreadURLs(); + const urls = await fetchWatchedGameThreadURLs(); // Create object const ud = new UserData(); ud.username = data.username; ud.avatarSrc = data.source; - ud.watchedThreads = urls; + ud.watchedGameThreads = urls; return ud; }; @@ -58,13 +58,21 @@ async function fetchUsernameAndAvatar() { /** * @private - * Gets the list of URLs of threads watched by the user. + * Gets the list of URLs of game threads watched by the user. * @returns {Promise} List of URLs */ -async function fetchWatchedThreadURLs() { +async function fetchWatchedGameThreadURLs() { // Local variables - let currentURL = f95url.F95_WATCHED_THREADS; - const wathcedThreadURLs = []; + const watchedGameThreadURLs = []; + + // Get the first page with the "unread" flag disabled + // and searching only the games forum + const firstPageURL = new URL(f95url.F95_WATCHED_THREADS); + firstPageURL.searchParams.append("unread", "0"); + firstPageURL.searchParams.append("nodes[0]", "2"); // This is the forum filter + + // Set the variable containing the current scraped page + let currentURL = firstPageURL.href; do { // Fetch page @@ -76,14 +84,14 @@ async function fetchWatchedThreadURLs() { // Find the URLs const urls = fetchPageURLs(body); - wathcedThreadURLs.push(...urls); + watchedGameThreadURLs.push(...urls); // Find the next page (if any) currentURL = fetchNextPageURL(body); } while (currentURL); - return wathcedThreadURLs; + return watchedGameThreadURLs; } /**