pull/47/head
MillenniumEarl 2020-11-07 18:55:20 +01:00
parent 22d5df4bed
commit 5c963a14c9
5 changed files with 29 additions and 23 deletions

View File

@ -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}'...`);

View File

@ -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,
};
}

View File

@ -16,10 +16,10 @@ class UserData {
*/
this.avatarSrc = null;
/**
* List of followed thread URLs.
* List of followed game thread URLs.
* @type String[]
*/
this.watchedThreads = [];
this.watchedGameThreads = [];
}
}

View File

@ -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
};
/**

View File

@ -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<String[]>} 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;
}
/**