Resolved circular dependency

pull/59/head
MillenniumEarl 2020-12-17 22:44:40 +01:00
parent cdfe056f8f
commit d3a1a1e11a
2 changed files with 9 additions and 8 deletions

View File

@ -7,6 +7,7 @@ const scraper = require("./scripts/scraper.js");
const searcher = require("./scripts/searcher.js"); const searcher = require("./scripts/searcher.js");
const uScraper = require("./scripts/user-scraper.js"); const uScraper = require("./scripts/user-scraper.js");
const latestFetch = require("./scripts/latest-fetch.js"); const latestFetch = require("./scripts/latest-fetch.js");
const fetchPlatformData = require("./scripts/platform-data.js").fetchPlatformData;
// Classes from file // Classes from file
const Credentials = require("./scripts/classes/credentials.js"); const Credentials = require("./scripts/classes/credentials.js");
@ -69,6 +70,9 @@ module.exports.login = async function (username, password) {
const result = await networkHelper.authenticate(creds); const result = await networkHelper.authenticate(creds);
shared.isLogged = result.success; shared.isLogged = result.success;
// Load platform data
if (result.success) await fetchPlatformData();
/* istambul ignore next */ /* istambul ignore next */
if (result.success) shared.logger.info("User logged in through the platform"); if (result.success) shared.logger.info("User logged in through the platform");
else shared.logger.warn(`Error during authentication: ${result.message}`); else shared.logger.warn(`Error during authentication: ${result.message}`);

View File

@ -11,7 +11,6 @@ const shared = require("./shared.js");
const f95url = require("./constants/url.js"); const f95url = require("./constants/url.js");
const f95selector = require("./constants/css-selector.js"); const f95selector = require("./constants/css-selector.js");
const LoginResult = require("./classes/login-result.js"); const LoginResult = require("./classes/login-result.js");
const fetchPlatformData = require("./platform-data.js").fetchPlatformData;
// Global variables // Global variables
const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) " + const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) " +
@ -96,12 +95,9 @@ module.exports.authenticate = async function (credentials, force) {
const errorMessage = $("body").find(f95selector.LOGIN_MESSAGE_ERROR).text().replace(/\n/g, ""); const errorMessage = $("body").find(f95selector.LOGIN_MESSAGE_ERROR).text().replace(/\n/g, "");
// Return the result of the authentication // Return the result of the authentication
if (errorMessage === "") { const result = errorMessage.trim() === "";
// Fetch data const message = errorMessage.trim() === "" ? "Authentication successful" : errorMessage;
await fetchPlatformData(); return new LoginResult(result, message);
return new LoginResult(true, "Authentication successful");
}
else return new LoginResult(false, errorMessage);
} catch (e) { } catch (e) {
shared.logger.error(`Error ${e.message} occurred while authenticating to ${secureURL}`); shared.logger.error(`Error ${e.message} occurred while authenticating to ${secureURL}`);
return new LoginResult(false, `Error ${e.message} while authenticating`); return new LoginResult(false, `Error ${e.message} while authenticating`);
@ -230,10 +226,11 @@ async function _axiosUrlExists(url) {
// Local variables // Local variables
let valid = false; let valid = false;
try { try {
const response = await axios.head(url); const response = await axios.head(url, {timeout: 3000});
valid = response && !/4\d\d/.test(response.status); valid = response && !/4\d\d/.test(response.status);
} catch (error) { } catch (error) {
if (error.code === "ENOTFOUND") valid = false; if (error.code === "ENOTFOUND") valid = false;
else if (error.code === "ETIMEDOUT") valid = false;
else throw error; else throw error;
} }
return valid; return valid;