Bugfixes
parent
22d5df4bed
commit
5c963a14c9
|
@ -37,7 +37,7 @@ async function main() {
|
||||||
// Get user data
|
// Get user data
|
||||||
console.log("Fetching user data...");
|
console.log("Fetching user data...");
|
||||||
const userdata = await F95API.getUserData();
|
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) {
|
for(const gamename of gameList) {
|
||||||
console.log(`Searching '${gamename}'...`);
|
console.log(`Searching '${gamename}'...`);
|
||||||
|
|
|
@ -93,6 +93,7 @@ class GameInfo {
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
|
id: this.id,
|
||||||
name: this.name,
|
name: this.name,
|
||||||
author: this.author,
|
author: this.author,
|
||||||
url: this.url,
|
url: this.url,
|
||||||
|
@ -106,10 +107,8 @@ class GameInfo {
|
||||||
previewSrc: this.previewSrc,
|
previewSrc: this.previewSrc,
|
||||||
version: this.version,
|
version: this.version,
|
||||||
lastUpdate: this.lastUpdate,
|
lastUpdate: this.lastUpdate,
|
||||||
lastPlayed: this.lastPlayed,
|
|
||||||
isMod: this.isMod,
|
isMod: this.isMod,
|
||||||
changelog: this.changelog,
|
changelog: this.changelog,
|
||||||
gameDir: this.gameDir,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,20 +6,20 @@
|
||||||
class UserData {
|
class UserData {
|
||||||
constructor() {
|
constructor() {
|
||||||
/**
|
/**
|
||||||
* User name.
|
* User name.
|
||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
this.username = "";
|
this.username = "";
|
||||||
/**
|
/**
|
||||||
* Path to the user's profile picture.
|
* Path to the user's profile picture.
|
||||||
* @type String
|
* @type String
|
||||||
*/
|
*/
|
||||||
this.avatarSrc = null;
|
this.avatarSrc = null;
|
||||||
/**
|
/**
|
||||||
* List of followed thread URLs.
|
* List of followed game thread URLs.
|
||||||
* @type String[]
|
* @type String[]
|
||||||
*/
|
*/
|
||||||
this.watchedThreads = [];
|
this.watchedGameThreads = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ const LoginResult = require("./classes/login-result.js");
|
||||||
const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) " +
|
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";
|
"AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15";
|
||||||
axiosCookieJarSupport(axios);
|
axiosCookieJarSupport(axios);
|
||||||
const cookieJar = new tough.CookieJar();
|
|
||||||
|
|
||||||
const commonConfig = {
|
const commonConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -27,7 +26,7 @@ const commonConfig = {
|
||||||
"Connection": "keep-alive"
|
"Connection": "keep-alive"
|
||||||
},
|
},
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
jar: cookieJar // Used to store the token in the PC
|
jar: new tough.CookieJar() // Used to store the token in the PC
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,13 +17,13 @@ const UserData = require("./classes/user-data.js");
|
||||||
module.exports.getUserData = async function() {
|
module.exports.getUserData = async function() {
|
||||||
// Fetch data
|
// Fetch data
|
||||||
const data = await fetchUsernameAndAvatar();
|
const data = await fetchUsernameAndAvatar();
|
||||||
const urls = await fetchWatchedThreadURLs();
|
const urls = await fetchWatchedGameThreadURLs();
|
||||||
|
|
||||||
// Create object
|
// Create object
|
||||||
const ud = new UserData();
|
const ud = new UserData();
|
||||||
ud.username = data.username;
|
ud.username = data.username;
|
||||||
ud.avatarSrc = data.source;
|
ud.avatarSrc = data.source;
|
||||||
ud.watchedThreads = urls;
|
ud.watchedGameThreads = urls;
|
||||||
|
|
||||||
return ud;
|
return ud;
|
||||||
};
|
};
|
||||||
|
@ -58,13 +58,21 @@ async function fetchUsernameAndAvatar() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @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
|
* @returns {Promise<String[]>} List of URLs
|
||||||
*/
|
*/
|
||||||
async function fetchWatchedThreadURLs() {
|
async function fetchWatchedGameThreadURLs() {
|
||||||
// Local variables
|
// Local variables
|
||||||
let currentURL = f95url.F95_WATCHED_THREADS;
|
const watchedGameThreadURLs = [];
|
||||||
const wathcedThreadURLs = [];
|
|
||||||
|
// 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 {
|
do {
|
||||||
// Fetch page
|
// Fetch page
|
||||||
|
@ -76,14 +84,14 @@ async function fetchWatchedThreadURLs() {
|
||||||
|
|
||||||
// Find the URLs
|
// Find the URLs
|
||||||
const urls = fetchPageURLs(body);
|
const urls = fetchPageURLs(body);
|
||||||
wathcedThreadURLs.push(...urls);
|
watchedGameThreadURLs.push(...urls);
|
||||||
|
|
||||||
// Find the next page (if any)
|
// Find the next page (if any)
|
||||||
currentURL = fetchNextPageURL(body);
|
currentURL = fetchNextPageURL(body);
|
||||||
}
|
}
|
||||||
while (currentURL);
|
while (currentURL);
|
||||||
|
|
||||||
return wathcedThreadURLs;
|
return watchedGameThreadURLs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue