Files
NwaifuWeb/apps/NwaifuAnime/src/app/services/search.service.ts

63 lines
1.8 KiB
TypeScript

import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { BehaviorSubject, Observable, map } from "rxjs";
import { MangalibParserService } from "./parsers/rulib/mangalib.parser.service";
import { IRulibChapterResult } from "./parsers/rulib/rulib.chapter.dto";
import { IRulibChaptersResult } from "./parsers/rulib/rulib.chapters.dto";
import { IRulibDetailResult } from "./parsers/rulib/rulib.detail.dto";
import { Datum, IRulibSearchResult } from "./parsers/rulib/rulib.search.dto";
@Injectable({ providedIn: "root" })
export class SearchService {
private itemsTerm = new BehaviorSubject<Datum[]>([]);
currentItemsTerm = this.itemsTerm.asObservable();
constructor(
private parser: MangalibParserService,
private http: HttpClient,
) {}
search(query: string): Observable<IRulibSearchResult> {
return this.parser.searchManga(query).pipe(
map((data) => {
return data;
}),
);
}
getDetails(slug_url: string): Observable<IRulibDetailResult> {
return this.parser.getDetails(slug_url).pipe(
map((data) => {
return data;
}),
);
}
getChapters(url: string): Observable<IRulibChaptersResult> {
return this.parser.getChapters(url).pipe(
map((data) => {
return data;
}),
);
}
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
return this.parser.getChapter(url, chapter, volume).pipe(
map((data) => {
return data;
}),
);
}
getImageServer() {
return this.parser.imageServer;
}
getImageData(imageUrl: string): Observable<Uint8Array> {
return this.http.get(imageUrl, { responseType: "arraybuffer" }).pipe(
map((arrayBuffer: ArrayBuffer) => {
return new Uint8Array(arrayBuffer);
}),
);
}
}