Update prettier printWidth
							parent
							
								
									e06f0db041
								
							
						
					
					
						commit
						1d5836c0d0
					
				| 
						 | 
					@ -60,11 +60,7 @@ async function main() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Log in the platform
 | 
					  // Log in the platform
 | 
				
			||||||
  console.log("Authenticating...");
 | 
					  console.log("Authenticating...");
 | 
				
			||||||
  const result = await login(
 | 
					  const result = await login(process.env.F95_USERNAME, process.env.F95_PASSWORD, insert2faCode);
 | 
				
			||||||
    process.env.F95_USERNAME,
 | 
					 | 
				
			||||||
    process.env.F95_PASSWORD,
 | 
					 | 
				
			||||||
    insert2faCode
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
  console.log(`Authentication result: ${result.message}\n`);
 | 
					  console.log(`Authentication result: ${result.message}\n`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Manage failed login
 | 
					  // Manage failed login
 | 
				
			||||||
| 
						 | 
					@ -87,9 +83,7 @@ async function main() {
 | 
				
			||||||
  latestQuery.includedTags = ["3d game"];
 | 
					  latestQuery.includedTags = ["3d game"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const latestUpdates = await getLatestUpdates<Game>(latestQuery, 1);
 | 
					  const latestUpdates = await getLatestUpdates<Game>(latestQuery, 1);
 | 
				
			||||||
  console.log(
 | 
					  console.log(`"${latestUpdates.shift().name}" was the last "3d game" tagged game to be updated\n`);
 | 
				
			||||||
    `"${latestUpdates.shift().name}" was the last "3d game" tagged game to be updated\n`
 | 
					 | 
				
			||||||
  );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Get game data
 | 
					  // Get game data
 | 
				
			||||||
  for (const gamename of gameList) {
 | 
					  for (const gamename of gameList) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,14 +6,7 @@
 | 
				
			||||||
"use strict";
 | 
					"use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Modules from files
 | 
					// Modules from files
 | 
				
			||||||
import {
 | 
					import { TAuthor, TRating, IHandiwork, TEngine, TCategory, TStatus } from "../../interfaces";
 | 
				
			||||||
  TAuthor,
 | 
					 | 
				
			||||||
  TRating,
 | 
					 | 
				
			||||||
  IHandiwork,
 | 
					 | 
				
			||||||
  TEngine,
 | 
					 | 
				
			||||||
  TCategory,
 | 
					 | 
				
			||||||
  TStatus
 | 
					 | 
				
			||||||
} from "../../interfaces";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * It represents a generic work, be it a game, a comic, an animation or an asset.
 | 
					 * It represents a generic work, be it a game, a comic, an animation or an asset.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,8 +96,7 @@ export default class HandiworkSearchQuery implements IQuery {
 | 
				
			||||||
    // If the keywords are set or the number
 | 
					    // If the keywords are set or the number
 | 
				
			||||||
    // of included tags is greather than 5,
 | 
					    // of included tags is greather than 5,
 | 
				
			||||||
    // we must perform a thread search
 | 
					    // we must perform a thread search
 | 
				
			||||||
    if (this.keywords || this.includedTags.length > MAX_TAGS_LATEST_SEARCH)
 | 
					    if (this.keywords || this.includedTags.length > MAX_TAGS_LATEST_SEARCH) return "thread";
 | 
				
			||||||
      return "thread";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return DEFAULT_SEARCH_TYPE;
 | 
					    return DEFAULT_SEARCH_TYPE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,8 +130,7 @@ export default class ThreadSearchQuery implements IQuery {
 | 
				
			||||||
    if (this.excludedTags) params["c[excludeTags]"] = this.excludedTags.join(",");
 | 
					    if (this.excludedTags) params["c[excludeTags]"] = this.excludedTags.join(",");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Set minimum reply number
 | 
					    // Set minimum reply number
 | 
				
			||||||
    if (this.minimumReplies > 0)
 | 
					    if (this.minimumReplies > 0) params["c[min_reply_count]"] = this.minimumReplies.toString();
 | 
				
			||||||
      params["c[min_reply_count]"] = this.minimumReplies.toString();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Add prefixes
 | 
					    // Add prefixes
 | 
				
			||||||
    const parser = new PrefixParser();
 | 
					    const parser = new PrefixParser();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -210,8 +210,8 @@ export default class Session {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Search for expired cookies
 | 
					    // Search for expired cookies
 | 
				
			||||||
    const jarValid =
 | 
					    const jarValid =
 | 
				
			||||||
      this._cookieJar.getCookiesSync("https://f95zone.to").filter((el) => el.TTL() === 0)
 | 
					      this._cookieJar.getCookiesSync("https://f95zone.to").filter((el) => el.TTL() === 0).length ===
 | 
				
			||||||
        .length === 0;
 | 
					      0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return dateValid && hashValid && jarValid;
 | 
					    return dateValid && hashValid && jarValid;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -162,8 +162,7 @@ export const POST = {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Contents of a spoiler element in a post.
 | 
					   * Contents of a spoiler element in a post.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  SPOILER_CONTENT:
 | 
					  SPOILER_CONTENT: "div.bbCodeSpoiler-content > div.bbCodeBlock--spoiler > div.bbCodeBlock-content"
 | 
				
			||||||
    "div.bbCodeSpoiler-content > div.bbCodeBlock--spoiler > div.bbCodeBlock-content"
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const MEMBER = {
 | 
					export const MEMBER = {
 | 
				
			||||||
| 
						 | 
					@ -214,8 +213,7 @@ export const MEMBER = {
 | 
				
			||||||
   * If the text is `Unfollow` then the user is followed.
 | 
					   * If the text is `Unfollow` then the user is followed.
 | 
				
			||||||
   * If the text is `Follow` then the user is not followed.
 | 
					   * If the text is `Follow` then the user is not followed.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  FOLLOWED:
 | 
					  FOLLOWED: "div.memberHeader-buttons > div.buttonGroup:first-child > a[data-sk-follow] > span",
 | 
				
			||||||
    "div.memberHeader-buttons > div.buttonGroup:first-child > a[data-sk-follow] > span",
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Button used to ignore/unignore the user.
 | 
					   * Button used to ignore/unignore the user.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,10 +83,7 @@ export type TCategory = "games" | "mods" | "comics" | "animations" | "assets";
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Valid names of classes that implement the IQuery interface.
 | 
					 * Valid names of classes that implement the IQuery interface.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export type TQueryInterface =
 | 
					export type TQueryInterface = "LatestSearchQuery" | "ThreadSearchQuery" | "HandiworkSearchQuery";
 | 
				
			||||||
  | "LatestSearchQuery"
 | 
					 | 
				
			||||||
  | "ThreadSearchQuery"
 | 
					 | 
				
			||||||
  | "HandiworkSearchQuery";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Collection of values defined for each
 | 
					 * Collection of values defined for each
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -86,9 +86,7 @@ export async function fetchHTML(
 | 
				
			||||||
      error: null
 | 
					      error: null
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return isHTML
 | 
					    return isHTML ? success(response.value.data as string) : failure(unexpectedResponseError);
 | 
				
			||||||
      ? success(response.value.data as string)
 | 
					 | 
				
			||||||
      : failure(unexpectedResponseError);
 | 
					 | 
				
			||||||
  } else return failure(response.value as GenericAxiosError);
 | 
					  } else return failure(response.value as GenericAxiosError);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,8 +103,7 @@ export async function authenticate(
 | 
				
			||||||
  force: boolean = 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) throw new InvalidF95Token(`Invalid token for auth: ${credentials.token}`);
 | 
				
			||||||
    throw new InvalidF95Token(`Invalid token for auth: ${credentials.token}`);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Secure the URL
 | 
					  // Secure the URL
 | 
				
			||||||
  const secureURL = enforceHttpsUrl(urls.LOGIN);
 | 
					  const secureURL = enforceHttpsUrl(urls.LOGIN);
 | 
				
			||||||
| 
						 | 
					@ -216,9 +213,7 @@ 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) {
 | 
				
			||||||
    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}`
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    const genericError = new GenericAxiosError({
 | 
					    const genericError = new GenericAxiosError({
 | 
				
			||||||
      id: 1,
 | 
					      id: 1,
 | 
				
			||||||
      message: `(GET) Error ${e.message} occurred while trying to fetch ${secureURL}`,
 | 
					      message: `(GET) Error ${e.message} occurred while trying to fetch ${secureURL}`,
 | 
				
			||||||
| 
						 | 
					@ -305,10 +300,7 @@ export function isStringAValidURL(url: string): boolean {
 | 
				
			||||||
 * If `true`, the function will consider redirects a violation and return `false`.
 | 
					 * If `true`, the function will consider redirects a violation and return `false`.
 | 
				
			||||||
 * Default: `false`
 | 
					 * Default: `false`
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
export async function urlExists(
 | 
					export async function urlExists(url: string, checkRedirect: boolean = false): Promise<boolean> {
 | 
				
			||||||
  url: string,
 | 
					 | 
				
			||||||
  checkRedirect: boolean = false
 | 
					 | 
				
			||||||
): Promise<boolean> {
 | 
					 | 
				
			||||||
  // Local variables
 | 
					  // Local variables
 | 
				
			||||||
  let valid = false;
 | 
					  let valid = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -376,10 +368,7 @@ function manageLoginPOSTResponse(response: AxiosResponse<any>) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Get the error message (if any) and remove the new line chars
 | 
					  // Get the error message (if any) and remove the new line chars
 | 
				
			||||||
  const errorMessage = $("body")
 | 
					  const errorMessage = $("body").find(GENERIC.LOGIN_MESSAGE_ERROR).text().replace(/\n/g, "");
 | 
				
			||||||
    .find(GENERIC.LOGIN_MESSAGE_ERROR)
 | 
					 | 
				
			||||||
    .text()
 | 
					 | 
				
			||||||
    .replace(/\n/g, "");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Return the result of the authentication
 | 
					  // Return the result of the authentication
 | 
				
			||||||
  const result = errorMessage.trim() === "";
 | 
					  const result = errorMessage.trim() === "";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,10 +122,7 @@ function stringToBoolean(s: string): boolean {
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Case-insensitive.
 | 
					 * Case-insensitive.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function getPostElementByName(
 | 
					function getPostElementByName(elements: IPostElement[], name: string): IPostElement | undefined {
 | 
				
			||||||
  elements: IPostElement[],
 | 
					 | 
				
			||||||
  name: string
 | 
					 | 
				
			||||||
): IPostElement | undefined {
 | 
					 | 
				
			||||||
  return elements.find((el) => el.name.toUpperCase() === name.toUpperCase());
 | 
					  return elements.find((el) => el.name.toUpperCase() === name.toUpperCase());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -162,8 +159,7 @@ function fillWithPrefixes(hw: HandiWork, prefixes: string[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Check what the prefix indicates
 | 
					    // Check what the prefix indicates
 | 
				
			||||||
    if (stringInDict(prefix, shared.prefixes["engines"])) engine = prefix as TEngine;
 | 
					    if (stringInDict(prefix, shared.prefixes["engines"])) engine = prefix as TEngine;
 | 
				
			||||||
    else if (stringInDict(prefix, shared.prefixes["statuses"]))
 | 
					    else if (stringInDict(prefix, shared.prefixes["statuses"])) status = prefix as TStatus;
 | 
				
			||||||
      status = prefix as TStatus;
 | 
					 | 
				
			||||||
    else if (stringInDict(prefix, fakeModDict)) mod = true;
 | 
					    else if (stringInDict(prefix, fakeModDict)) mod = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Anyway add the prefix to list
 | 
					    // Anyway add the prefix to list
 | 
				
			||||||
| 
						 | 
					@ -206,8 +202,7 @@ function fillWithPostData(hw: HandiWork, elements: IPostElement[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Parse the censorship
 | 
					  // Parse the censorship
 | 
				
			||||||
  const censored =
 | 
					  const censored =
 | 
				
			||||||
    getPostElementByName(elements, "censored") ||
 | 
					    getPostElementByName(elements, "censored") || getPostElementByName(elements, "censorship");
 | 
				
			||||||
    getPostElementByName(elements, "censorship");
 | 
					 | 
				
			||||||
  if (censored) hw.censored = stringToBoolean(censored.text);
 | 
					  if (censored) hw.censored = stringToBoolean(censored.text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Get the genres
 | 
					  // Get the genres
 | 
				
			||||||
| 
						 | 
					@ -249,8 +244,7 @@ function fillWithPostData(hw: HandiWork, elements: IPostElement[]) {
 | 
				
			||||||
  //#region Get the changelog
 | 
					  //#region Get the changelog
 | 
				
			||||||
  hw.changelog = [];
 | 
					  hw.changelog = [];
 | 
				
			||||||
  const changelogElement =
 | 
					  const changelogElement =
 | 
				
			||||||
    getPostElementByName(elements, "changelog") ||
 | 
					    getPostElementByName(elements, "changelog") || getPostElementByName(elements, "change-log");
 | 
				
			||||||
    getPostElementByName(elements, "change-log");
 | 
					 | 
				
			||||||
  if (changelogElement) {
 | 
					  if (changelogElement) {
 | 
				
			||||||
    const changelogSpoiler = changelogElement?.content.find((el) => {
 | 
					    const changelogSpoiler = changelogElement?.content.find((el) => {
 | 
				
			||||||
      return el.type === "Spoiler" && el.content.length > 0;
 | 
					      return el.type === "Spoiler" && el.content.length > 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,9 +59,7 @@ function parseJSONLD(element: cheerio.Element): TJsonLD {
 | 
				
			||||||
  const html = cheerio(element).html().trim();
 | 
					  const html = cheerio(element).html().trim();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Obtain the JSON-LD
 | 
					  // Obtain the JSON-LD
 | 
				
			||||||
  const data = html
 | 
					  const data = html.replace('<script type="application/ld+json">', "").replace("</script>", "");
 | 
				
			||||||
    .replace('<script type="application/ld+json">', "")
 | 
					 | 
				
			||||||
    .replace("</script>", "");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Convert the string to an object
 | 
					  // Convert the string to an object
 | 
				
			||||||
  return JSON.parse(data);
 | 
					  return JSON.parse(data);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,8 +34,6 @@ export function suite(): void {
 | 
				
			||||||
  it("Fetch post with invalid ID", async function fetchWithInvalidID() {
 | 
					  it("Fetch post with invalid ID", async function fetchWithInvalidID() {
 | 
				
			||||||
    Shared.setIsLogged(true);
 | 
					    Shared.setIsLogged(true);
 | 
				
			||||||
    const thread = new Thread(-1);
 | 
					    const thread = new Thread(-1);
 | 
				
			||||||
    await expect(thread.getPost(0)).to.be.rejectedWith(
 | 
					    await expect(thread.getPost(0)).to.be.rejectedWith("Index must be greater or equal than 1");
 | 
				
			||||||
      "Index must be greater or equal than 1"
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,15 +29,7 @@ export function suite(): void {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test values
 | 
					    // Test values
 | 
				
			||||||
    const testIDs = [103, 225, 44, 13, 2, 7, 22];
 | 
					    const testIDs = [103, 225, 44, 13, 2, 7, 22];
 | 
				
			||||||
    const testPrefixes = [
 | 
					    const testPrefixes = ["corruption", "pregnancy", "slave", "VN", "RPGM", "Ren'Py", "Abandoned"];
 | 
				
			||||||
      "corruption",
 | 
					 | 
				
			||||||
      "pregnancy",
 | 
					 | 
				
			||||||
      "slave",
 | 
					 | 
				
			||||||
      "VN",
 | 
					 | 
				
			||||||
      "RPGM",
 | 
					 | 
				
			||||||
      "Ren'Py",
 | 
					 | 
				
			||||||
      "Abandoned"
 | 
					 | 
				
			||||||
    ];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Parse values
 | 
					    // Parse values
 | 
				
			||||||
    const ids = parser.prefixesToIDs(testPrefixes);
 | 
					    const ids = parser.prefixesToIDs(testPrefixes);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue