diff --git a/src/scraper/sites/manga/manganelo/ManganatoManagerUtils.ts b/src/scraper/sites/manga/manganelo/ManganatoManagerUtils.ts index 92dabde..3f0c750 100644 --- a/src/scraper/sites/manga/manganelo/ManganatoManagerUtils.ts +++ b/src/scraper/sites/manga/manganelo/ManganatoManagerUtils.ts @@ -2,11 +2,15 @@ import { ManganatoAdvancedSearchURLManager } from "./managers/ManganatoURLManage export class ManganatoManagerUtils { private static instance: ManganatoManagerUtils; - readonly url: ManganatoAdvancedSearchURLManager = new ManganatoAdvancedSearchURLManager(); + readonly url: ManganatoAdvancedSearchURLManager = + new ManganatoAdvancedSearchURLManager(); + + private constructor() {} static get Instance() { - if (!this.instance) this.instance = new ManganatoManagerUtils(); + if (!ManganatoManagerUtils.instance) + ManganatoManagerUtils.instance = new ManganatoManagerUtils(); - return this.instance; + return ManganatoManagerUtils.instance; } } diff --git a/src/scraper/sites/manga/manganelo/ManganatoTypes.ts b/src/scraper/sites/manga/manganelo/ManganatoTypes.ts index 925d79e..fed9247 100644 --- a/src/scraper/sites/manga/manganelo/ManganatoTypes.ts +++ b/src/scraper/sites/manga/manganelo/ManganatoTypes.ts @@ -1,5 +1,6 @@ export const manganatoOrderByOptionsList = ["topview", "newest", "az"] as const; -export type manganatoOrderByOptions = typeof manganatoOrderByOptionsList[number]; +export type manganatoOrderByOptions = + (typeof manganatoOrderByOptionsList)[number]; export interface IManganatoFilterParams { /** @@ -13,7 +14,12 @@ export interface IManganatoFilterParams { genres: string; /** Results page */ page: number; -}; +} + +export type ManganatoFilterURLParams = + | keyof Omit + | "g_i" + | "s"; export const manganatoGenreList = { action: 2, @@ -57,5 +63,5 @@ export const manganatoGenreList = { manhua: 44, isekai: 45, pornographic: 47, - erotica: 48 + erotica: 48, } as const; diff --git a/src/scraper/sites/manga/manganelo/managers/ManganatoURLManager.ts b/src/scraper/sites/manga/manganelo/managers/ManganatoURLManager.ts index db9655c..cf1e266 100644 --- a/src/scraper/sites/manga/manganelo/managers/ManganatoURLManager.ts +++ b/src/scraper/sites/manga/manganelo/managers/ManganatoURLManager.ts @@ -1,5 +1,11 @@ import { URLSearchParams } from "url"; -import { IManganatoFilterParams, manganatoGenreList, manganatoOrderByOptions, manganatoOrderByOptionsList } from "../ManganatoTypes"; +import { + IManganatoFilterParams, + ManganatoFilterURLParams, + manganatoGenreList, + manganatoOrderByOptions, + manganatoOrderByOptionsList, +} from "../ManganatoTypes"; import { ManganatoManager } from "./ManganatoManager"; export class ManganatoAdvancedSearchURLManager extends ManganatoManager { @@ -11,9 +17,9 @@ export class ManganatoAdvancedSearchURLManager extends ManganatoManager { } private processGenres(genresArray: string[]): number[] { - let arrGenerated: number[] = []; + const arrGenerated: number[] = []; - for (let genre of genresArray) { + for (const genre of genresArray) { if (manganatoGenreList[genre.toLowerCase()]) arrGenerated.push(manganatoGenreList[genre.toLowerCase()]); else continue; @@ -27,28 +33,39 @@ export class ManganatoAdvancedSearchURLManager extends ManganatoManager { } private processStatus(status: unknown) { - return (typeof status === "string" && (status.toLowerCase() === "ongoing" || status.toLowerCase() === "completed")) + return typeof status === "string" && + (status.toLowerCase() === "ongoing" || + status.toLowerCase() === "completed") ? status : ""; } private processOrderBy(order: unknown) { - return (typeof order === "string" && manganatoOrderByOptionsList.includes(order.toLowerCase() as manganatoOrderByOptions)) + return typeof order === "string" && + manganatoOrderByOptionsList.includes( + order.toLowerCase() as manganatoOrderByOptions, + ) ? order : ""; } - generate(params: IManganatoFilterParams) { - const splitted = this.splitGenresToArray(params.genres); - const processed = this.processGenres(splitted); - - const urlParams = new URLSearchParams({ + generate(params: Partial) { + const urlParamsObject = { s: "all", - g_i: processed.length ? this.formatGenres(processed) : "", + g_i: "", sts: this.processStatus(params.sts), orby: this.processOrderBy(params.orby), - page: params.page ? params.page.toString() : "" - }); + page: params.page ? params.page.toString() : "", + } satisfies Record; + + if (params.genres) { + const splitted = this.splitGenresToArray(params.genres); + const processed = this.processGenres(splitted); + + urlParamsObject.g_i = this.formatGenres(processed); + } + + const urlParams = new URLSearchParams(urlParamsObject); return `${this.baseURL}?${urlParams.toString()}`; }