Lint scripts

pull/81/head
MillenniumEarl 2021-03-04 13:15:01 +01:00
parent e6f6d5b1b7
commit 2070352ca0
13 changed files with 68 additions and 71 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* /*
to use this example, create an .env file to use this example, create an .env file
in the project root with the following values: in the project root with the following values:

View File

@ -45,8 +45,8 @@ export { default as ThreadSearchQuery } from "./scripts/classes/query/thread-sea
/** /**
* Set the logger level for module debugging. * Set the logger level for module debugging.
*/ */
/* istambul ignore next */ // eslint-disable-next-line prefer-const
export var loggerLevel = shared.logger.level; export let loggerLevel = shared.logger.level;
shared.logger.level = "warn"; // By default log only the warn messages shared.logger.level = "warn"; // By default log only the warn messages
/** /**

View File

@ -38,91 +38,91 @@ export default class PlatformUser {
/** /**
* Unique user ID. * Unique user ID.
*/ */
public get id() { public get id(): number {
return this._id; return this._id;
} }
/** /**
* Username. * Username.
*/ */
public get name() { public get name(): string {
return this._name; return this._name;
} }
/** /**
* Title assigned to the user by the platform. * Title assigned to the user by the platform.
*/ */
public get title() { public get title(): string {
return this._title; return this._title;
} }
/** /**
* List of banners assigned by the platform. * List of banners assigned by the platform.
*/ */
public get banners() { public get banners(): string[] {
return this._banners; return this._banners;
} }
/** /**
* Number of messages written by the user. * Number of messages written by the user.
*/ */
public get messages() { public get messages(): number {
return this._messages; return this._messages;
} }
/** /**
* @todo Reaction score. * @todo Reaction score.
*/ */
public get reactionScore() { public get reactionScore(): number {
return this._reactionScore; return this._reactionScore;
} }
/** /**
* @todo Points. * @todo Points.
*/ */
public get points() { public get points(): number {
return this._points; return this._points;
} }
/** /**
* Number of ratings received. * Number of ratings received.
*/ */
public get ratingsReceived() { public get ratingsReceived(): number {
return this._ratingsReceived; return this._ratingsReceived;
} }
/** /**
* Date of joining the platform. * Date of joining the platform.
*/ */
public get joined() { public get joined(): Date {
return this._joined; return this._joined;
} }
/** /**
* Date of the last connection to the platform. * Date of the last connection to the platform.
*/ */
public get lastSeen() { public get lastSeen(): Date {
return this._lastSeen; return this._lastSeen;
} }
/** /**
* Indicates whether the user is followed by the currently logged in user. * Indicates whether the user is followed by the currently logged in user.
*/ */
public get followed() { public get followed(): boolean {
return this._followed; return this._followed;
} }
/** /**
* Indicates whether the user is ignored by the currently logged on user. * Indicates whether the user is ignored by the currently logged on user.
*/ */
public get ignored() { public get ignored(): boolean {
return this._ignored; return this._ignored;
} }
/** /**
* Indicates that the profile is private and not viewable by the user. * Indicates that the profile is private and not viewable by the user.
*/ */
public get private() { public get private(): boolean {
return this._private; return this._private;
} }
/** /**
* URL of the image used as the user's avatar. * URL of the image used as the user's avatar.
*/ */
public get avatar() { public get avatar(): string {
return this._avatar; return this._avatar;
} }
/** /**
* Value of donations made. * Value of donations made.
*/ */
public get donation() { public get donation(): number {
return this._amountDonated; return this._amountDonated;
} }
@ -134,11 +134,11 @@ export default class PlatformUser {
//#region Public methods //#region Public methods
public setID(id: number) { public setID(id: number): void {
this._id = id; this._id = id;
} }
public async fetch() { public async fetch(): Promise<void> {
// Check ID // Check ID
if (!this.id && this.id < 1) throw new Error("Invalid user ID"); if (!this.id && this.id < 1) throw new Error("Invalid user ID");

View File

@ -35,49 +35,49 @@ export default class Post {
/** /**
* Represents a post published by a user on the F95Zone platform. * Represents a post published by a user on the F95Zone platform.
*/ */
public get id() { public get id(): number {
return this._id; return this._id;
} }
/** /**
* Unique ID of the post within the thread in which it is present. * Unique ID of the post within the thread in which it is present.
*/ */
public get number() { public get number(): number {
return this._number; return this._number;
} }
/** /**
* Date the post was first published. * Date the post was first published.
*/ */
public get published() { public get published(): Date {
return this._published; return this._published;
} }
/** /**
* Date the post was last modified. * Date the post was last modified.
*/ */
public get lastEdit() { public get lastEdit(): Date {
return this._lastEdit; return this._lastEdit;
} }
/** /**
* User who owns the post. * User who owns the post.
*/ */
public get owner() { public get owner(): PlatformUser {
return this._owner; return this._owner;
} }
/** /**
* Indicates whether the post has been bookmarked. * Indicates whether the post has been bookmarked.
*/ */
public get bookmarked() { public get bookmarked(): boolean {
return this._bookmarked; return this._bookmarked;
} }
/** /**
* Post message text. * Post message text.
*/ */
public get message() { public get message(): string {
return this._message; return this._message;
} }
/** /**
* Set of the elements that make up the body of the post. * Set of the elements that make up the body of the post.
*/ */
public get body() { public get body(): IPostElement[] {
return this._body; return this._body;
} }
@ -92,7 +92,7 @@ export default class Post {
/** /**
* Gets the post data starting from its unique ID for the entire platform. * Gets the post data starting from its unique ID for the entire platform.
*/ */
public async fetch() { public async fetch(): Promise<void> {
// Fetch HTML page containing the post // Fetch HTML page containing the post
const url = new URL(this.id.toString(), urls.F95_POSTS).toString(); const url = new URL(this.id.toString(), urls.F95_POSTS).toString();
const htmlResponse = await fetchHTML(url); const htmlResponse = await fetchHTML(url);

View File

@ -45,7 +45,7 @@ export default class Thread {
/** /**
* Unique ID of the thread on the platform. * Unique ID of the thread on the platform.
*/ */
public get id() { public get id(): number {
return this._id; return this._id;
} }
/** /**
@ -53,55 +53,55 @@ export default class Thread {
* *
* It may vary depending on any versions of the contained product. * It may vary depending on any versions of the contained product.
*/ */
public get url() { public get url(): string {
return this._url; return this._url;
} }
/** /**
* Thread title. * Thread title.
*/ */
public get title() { public get title(): string {
return this._title; return this._title;
} }
/** /**
* Tags associated with the thread. * Tags associated with the thread.
*/ */
public get tags() { public get tags(): string[] {
return this._tags; return this._tags;
} }
/** /**
* Prefixes associated with the thread * Prefixes associated with the thread
*/ */
public get prefixes() { public get prefixes(): string[] {
return this._prefixes; return this._prefixes;
} }
/** /**
* Rating assigned to the thread. * Rating assigned to the thread.
*/ */
public get rating() { public get rating(): TRating {
return this._rating; return this._rating;
} }
/** /**
* Owner of the thread. * Owner of the thread.
*/ */
public get owner() { public get owner(): PlatformUser {
return this._owner; return this._owner;
} }
/** /**
* Date the thread was first published. * Date the thread was first published.
*/ */
public get publication() { public get publication(): Date {
return this._publication; return this._publication;
} }
/** /**
* Date the thread was last modified. * Date the thread was last modified.
*/ */
public get modified() { public get modified(): Date {
return this._modified; return this._modified;
} }
/** /**
* Category to which the content of the thread belongs. * Category to which the content of the thread belongs.
*/ */
public get category() { public get category(): TCategory {
return this._category; return this._category;
} }
@ -233,7 +233,7 @@ export default class Thread {
/** /**
* Gets information about this thread. * Gets information about this thread.
*/ */
public async fetch() { public async fetch(): Promise<void> {
// Prepare the url // Prepare the url
this._url = new URL(this.id.toString(), urls.F95_THREADS).toString(); this._url = new URL(this.id.toString(), urls.F95_THREADS).toString();

View File

@ -52,28 +52,28 @@ export default class UserProfile extends PlatformUser {
/** /**
* List of followed thread data. * List of followed thread data.
*/ */
public get watched() { public get watched(): IWatchedThread[] {
return this._watched; return this._watched;
} }
/** /**
* List of bookmarked posts. * List of bookmarked posts.
* @todo * @todo
*/ */
public get bookmarks() { public get bookmarks(): Post[] {
return this._bookmarks; return this._bookmarks;
} }
/** /**
* List of alerts. * List of alerts.
* @todo * @todo
*/ */
public get alerts() { public get alerts(): string[] {
return this._alerts; return this._alerts;
} }
/** /**
* List of conversations. * List of conversations.
* @todo * @todo
*/ */
public get conversation() { public get conversation(): string[] {
return this._conversations; return this._conversations;
} }
@ -85,7 +85,7 @@ export default class UserProfile extends PlatformUser {
//#region Public methods //#region Public methods
public async fetch() { public async fetch(): Promise<void> {
// First get the user ID and set it // First get the user ID and set it
const id = await this.fetchUserID(); const id = await this.fetchUserID();
super.setID(id); super.setID(id);

View File

@ -6,7 +6,7 @@ import validator from "class-validator";
// Module from files // Module from files
import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js"; import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js";
import { GenericAxiosError, UnexpectedResponseContentType } from "../errors.js"; import { GenericAxiosError } from "../errors.js";
import { Result } from "../result.js"; import { Result } from "../result.js";
import LatestSearchQuery, { TLatestOrder } from "./latest-search-query.js"; import LatestSearchQuery, { TLatestOrder } from "./latest-search-query.js";
import ThreadSearchQuery, { TThreadOrder } from "./thread-search-query.js"; import ThreadSearchQuery, { TThreadOrder } from "./thread-search-query.js";

View File

@ -8,6 +8,9 @@ import { urls } from "../../constants/url.js";
import PrefixParser from "../prefix-parser.js"; import PrefixParser from "../prefix-parser.js";
import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js"; import { IQuery, TCategory, TQueryInterface } from "../../interfaces.js";
import { fetchGETResponse } from "../../network-helper.js"; import { fetchGETResponse } from "../../network-helper.js";
import { AxiosResponse } from "axios";
import { GenericAxiosError } from "../errors.js";
import { Result } from "../result.js";
// Type definitions // Type definitions
export type TLatestOrder = "date" | "likes" | "views" | "title" | "rating"; export type TLatestOrder = "date" | "likes" | "views" | "title" | "rating";
@ -64,7 +67,9 @@ export default class LatestSearchQuery implements IQuery {
return validator.validateSync(this).length === 0; return validator.validateSync(this).length === 0;
} }
public async execute() { public async execute(): Promise<
Result<GenericAxiosError, AxiosResponse<any>>
> {
// Check if the query is valid // Check if the query is valid
if (!this.validate()) { if (!this.validate()) {
throw new Error( throw new Error(

View File

@ -37,37 +37,37 @@ export default class Session {
/** /**
* Path of the session map file on disk. * Path of the session map file on disk.
*/ */
public get path() { public get path(): string {
return this._path; return this._path;
} }
/** /**
* Indicates if the session is mapped on disk. * Indicates if the session is mapped on disk.
*/ */
public get isMapped() { public get isMapped(): boolean {
return this._isMapped; return this._isMapped;
} }
/** /**
* Date of creation of the session. * Date of creation of the session.
*/ */
public get created() { public get created(): Date {
return this._created; return this._created;
} }
/** /**
* MD5 hash of the username and the password. * MD5 hash of the username and the password.
*/ */
public get hash() { public get hash(): string {
return this._hash; return this._hash;
} }
/** /**
* Token used to login to F95Zone. * Token used to login to F95Zone.
*/ */
public get token() { public get token(): string {
return this._token; return this._token;
} }
/** /**
* Cookie holder. * Cookie holder.
*/ */
public get cookieJar() { public get cookieJar(): tough.CookieJar {
return this._cookieJar; return this._cookieJar;
} }

View File

@ -84,7 +84,7 @@ export async function fetchHTML(
*/ */
export async function authenticate( export async function authenticate(
credentials: credentials, credentials: credentials,
force = false force: boolean = false
): Promise<LoginResult> { ): Promise<LoginResult> {
shared.logger.info(`Authenticating with user ${credentials.username}`); shared.logger.info(`Authenticating with user ${credentials.username}`);
if (!credentials.token) if (!credentials.token)
@ -140,7 +140,7 @@ export async function authenticate(
/** /**
* Obtain the token used to authenticate the user to the platform. * Obtain the token used to authenticate the user to the platform.
*/ */
export async function getF95Token() { export async function getF95Token(): Promise<string> {
// Fetch the response of the platform // Fetch the response of the platform
const response = await fetchGETResponse(f95url.F95_LOGIN_URL); const response = await fetchGETResponse(f95url.F95_LOGIN_URL);
@ -167,7 +167,6 @@ export async function fetchGETResponse(
const response = await axios.get(secureURL, commonConfig); const response = await axios.get(secureURL, commonConfig);
return success(response); return success(response);
} catch (e) { } catch (e) {
console.log(e.response);
shared.logger.error( shared.logger.error(
`(GET) Error ${e.message} occurred while trying to fetch ${secureURL}` `(GET) Error ${e.message} occurred while trying to fetch ${secureURL}`
); );
@ -217,7 +216,7 @@ export function isStringAValidURL(url: string): boolean {
*/ */
export async function urlExists( export async function urlExists(
url: string, url: string,
checkRedirect = false checkRedirect: boolean = false
): Promise<boolean> { ): Promise<boolean> {
// Local variables // Local variables
let valid = false; let valid = false;

View File

@ -90,13 +90,7 @@ function parseCheerioSpoilerNode(
if (element.attr("class") === "bbCodeSpoiler") { if (element.attr("class") === "bbCodeSpoiler") {
const spoiler = parseCheerioSpoilerNode($, element); const spoiler = parseCheerioSpoilerNode($, element);
content.content.push(spoiler); content.content.push(spoiler);
} } else if (el.type === "text") {
//@ts-ignore
// else if (el.name === "br") {
// // Add new line
// content.text += "\n";
// }
else if (el.type === "text") {
// Append text // Append text
content.text += element.text(); content.text += element.text();
} }
@ -266,7 +260,7 @@ function parseCheerioNode(
function parsePostElements(elements: IPostElement[]): IPostElement[] { function parsePostElements(elements: IPostElement[]): IPostElement[] {
// Local variables // Local variables
const pairs: IPostElement[] = []; const pairs: IPostElement[] = [];
const specialCharsRegex = /^[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]/; const specialCharsRegex = /^[-!$%^&*()_+|~=`{}[\]:";'<>?,./]/;
const specialRegex = new RegExp(specialCharsRegex); const specialRegex = new RegExp(specialCharsRegex);
for (let i = 0; i < elements.length; i++) { for (let i = 0; i < elements.length; i++) {

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-inferrable-types */
"use strict"; "use strict";
// Modules from file // Modules from file
@ -13,15 +14,13 @@ import getURLsFromQuery from "./fetch-data/fetch-query.js";
*/ */
export default async function search<T extends IBasic>( export default async function search<T extends IBasic>(
query: IQuery, query: IQuery,
limit = 30 limit: number = 30
): Promise<T[]> { ): Promise<T[]> {
// Fetch the URLs // Fetch the URLs
const urls: string[] = await getURLsFromQuery(query, limit); const urls: string[] = await getURLsFromQuery(query, limit);
// Fetch the data // Fetch the data
const results = urls.map((url, idx) => { const results = urls.map((url) => getHandiworkInformation<T>(url));
return getHandiworkInformation<T>(url);
});
return Promise.all(results); return Promise.all(results);
} }

View File

@ -14,6 +14,7 @@ import Session from "./classes/session.js";
// Types declaration // Types declaration
export type TPrefixDict = { [n: number]: string }; export type TPrefixDict = { [n: number]: string };
type TPrefixKey = "engines" | "statuses" | "tags" | "others"; type TPrefixKey = "engines" | "statuses" | "tags" | "others";
type TPrefixes = { [key in TPrefixKey]: TPrefixDict };
/** /**
* Class containing variables shared between modules. * Class containing variables shared between modules.
@ -22,9 +23,7 @@ export default abstract class Shared {
//#region Fields //#region Fields
private static _isLogged = false; private static _isLogged = false;
private static _prefixes: { [key in TPrefixKey]: TPrefixDict } = {} as { private static _prefixes: TPrefixes = {} as TPrefixes;
[key in TPrefixKey]: TPrefixDict;
};
private static _logger: log4js.Logger = log4js.getLogger(); private static _logger: log4js.Logger = log4js.getLogger();
private static _session = new Session(join(tmpdir(), "f95session.json")); private static _session = new Session(join(tmpdir(), "f95session.json"));