Compare commits
3 Commits
2becf42487
...
8c9efd4371
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c9efd4371 | |||
| d710d6bac5 | |||
| 6b209077ef |
@@ -3,6 +3,9 @@ import { ApplicationConfig, isDevMode, provideZoneChangeDetection } from "@angul
|
|||||||
import { provideRouter } from "@angular/router";
|
import { provideRouter } from "@angular/router";
|
||||||
import { provideServiceWorker } from "@angular/service-worker";
|
import { provideServiceWorker } from "@angular/service-worker";
|
||||||
import { appRoutes } from "./app.routes";
|
import { appRoutes } from "./app.routes";
|
||||||
|
import { Parser } from "./services/parsers/parser";
|
||||||
|
import { MangalibParserService } from "./services/parsers/rulib/mangalib.parser.service";
|
||||||
|
import { SlashlibParserService } from "./services/parsers/rulib/slashlib.parser.service";
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [
|
providers: [
|
||||||
@@ -13,5 +16,7 @@ export const appConfig: ApplicationConfig = {
|
|||||||
registrationStrategy: "registerWhenStable:30000",
|
registrationStrategy: "registerWhenStable:30000",
|
||||||
}),
|
}),
|
||||||
provideHttpClient(withFetch()),
|
provideHttpClient(withFetch()),
|
||||||
|
{ provide: Parser, multi: true, useClass: MangalibParserService },
|
||||||
|
{ provide: Parser, multi: true, useClass: SlashlibParserService },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
.header {
|
.header {
|
||||||
transition: height 0.3s;
|
transition: height 0.3s;
|
||||||
}
|
}
|
||||||
|
:host {
|
||||||
|
z-index: 20;
|
||||||
|
position: fixed;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,22 +1,56 @@
|
|||||||
<h1>It's home component</h1>
|
@if (!search) {
|
||||||
<div class="flex flex-col items-center w-full px-3">
|
|
||||||
@if (loading) {
|
@if (loading) {
|
||||||
<h1>Loading...</h1>
|
<p class="text-5xl text-center mb-16">Подождите...</p>
|
||||||
|
} @else {
|
||||||
|
<p class="text-5xl text-center mb-10">Популярное:</p>
|
||||||
|
<div class="flex flex-col gap-3 items-center w-full px-4 overflow-x-hidden">
|
||||||
|
@for (popular of popularItems; track popular[0]) {
|
||||||
|
<p class="text-5xl text-center">{{ popular[0] }}</p>
|
||||||
|
<div class="w-full overflow-x-auto py-3">
|
||||||
|
<div class="flex flex-row items-center gap-4 h-[400px] w-max">
|
||||||
|
@for (popularTitle of popular[1]; track popularTitle.id) {
|
||||||
|
<a routerLink="/detail" [queryParams]="{ url: popularTitle.slug_url }" class="h-full">
|
||||||
|
<div
|
||||||
|
class="flex flex-col justify-around border-black rounded-md p-4 w-[400px] items-center border h-full flex-shrink-0"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
[src]="popularTitle.cover.thumbnail"
|
||||||
|
[alt]="popularTitle.slug"
|
||||||
|
class="w-[200px] h-auto aspect-auto"
|
||||||
|
/>
|
||||||
|
<p>{{ popularTitle.rus_name }}</p>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
@if (notFound && !loading) {
|
} @else {
|
||||||
<h1>Not found</h1>
|
<div class="flex flex-col items-center w-full px-3">
|
||||||
}
|
@if (loading) {
|
||||||
@for (item of items; track $index) {
|
<h1>Loading...</h1>
|
||||||
<a
|
}
|
||||||
routerLink="/detail"
|
@if (notFound && !loading) {
|
||||||
[queryParams]="{ url: item.slug_url }"
|
<h1>Not found</h1>
|
||||||
title="{{ item.name }}"
|
}
|
||||||
class="mb-6 max-w-[700px] w-full"
|
@for (item of items; track $index) {
|
||||||
>
|
<a
|
||||||
<div class="card flex flex-col items-center border-black border-2 rounded-md p-4 w-full">
|
routerLink="/detail"
|
||||||
<h1>{{ item.rus_name }}</h1>
|
[queryParams]="{ url: item.slug_url }"
|
||||||
<img [src]="item.cover.thumbnail" [alt]="item.slug" class="w-[200px] h-auto aspect-auto" />
|
title="{{ item.name }}"
|
||||||
</div>
|
class="mb-6 max-w-[700px] w-full"
|
||||||
</a>
|
>
|
||||||
}
|
<div class="card flex flex-col items-center border-black border-2 rounded-md p-4 w-full">
|
||||||
</div>
|
<h1>{{ item.rus_name }}</h1>
|
||||||
|
<img
|
||||||
|
[src]="item.cover.thumbnail"
|
||||||
|
[alt]="item.slug"
|
||||||
|
class="w-[200px] h-auto aspect-auto"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
||||||
import { ActivatedRoute, RouterLink } from "@angular/router";
|
import { ActivatedRoute, RouterLink } from "@angular/router";
|
||||||
import { Subject, takeUntil } from "rxjs";
|
import { map, Subject, Subscription, takeUntil } from "rxjs";
|
||||||
|
import { IRuLIBPopular } from "../../services/parsers/rulib/rulib.popular.dto";
|
||||||
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
import { Datum } from "../../services/parsers/rulib/rulib.search.dto";
|
||||||
import { SearchService } from "../../services/search.service";
|
import { SearchService } from "../../services/search.service";
|
||||||
|
|
||||||
@@ -16,33 +17,75 @@ export class HomeComponent implements OnDestroy, OnInit {
|
|||||||
@Input() items: Datum[] = [];
|
@Input() items: Datum[] = [];
|
||||||
loading = false;
|
loading = false;
|
||||||
notFound = false;
|
notFound = false;
|
||||||
|
search: string = "";
|
||||||
|
popularItemsMap: Map<string, IRuLIBPopular[]> = new Map<string, IRuLIBPopular[]>();
|
||||||
|
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
|
private popularSubscription = new Subscription();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private searchService: SearchService,
|
private searchService: SearchService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
) {}
|
) {
|
||||||
|
this.searchService.setMangalibParser();
|
||||||
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
|
this.popularSubscription.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPopular(parserName: string) {
|
||||||
|
this.searchService
|
||||||
|
.getPopular()
|
||||||
|
.pipe(
|
||||||
|
map((data) => data as IRuLIBPopular[]),
|
||||||
|
takeUntil(this.destroy$),
|
||||||
|
)
|
||||||
|
.subscribe({
|
||||||
|
next: (data) => {
|
||||||
|
this.popularItemsMap.set(parserName, data);
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPopularMangalib() {
|
||||||
|
this.searchService.setMangalibParser();
|
||||||
|
this.getPopular(this.searchService.getRuLibName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPopularSlashlib() {
|
||||||
|
this.searchService.setSlashlibParser();
|
||||||
|
this.getPopular(this.searchService.getRuLibName());
|
||||||
|
}
|
||||||
|
|
||||||
|
get popularItems() {
|
||||||
|
return Array.from(this.popularItemsMap.entries()).sort((a, b) => (a[0] > b[0] ? 1 : -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.queryParams.subscribe((params) => {
|
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||||
const search = params["search"];
|
this.search = params["search"] ?? "";
|
||||||
if (search) {
|
this.items = [];
|
||||||
|
this.loading = true;
|
||||||
|
if (this.search) {
|
||||||
this.searchService.setMangalibParser();
|
this.searchService.setMangalibParser();
|
||||||
this.loading = true;
|
|
||||||
this.searchService
|
this.searchService
|
||||||
.search(search)
|
.search(this.search)
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe((data) => {
|
.subscribe((data) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.items = data.data;
|
this.items = data.data;
|
||||||
this.notFound = this.items.length === 0;
|
this.notFound = this.items.length === 0;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.getPopularMangalib();
|
||||||
|
this.getPopularSlashlib();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,11 @@
|
|||||||
@if (pages.length > 0 && currentPage) {
|
@if (pages.length > 0 && currentPage) {
|
||||||
<div [class]="imageContainerClass">
|
<div [class]="imageContainerClass">
|
||||||
@if (!isManhwa) {
|
@if (!isManhwa) {
|
||||||
<app-scale-image [imageSrc]="currentPage.imageUrl"></app-scale-image>
|
<app-scale-image
|
||||||
|
[imageSrc]="currentPage.imageUrl"
|
||||||
|
(clickLeft)="prevPage()"
|
||||||
|
(clickRight)="nextPage()"
|
||||||
|
></app-scale-image>
|
||||||
} @else {
|
} @else {
|
||||||
@for (page of manhwaPages; track page.id) {
|
@for (page of manhwaPages; track page.id) {
|
||||||
<app-scale-image
|
<app-scale-image
|
||||||
@@ -26,7 +30,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center justify-center space-x-4 my-10">
|
<div class="flex items-center justify-center space-x-4 mt-[6rem]">
|
||||||
<button (click)="prevPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg">
|
<button (click)="prevPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg">
|
||||||
←
|
←
|
||||||
</button>
|
</button>
|
||||||
@@ -35,8 +39,10 @@
|
|||||||
→
|
→
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="hidden md:block md:fixed right-10 top-[50%]">
|
@if (isManhwa) {
|
||||||
{{ currentPageIndex + 1 }} / {{ pages.length }}
|
<div class="hidden md:block md:fixed right-10 top-[50%]">
|
||||||
</div>
|
{{ currentPageIndex + 1 }} / {{ pages.length }}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -240,6 +240,6 @@ export class ReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get imageContainerClass() {
|
get imageContainerClass() {
|
||||||
return `${this.isManhwa ? "h-auto" : "h-[70vh]"} w-[95vw] md:w-[450px] flex flex-col`;
|
return `${this.isManhwa ? "h-auto" : "h-[70vh]"} w-screen md:w-[450px] flex flex-col`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="image-container" #container>
|
<div class="image-container" #container>
|
||||||
@if (imageSrc) {
|
@if (imageSrc) {
|
||||||
<img #image [src]="imageSrc" (load)="onImageLoad()" alt="Manga page" />
|
<img #image [src]="imageSrc" (load)="onImageLoad()" alt="Manga page" class="cursor-pointer" />
|
||||||
} @else {
|
} @else {
|
||||||
<div class="h-screen flex flex-col items-center justify-center"><h1>Loading...</h1></div>
|
<div class="h-screen flex flex-col items-center justify-center"><h1>Loading...</h1></div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
Output,
|
Output,
|
||||||
|
QueryList,
|
||||||
ViewChild,
|
ViewChild,
|
||||||
|
ViewChildren,
|
||||||
} from "@angular/core";
|
} from "@angular/core";
|
||||||
import { Subscription, debounceTime, fromEvent } from "rxjs";
|
import { Subject, Subscription, debounceTime, fromEvent, map, takeUntil } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-scale-image",
|
selector: "app-scale-image",
|
||||||
@@ -20,10 +22,16 @@ export class ScaleImageComponent implements AfterViewInit, OnDestroy {
|
|||||||
@Input({ required: true }) imageSrc: string = "";
|
@Input({ required: true }) imageSrc: string = "";
|
||||||
@ViewChild("container", { static: true }) containerRef: ElementRef | null = null;
|
@ViewChild("container", { static: true }) containerRef: ElementRef | null = null;
|
||||||
@ViewChild("image", { static: true }) imageRef: ElementRef | null = null;
|
@ViewChild("image", { static: true }) imageRef: ElementRef | null = null;
|
||||||
|
@ViewChildren("image") imageList: QueryList<ElementRef<HTMLImageElement>> = new QueryList<
|
||||||
|
ElementRef<HTMLImageElement>
|
||||||
|
>();
|
||||||
@Output() view = new EventEmitter<void>();
|
@Output() view = new EventEmitter<void>();
|
||||||
|
@Output() clickLeft = new EventEmitter<void>();
|
||||||
|
@Output() clickRight = new EventEmitter<void>();
|
||||||
@Input() host: ElementRef | null = null;
|
@Input() host: ElementRef | null = null;
|
||||||
@Input() hostScrollable: boolean = false;
|
@Input() hostScrollable: boolean = false;
|
||||||
|
|
||||||
|
private destroy$ = new Subject<void>();
|
||||||
private resizeSubscription: Subscription = new Subscription();
|
private resizeSubscription: Subscription = new Subscription();
|
||||||
private observer!: IntersectionObserver;
|
private observer!: IntersectionObserver;
|
||||||
|
|
||||||
@@ -39,11 +47,37 @@ export class ScaleImageComponent implements AfterViewInit, OnDestroy {
|
|||||||
);
|
);
|
||||||
if (this.containerRef) this.observer.observe(this.containerRef.nativeElement);
|
if (this.containerRef) this.observer.observe(this.containerRef.nativeElement);
|
||||||
}
|
}
|
||||||
|
if (!this.host) {
|
||||||
|
this.imageList.changes
|
||||||
|
.pipe<QueryList<ElementRef<HTMLImageElement>>>(takeUntil(this.destroy$))
|
||||||
|
.subscribe((imageList) => {
|
||||||
|
fromEvent(imageList.first.nativeElement, "click")
|
||||||
|
.pipe(
|
||||||
|
takeUntil(this.destroy$),
|
||||||
|
map((e) => e as MouseEvent),
|
||||||
|
)
|
||||||
|
.subscribe((e) => {
|
||||||
|
const target = e.target as HTMLImageElement;
|
||||||
|
const imageWidth = target.clientWidth;
|
||||||
|
const clickX = e.offsetX;
|
||||||
|
if (clickX < imageWidth / 2) this.clickLeft.emit();
|
||||||
|
else this.clickRight.emit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// fromEvent(this.imageRef.first.nativeElement, "click")
|
||||||
|
// .pipe(takeUntil(this.destroy$))
|
||||||
|
// .subscribe((e) => {
|
||||||
|
// console.log(e);
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
if (this.resizeSubscription) this.resizeSubscription.unsubscribe();
|
if (this.resizeSubscription) this.resizeSubscription.unsubscribe();
|
||||||
if (this.observer) this.observer.disconnect();
|
if (this.observer) this.observer.disconnect();
|
||||||
|
this.destroy$.next();
|
||||||
|
this.destroy$.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
onImageLoad() {
|
onImageLoad() {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export enum EParser {
|
||||||
|
MangaLib = 0,
|
||||||
|
SlashLib = 1,
|
||||||
|
}
|
||||||
@@ -15,4 +15,6 @@ export abstract class Parser {
|
|||||||
abstract getChapters(url: string): Observable<object>;
|
abstract getChapters(url: string): Observable<object>;
|
||||||
|
|
||||||
abstract getChapter(url: string, chapter: string, volume: string): Observable<object>;
|
abstract getChapter(url: string, chapter: string, volume: string): Observable<object>;
|
||||||
|
|
||||||
|
abstract getPopular(): Observable<object[]>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { RulibAuthService } from "./rulib.auth.service";
|
|||||||
import { IRulibChapterResult } from "./rulib.chapter.dto";
|
import { IRulibChapterResult } from "./rulib.chapter.dto";
|
||||||
import { IRulibChaptersResult } from "./rulib.chapters.dto";
|
import { IRulibChaptersResult } from "./rulib.chapters.dto";
|
||||||
import { IRulibDetailResult } from "./rulib.detail.dto";
|
import { IRulibDetailResult } from "./rulib.detail.dto";
|
||||||
|
import { IRuLIBPopular } from "./rulib.popular.dto";
|
||||||
import { IRulibSearchResult } from "./rulib.search.dto";
|
import { IRulibSearchResult } from "./rulib.search.dto";
|
||||||
|
|
||||||
//TODO: Make abstract classes
|
//TODO: Make abstract classes
|
||||||
@@ -98,4 +99,21 @@ export class LibSocialParserService extends Parser {
|
|||||||
catchError((error) => throwError(() => `Now found ${error}`)),
|
catchError((error) => throwError(() => `Now found ${error}`)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPopular(): Observable<IRuLIBPopular[]> {
|
||||||
|
return this.http
|
||||||
|
.get<{ data: { popular: [] } }>(`${this.url}/api/`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer " + this.rulibAuthService.getToken(),
|
||||||
|
"Site-Id": this.site_id,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.pipe(
|
||||||
|
map((data) => {
|
||||||
|
const res = data.data.popular as IRuLIBPopular[];
|
||||||
|
return res;
|
||||||
|
}),
|
||||||
|
catchError((error) => throwError(() => `Now found ${error}`)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
export interface IRuLIBPopular {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
rus_name: string;
|
||||||
|
eng_name: string;
|
||||||
|
slug: string;
|
||||||
|
slug_url: string;
|
||||||
|
cover: Cover;
|
||||||
|
ageRestriction: AgeRestriction;
|
||||||
|
site: number;
|
||||||
|
type: AgeRestriction;
|
||||||
|
rating: Rating;
|
||||||
|
last_item_at: Date;
|
||||||
|
metadata: Metadata;
|
||||||
|
model: Model;
|
||||||
|
status: AgeRestriction;
|
||||||
|
releaseDateString: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AgeRestriction {
|
||||||
|
id: number;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Cover {
|
||||||
|
filename: string;
|
||||||
|
thumbnail: string;
|
||||||
|
default: string;
|
||||||
|
md: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Metadata {
|
||||||
|
last_item: LastItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LastItem {
|
||||||
|
id: number;
|
||||||
|
number: string;
|
||||||
|
volume: number | string;
|
||||||
|
name: string;
|
||||||
|
branch_id: number | null;
|
||||||
|
status?: null;
|
||||||
|
type?: string;
|
||||||
|
number_secondary?: string;
|
||||||
|
slug?: number;
|
||||||
|
manga_id?: null;
|
||||||
|
created_at?: Date;
|
||||||
|
likes_count?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Model {
|
||||||
|
Manga = "manga",
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Rating {
|
||||||
|
average: string;
|
||||||
|
averageFormated: string;
|
||||||
|
votes: number;
|
||||||
|
votesFormated: string;
|
||||||
|
user: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { ParserDecorator } from "../decorators/parser.decorator";
|
||||||
|
import { ESiteUrls } from "../urls";
|
||||||
|
import { LibSocialParserService } from "./lib.social.parser.service";
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: "root",
|
||||||
|
})
|
||||||
|
@ParserDecorator({ site_name: "Slashlib", url: ESiteUrls.LIB_SOCIAL, site_id: 2 })
|
||||||
|
export class SlashlibParserService extends LibSocialParserService {}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export enum ESiteUrls {
|
export enum ESiteUrls {
|
||||||
LIB_SOCIAL = "https://api.lib.social",
|
LIB_SOCIAL = "https://api.lib.social",
|
||||||
MANGALIB = "https://api.mangalib.me",
|
MANGALIB = "https://api.mangalib.me",
|
||||||
|
SLASHLIB = "https://api.slashlib.me",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from "@angular/common/http";
|
||||||
import { Injectable } from "@angular/core";
|
import { Inject, Injectable } from "@angular/core";
|
||||||
import { Observable, map } from "rxjs";
|
import { Observable, map } from "rxjs";
|
||||||
|
import { EParser } from "./parsers/enums/parser";
|
||||||
import { Parser } from "./parsers/parser";
|
import { Parser } from "./parsers/parser";
|
||||||
import { MangalibParserService } from "./parsers/rulib/mangalib.parser.service";
|
|
||||||
import { IRulibChapterResult } from "./parsers/rulib/rulib.chapter.dto";
|
import { IRulibChapterResult } from "./parsers/rulib/rulib.chapter.dto";
|
||||||
import { IRulibChaptersResult } from "./parsers/rulib/rulib.chapters.dto";
|
import { IRulibChaptersResult } from "./parsers/rulib/rulib.chapters.dto";
|
||||||
import { IRulibDetailResult } from "./parsers/rulib/rulib.detail.dto";
|
import { IRulibDetailResult } from "./parsers/rulib/rulib.detail.dto";
|
||||||
@@ -13,11 +13,19 @@ export class SearchService {
|
|||||||
private parser!: Parser;
|
private parser!: Parser;
|
||||||
constructor(
|
constructor(
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
private mangalibParser: MangalibParserService,
|
@Inject(Parser) private parsers: Parser[],
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
setMangalibParser() {
|
setMangalibParser() {
|
||||||
this.parser = this.mangalibParser;
|
this.setParser(EParser.MangaLib);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSlashlibParser() {
|
||||||
|
this.setParser(EParser.SlashLib);
|
||||||
|
}
|
||||||
|
|
||||||
|
private setParser(parser: EParser) {
|
||||||
|
this.parser = this.parsers[parser];
|
||||||
}
|
}
|
||||||
|
|
||||||
search(query: string): Observable<IRulibSearchResult> {
|
search(query: string): Observable<IRulibSearchResult> {
|
||||||
@@ -69,4 +77,13 @@ export class SearchService {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
return (this.parser as any).isManhwa(url);
|
return (this.parser as any).isManhwa(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPopular(): Observable<object[]> {
|
||||||
|
return this.parser.getPopular();
|
||||||
|
}
|
||||||
|
|
||||||
|
getRuLibName(): string {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return (this.parser as any).site_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user