import { Injectable } from "@angular/core"; import { Observable, catchError, map, throwError } from "rxjs"; import { Parser } from "../parser"; import { IRulibChapterResult } from "./rulib.chapter.dto"; import { IRulibChaptersResult } from "./rulib.chapters.dto"; import { IRulibDetailResult } from "./rulib.detail.dto"; import { IRulibSearchResult } from "./rulib.search.dto"; //TODO: Make abstract classes @Injectable({ providedIn: "root", }) export class LibSocialParserService extends Parser { // eslint-disable-next-line @typescript-eslint/no-explicit-any protected url = (this as any).api_url; // eslint-disable-next-line @typescript-eslint/no-explicit-any private site_id = (this as any).site_id; get imageServer() { return "https://img33.imgslib.link"; } searchManga(query: string): Observable { return this.http .get( `${this.url}/api/manga?fields[]=rate_avg&fields[]=rate&q=${query}&site_id[]=${this.site_id}`, ) .pipe( map((data: object) => { return data as IRulibSearchResult; }), catchError((error) => { return throwError(() => `Now found ${error}`); }), ); } getDetails(slug_url: string): Observable { return this.http .get( `${this.url}/api/manga/${slug_url}?fields[]=summary&fields[]=genres&fields[]=tags&fields[]=authors`, ) .pipe( map((data: object) => { return data as IRulibDetailResult; }), catchError((error) => { return throwError(() => `Now found ${error}`); }), ); } getChapters(url: string): Observable { return this.http.get(`${this.url}/api/manga/${url}/chapters`).pipe( map((data) => { return data as IRulibChaptersResult; }), catchError((error) => { return throwError(() => `Now found ${error}`); }), ); } getChapter(url: string, chapter: string, volume: string): Observable { return this.http .get(`${this.url}/api/manga/${url}/chapter?number=${chapter}&volume=${volume}`) .pipe( map((data) => data as IRulibChapterResult), catchError((error) => throwError(() => `Now found ${error}`)), ); } }