2020-10-16 07:58:42 +00:00
|
|
|
"use strict";
|
2020-10-02 12:01:51 +00:00
|
|
|
|
|
|
|
// Core modules
|
2020-10-16 07:58:42 +00:00
|
|
|
const { join } = require("path");
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-21 13:31:11 +00:00
|
|
|
const log4js = require("log4js");
|
|
|
|
|
2020-10-01 19:13:23 +00:00
|
|
|
/**
|
|
|
|
* Class containing variables shared between modules.
|
|
|
|
*/
|
|
|
|
class Shared {
|
2020-10-29 21:14:40 +00:00
|
|
|
//#region Properties
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* Shows log messages and other useful functions for module debugging.
|
|
|
|
* @type Boolean
|
|
|
|
*/
|
2020-10-21 13:31:11 +00:00
|
|
|
static #_debug = false;
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* Indicates whether a user is logged in to the F95Zone platform or not.
|
|
|
|
* @type Boolean
|
|
|
|
*/
|
2020-10-21 13:31:11 +00:00
|
|
|
static #_isLogged = false;
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* List of cookies obtained from the F95Zone platform.
|
|
|
|
* @type Object[]
|
|
|
|
*/
|
2020-10-21 13:31:11 +00:00
|
|
|
static #_cookies = null;
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* List of possible game engines used for development.
|
|
|
|
* @type String[]
|
|
|
|
*/
|
2020-10-21 13:31:11 +00:00
|
|
|
static #_engines = null;
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* List of possible development statuses that a game can assume.
|
|
|
|
* @type String[]
|
|
|
|
*/
|
2020-10-21 13:31:11 +00:00
|
|
|
static #_statuses = null;
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* Wait instruction for the browser created by puppeteer.
|
|
|
|
* @type String
|
|
|
|
*/
|
2020-10-16 07:58:42 +00:00
|
|
|
static WAIT_STATEMENT = "domcontentloaded";
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* Path to the directory to save the cache generated by the API.
|
|
|
|
* @type String
|
|
|
|
*/
|
2020-10-21 13:31:11 +00:00
|
|
|
static #_cacheDir = "./f95cache";
|
2020-10-08 21:09:05 +00:00
|
|
|
/**
|
|
|
|
* If true, it opens a new browser for each request to
|
|
|
|
* the F95Zone platform, otherwise it reuses the same.
|
|
|
|
* @type Boolean
|
|
|
|
*/
|
2020-10-21 13:31:11 +00:00
|
|
|
static #_isolation = false;
|
2020-10-21 13:31:39 +00:00
|
|
|
/**
|
2020-10-21 13:31:11 +00:00
|
|
|
* Logger object used to write to both file and console.
|
|
|
|
* @type log4js.Logger
|
|
|
|
*/
|
|
|
|
static #_logger = log4js.getLogger();
|
2020-10-08 21:09:05 +00:00
|
|
|
//#endregion Properties
|
2020-10-01 19:13:23 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
//#region Getters
|
|
|
|
/**
|
|
|
|
* Shows log messages and other useful functions for module debugging.
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
static get debug() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_debug;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Indicates whether a user is logged in to the F95Zone platform or not.
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
static get isLogged() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_isLogged;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* List of cookies obtained from the F95Zone platform.
|
|
|
|
* @returns {Object[]}
|
|
|
|
*/
|
|
|
|
static get cookies() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_cookies;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* List of possible game engines used for development.
|
|
|
|
* @returns {String[]}
|
|
|
|
*/
|
|
|
|
static get engines() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_engines;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* List of possible development states that a game can assume.
|
|
|
|
* @returns {String[]}
|
|
|
|
*/
|
|
|
|
static get statuses() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_statuses;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Directory to save the API cache.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
static get cacheDir() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_cacheDir;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Path to the F95 platform cache.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
static get cookiesCachePath() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return join(this.#_cacheDir, "cookies.json");
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Path to the game engine cache.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
static get enginesCachePath() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return join(this.#_cacheDir, "engines.json");
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Path to the cache of possible game states.
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
static get statusesCachePath() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return join(this.#_cacheDir, "statuses.json");
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* If true, it opens a new browser for each request
|
|
|
|
* to the F95Zone platform, otherwise it reuses the same.
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
static get isolation() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_isolation;
|
2020-10-21 13:31:11 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Logger object used to write to both file and console.
|
|
|
|
* @returns {log4js.Logger}
|
|
|
|
*/
|
|
|
|
static get logger() {
|
2020-10-29 21:14:40 +00:00
|
|
|
return this.#_logger;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
//#endregion Getters
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
//#region Setters
|
|
|
|
static set cookies(val) {
|
2020-10-29 21:14:40 +00:00
|
|
|
this.#_cookies = val;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
static set engines(val) {
|
2020-10-29 21:14:40 +00:00
|
|
|
this.#_engines = val;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
static set statuses(val) {
|
2020-10-29 21:14:40 +00:00
|
|
|
this.#_statuses = val;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
static set cacheDir(val) {
|
2020-10-29 21:14:40 +00:00
|
|
|
this.#_cacheDir = val;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
static set debug(val) {
|
2020-10-29 21:14:40 +00:00
|
|
|
this.#_debug = val;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
static set isLogged(val) {
|
2020-10-29 21:14:40 +00:00
|
|
|
this.#_isLogged = val;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
2020-10-02 12:01:51 +00:00
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
static set isolation(val) {
|
2020-10-29 21:14:40 +00:00
|
|
|
this.#_isolation = val;
|
2020-10-08 21:09:05 +00:00
|
|
|
}
|
|
|
|
//#endregion Setters
|
2020-10-01 19:13:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 21:09:05 +00:00
|
|
|
module.exports = Shared;
|