Skip to content

Commit

Permalink
Merge pull request #133 from koikiss-dev/manganelo-fix
Browse files Browse the repository at this point in the history
fix(ManganeloFilter): error when genres parameter is not provided
  • Loading branch information
koikiss-dev authored Jan 29, 2024
2 parents 04c9fcb + 636b904 commit 4acaac3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/scraper/sites/manga/manganelo/ManganatoManagerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ export class ManganatoManagerUtils {
private static instance: ManganatoManagerUtils;
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;
}
}
2 changes: 2 additions & 0 deletions src/scraper/sites/manga/manganelo/ManganatoTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface IManganatoFilterParams {
page: number;
};

export type ManganatoFilterURLParams = keyof Omit<IManganatoFilterParams, "genres"> | "g_i" | "s";

export const manganatoGenreList = {
action: 2,
adult: 3,
Expand Down
22 changes: 14 additions & 8 deletions src/scraper/sites/manga/manganelo/managers/ManganatoURLManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { URLSearchParams } from "url";
import { IManganatoFilterParams, manganatoGenreList, manganatoOrderByOptions, manganatoOrderByOptionsList } from "../ManganatoTypes";
import { IManganatoFilterParams, manganatoGenreList, manganatoOrderByOptions, manganatoOrderByOptionsList, ManganatoFilterURLParams } from "../ManganatoTypes";
import { ManganatoManager } from "./ManganatoManager";

export class ManganatoAdvancedSearchURLManager extends ManganatoManager {
Expand Down Expand Up @@ -38,17 +38,23 @@ export class ManganatoAdvancedSearchURLManager extends ManganatoManager {
: "";
}

generate(params: IManganatoFilterParams) {
const splitted = this.splitGenresToArray(params.genres);
const processed = this.processGenres(splitted);

const urlParams = new URLSearchParams({
generate(params: Partial<IManganatoFilterParams>) {
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() : ""
});
} satisfies Record<ManganatoFilterURLParams, string>;

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()}`;
}
Expand Down

0 comments on commit 4acaac3

Please sign in to comment.