Compare commits
13 Commits
5a4206a81e
...
feature/ma
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b209077ef | |||
| 2becf42487 | |||
| 7b2c6d9fc8 | |||
| 00213d25a1 | |||
| 5465d1635c | |||
| d414223df2 | |||
| c427c6d0b4 | |||
| 4105933098 | |||
| 0fea62b639 | |||
| e040edb5bd | |||
| 8c87401482 | |||
| c9c959ce76 | |||
| 45389364ff |
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -9,5 +9,8 @@
|
|||||||
// "**/node_modules": true,
|
// "**/node_modules": true,
|
||||||
"**/.angular": true
|
"**/.angular": true
|
||||||
},
|
},
|
||||||
"editor.formatOnSave": true
|
"editor.formatOnSave": true,
|
||||||
|
"cSpell.words": [
|
||||||
|
"Manhwa"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -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 },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ export class DetailComponent implements AfterViewInit, OnDestroy {
|
|||||||
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||||
const url = params["url"];
|
const url = params["url"];
|
||||||
if (url) {
|
if (url) {
|
||||||
|
this.searchService.setMangalibParser();
|
||||||
this.getDetails(url);
|
this.getDetails(url);
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(["/"]);
|
this.router.navigate(["/"]);
|
||||||
|
|||||||
@@ -1,28 +1,64 @@
|
|||||||
<div
|
<div
|
||||||
class="header fixed flex justify-between w-full p-2 bg-gray-700 md:h-8 items-center md:flex-row flex-col md:gap-0 gap-3 text-xl md:text-base"
|
[class]="
|
||||||
|
'header fixed flex justify-between w-full px-2 bg-gray-700 md:h-8 items-center md:flex-row flex-col md:gap-0 gap-3 text-xl md:text-base ' +
|
||||||
|
(menuOpened ? 'h-screen' : '')
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<div class="flex justify-between flex-row w-full align-middle">
|
<div class="flex justify-between flex-row w-full align-middle h-8 items-center">
|
||||||
<a href="/"><h1 class="text-white" title="Main page">NwaifuAnime</h1></a>
|
<div class="flex flex-row gap-3 h-full items-center">
|
||||||
|
<a routerLink="/" class="h-full px-2 flex justify-center items-center justify-self-center"
|
||||||
|
><h1 class="text-white" title="Main page">NwaifuAnime</h1></a
|
||||||
|
>
|
||||||
|
<div class="border-l border-white h-full"></div>
|
||||||
|
<div class="flex-row gap-3 md:flex hidden h-full items-center">
|
||||||
|
<a
|
||||||
|
routerLink="/auth"
|
||||||
|
class="h-full px-2 flex justify-center items-center hover:bg-gray-600 transition ease-in-out delay-150 duration-300"
|
||||||
|
><h2 class="text-white" title="Auth page">Auth</h2></a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Search bar on small screens -->
|
<!-- Search bar on small screens -->
|
||||||
<button type="button" class="md:hidden" (click)="changeMenu()">
|
<button
|
||||||
|
type="button"
|
||||||
|
class="md:hidden flex justify-center items-center px-2"
|
||||||
|
(click)="changeMenu()"
|
||||||
|
>
|
||||||
<i [class]="menuBtnClass"></i>
|
<i [class]="menuBtnClass"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Search bar on big screens -->
|
<div
|
||||||
<div [class]="searchBarClass">
|
class="flex flex-col md:flex-row md:justify-end justify-center items-center gap-3 md:w-[50vw] h-full w-full"
|
||||||
<input
|
>
|
||||||
type="search"
|
<!-- Search bar on big screens -->
|
||||||
#searchInput
|
<div [class]="searchBarClass">
|
||||||
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
|
<input
|
||||||
(keydown.enter)="search()"
|
type="search"
|
||||||
/>
|
#searchInput
|
||||||
<button
|
class="outline-none ps-1 text-sm leading-6 w-full border-0 bg-transparent border-r border-gray-700"
|
||||||
class="align-middle w-[100px] text-center border-0 flex flex-col items-center justify-center"
|
(keydown.enter)="search()"
|
||||||
type="submit"
|
/>
|
||||||
(click)="search()"
|
<button
|
||||||
|
class="align-middle w-[100px] text-center border-0 flex flex-col items-center justify-center"
|
||||||
|
type="submit"
|
||||||
|
(click)="search()"
|
||||||
|
>
|
||||||
|
<span class="text-sm text-black h-full">Поиск</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
[class]="
|
||||||
|
'flex flex-col w-full justify-start items-center md:hidden overflow-hidden ' +
|
||||||
|
(menuOpened ? 'h-auto' : 'h-0')
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<span class="text-sm text-black h-full">Поиск</span>
|
<a
|
||||||
</button>
|
routerLink="/auth"
|
||||||
|
class="h-full px-2 flex justify-center items-center hover:bg-gray-600 transition ease-in-out delay-150 duration-300"
|
||||||
|
><h2 class="text-white" title="Auth page">Auth</h2></a
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
|
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from "@angular/core";
|
||||||
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
|
import { ActivatedRoute, NavigationEnd, Router, RouterLink } from "@angular/router";
|
||||||
import { Subject, filter, takeUntil } from "rxjs";
|
import { Subject, filter, takeUntil } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -8,7 +8,7 @@ import { Subject, filter, takeUntil } from "rxjs";
|
|||||||
templateUrl: "./header.component.html",
|
templateUrl: "./header.component.html",
|
||||||
styleUrls: ["./header.component.less"],
|
styleUrls: ["./header.component.less"],
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule],
|
imports: [CommonModule, RouterLink],
|
||||||
})
|
})
|
||||||
export class HeaderComponent implements AfterViewInit, OnDestroy {
|
export class HeaderComponent implements AfterViewInit, OnDestroy {
|
||||||
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
|
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
|
||||||
@@ -37,7 +37,7 @@ export class HeaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get searchBarClass(): string {
|
get searchBarClass(): string {
|
||||||
return `search-bar bg-slate-300 md:w-[50%] w-full md:m-0 ms-2 me-2 md:h-6 h-10 md:flex justify-start flex-row items-center rounded-md ${this.menuOpened ? "flex" : "hidden"}`;
|
return `search-bar bg-slate-300 md:w-full w-full md:m-0 ms-2 me-2 md:h-6 h-10 md:flex justify-start flex-row items-center rounded-md ${this.menuOpened ? "flex" : "hidden"}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
search() {
|
search() {
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
<h1>It's home component</h1>
|
<h1>It's home component</h1>
|
||||||
|
@if (!search) {
|
||||||
|
@for (popular of popularItems; track popular[0]) {
|
||||||
|
<p class="text-5xl">{{ popular[0] }}</p>
|
||||||
|
@for (popularTitle of popular[1]; track popularTitle.id) {
|
||||||
|
<p>{{ popularTitle.rus_name }}</p>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
<div class="flex flex-col items-center w-full px-3">
|
<div class="flex flex-col items-center w-full px-3">
|
||||||
|
@if (loading) {
|
||||||
|
<h1>Loading...</h1>
|
||||||
|
}
|
||||||
|
@if (notFound && !loading) {
|
||||||
|
<h1>Not found</h1>
|
||||||
|
}
|
||||||
@for (item of items; track $index) {
|
@for (item of items; track $index) {
|
||||||
<a
|
<a
|
||||||
routerLink="/detail"
|
routerLink="/detail"
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { AfterViewInit, Component, Input, OnDestroy } 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";
|
||||||
|
|
||||||
@@ -12,31 +13,77 @@ import { SearchService } from "../../services/search.service";
|
|||||||
styleUrls: ["./home.component.less"],
|
styleUrls: ["./home.component.less"],
|
||||||
imports: [CommonModule, RouterLink],
|
imports: [CommonModule, RouterLink],
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnDestroy, AfterViewInit {
|
export class HomeComponent implements OnDestroy, OnInit {
|
||||||
@Input() items: Datum[] = [];
|
@Input() items: Datum[] = [];
|
||||||
|
loading = 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
private getPopular() {
|
||||||
this.route.queryParams.subscribe((params) => {
|
if (!this.popularSubscription.closed) this.popularSubscription.unsubscribe();
|
||||||
const search = params["search"];
|
this.popularSubscription = this.searchService
|
||||||
if (search) {
|
.getPopular()
|
||||||
|
.pipe(map((data) => data as IRuLIBPopular[]))
|
||||||
|
.subscribe({
|
||||||
|
next: (data) => {
|
||||||
|
this.popularItemsMap.set(this.searchService.getRuLibName(), data);
|
||||||
|
console.log(this.popularItemsMap);
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getPopularMangalib() {
|
||||||
|
this.searchService.setMangalibParser();
|
||||||
|
this.getPopular();
|
||||||
|
}
|
||||||
|
|
||||||
|
getPopularSlashlib() {
|
||||||
|
this.searchService.setSlashlibParser();
|
||||||
|
this.getPopular();
|
||||||
|
}
|
||||||
|
|
||||||
|
get popularItems() {
|
||||||
|
return this.popularItemsMap.entries();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||||
|
this.search = params["search"] ?? "";
|
||||||
|
this.items = [];
|
||||||
|
if (this.search) {
|
||||||
|
this.loading = true;
|
||||||
|
this.searchService.setMangalibParser();
|
||||||
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.items = data.data;
|
this.items = data.data;
|
||||||
|
this.notFound = this.items.length === 0;
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.getPopularMangalib();
|
||||||
|
this.getPopularSlashlib();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,18 @@
|
|||||||
<h3>{{ currentChapterInfo?.number }}. {{ currentChapterInfo?.name || "Нет названия" }}</h3>
|
<h3>{{ currentChapterInfo?.number }}. {{ currentChapterInfo?.name || "Нет названия" }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
@if (pages.length > 0 && cachedPages[currentPageIndex]) {
|
@if (pages.length > 0 && currentPage) {
|
||||||
<div [class]="imageContainerClass">
|
<div [class]="imageContainerClass">
|
||||||
@if (!isManhwa$.value) {
|
@if (!isManhwa) {
|
||||||
<app-scale-image [imageSrc]="imageUrl"></app-scale-image>
|
<app-scale-image [imageSrc]="currentPage.imageUrl"></app-scale-image>
|
||||||
} @else {
|
} @else {
|
||||||
@for (page of manhwaPages; track page.id) {
|
@for (page of manhwaPages; track page.id) {
|
||||||
<app-scale-image [imageSrc]="page.imageUrl"></app-scale-image>
|
<app-scale-image
|
||||||
|
[imageSrc]="page.imageUrl"
|
||||||
|
[host]="host"
|
||||||
|
(view)="loadPage(page.index)"
|
||||||
|
[hostScrollable]="isHostScrollable()"
|
||||||
|
></app-scale-image>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -25,10 +30,13 @@
|
|||||||
<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>
|
||||||
<p *ngIf="!isManhwa$.value">{{ pages[currentPageIndex].slug }} / {{ pages.length }}</p>
|
<p *ngIf="!isManhwa">{{ pages[currentPageIndex].slug }} / {{ pages.length }}</p>
|
||||||
<button (click)="nextPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg">
|
<button (click)="nextPage()" class="p-3 text-white bg-slate-600 w-[100px] rounded-lg">
|
||||||
→
|
→
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="hidden md:block md:fixed right-10 top-[50%]">
|
||||||
|
{{ currentPageIndex + 1 }} / {{ pages.length }}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule, isPlatformBrowser } from "@angular/common";
|
||||||
import { AfterViewInit, Component, OnDestroy } from "@angular/core";
|
|
||||||
import { ActivatedRoute, Router, RouterLink } from "@angular/router";
|
|
||||||
import {
|
import {
|
||||||
BehaviorSubject,
|
Component,
|
||||||
Observable,
|
ElementRef,
|
||||||
Subject,
|
HostListener,
|
||||||
Subscription,
|
Inject,
|
||||||
fromEvent,
|
OnDestroy,
|
||||||
map,
|
OnInit,
|
||||||
takeUntil,
|
PLATFORM_ID,
|
||||||
throttleTime,
|
} from "@angular/core";
|
||||||
} from "rxjs";
|
import { ActivatedRoute, Router, RouterLink } from "@angular/router";
|
||||||
|
import { Subject, takeUntil } from "rxjs";
|
||||||
import { Chapter, Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
import { Chapter, Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
||||||
import { IRulibChapter } from "../../services/parsers/rulib/rulib.chapters.dto";
|
import { IRulibChapter } from "../../services/parsers/rulib/rulib.chapters.dto";
|
||||||
import { SearchService } from "../../services/search.service";
|
import { SearchService } from "../../services/search.service";
|
||||||
@@ -24,104 +23,78 @@ import { CachedPage, CachedPages } from "./reader.dto";
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, ScaleImageComponent, RouterLink],
|
imports: [CommonModule, ScaleImageComponent, RouterLink],
|
||||||
})
|
})
|
||||||
export class ReaderComponent implements AfterViewInit, OnDestroy {
|
export class ReaderComponent implements OnInit, OnDestroy {
|
||||||
//FIXME: Scrolling to top when manhwa
|
|
||||||
pages: Page[] = [];
|
pages: Page[] = [];
|
||||||
currentPageIndex = 0;
|
currentPageIndex = 0;
|
||||||
cachedPages: CachedPages = {};
|
cachedPages: CachedPages = new Map<number, CachedPage>();
|
||||||
imageUrl: string = "";
|
imageUrl: string = "";
|
||||||
isManhwa = false;
|
isManhwa = false;
|
||||||
currentChapterInfo: Chapter | null = null;
|
currentChapterInfo: Chapter | null = null;
|
||||||
url = "";
|
url = "";
|
||||||
isManhwa$ = new BehaviorSubject<boolean>(false);
|
|
||||||
private chaptersInfo: IRulibChapter[] = [];
|
private chaptersInfo: IRulibChapter[] = [];
|
||||||
private chapterNum: number = 0;
|
private chapterNum: number = 0;
|
||||||
private chapterVol: number = 0;
|
private chapterVol: number = 0;
|
||||||
private fromTowards = false;
|
private fromTowards = false;
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
private scrollSubscription = new Subscription();
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private searchService: SearchService,
|
private searchService: SearchService,
|
||||||
|
public host: ElementRef,
|
||||||
|
@Inject(PLATFORM_ID) private platformId: object,
|
||||||
) {}
|
) {}
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.destroy$.next();
|
this.destroy$.next();
|
||||||
this.destroy$.complete();
|
this.destroy$.complete();
|
||||||
this.isManhwa$.complete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get manhwaPages() {
|
get manhwaPages() {
|
||||||
return Object.values(this.cachedPages) as CachedPage[];
|
return this.cachedPages.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
|
||||||
const url = params["url"];
|
const url = params["url"];
|
||||||
const chapter = params["chapter"];
|
const chapter = params["chapter"];
|
||||||
const volume = params["volume"];
|
const volume = params["volume"];
|
||||||
const fromTowards = params["from_towards"];
|
const fromTowards = params["from_towards"];
|
||||||
if (url && chapter && volume) {
|
if (url && chapter && volume) {
|
||||||
|
this.searchService.setMangalibParser();
|
||||||
if (fromTowards) this.fromTowards = Boolean(+fromTowards);
|
if (fromTowards) this.fromTowards = Boolean(+fromTowards);
|
||||||
else this.fromTowards = false;
|
else this.fromTowards = false;
|
||||||
this.chapterNum = +chapter;
|
this.chapterNum = +chapter;
|
||||||
this.chapterVol = +volume;
|
this.chapterVol = +volume;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.loadChapter(url, chapter, volume);
|
|
||||||
this.searchService
|
this.searchService
|
||||||
.getChapters(url)
|
.getChapters(url)
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe((data) => {
|
.subscribe((data) => {
|
||||||
this.chaptersInfo = data.data;
|
this.chaptersInfo = data.data;
|
||||||
});
|
});
|
||||||
|
this.searchService
|
||||||
|
.isManhwa(url)
|
||||||
|
.pipe(takeUntil(this.destroy$))
|
||||||
|
.subscribe((data) => {
|
||||||
|
this.isManhwa = data;
|
||||||
|
this.loadChapter(url, chapter, volume);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(["/"]);
|
this.router.navigate(["/"]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.isManhwa$.pipe(takeUntil(this.destroy$)).subscribe((isManhwa) => {
|
|
||||||
this.isManhwa = isManhwa;
|
|
||||||
if (isManhwa) this.initManhwaScroll();
|
|
||||||
else this.noManhwaScroll();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleScrollManhwa(event: Event) {
|
public isHostScrollable(): boolean {
|
||||||
if (event.currentTarget) {
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
if (
|
const style = window.getComputedStyle(this.host.nativeElement);
|
||||||
(event.currentTarget as HTMLElement).scrollHeight -
|
return (
|
||||||
(event.currentTarget as HTMLElement).scrollTop <
|
style.getPropertyValue("overflow") === "auto" ||
|
||||||
3000
|
style.getPropertyValue("overflow-y") === "scroll"
|
||||||
) {
|
);
|
||||||
this.loadPage(this.currentPageIndex + 1);
|
|
||||||
console.log("load");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private initManhwaScroll() {
|
return false;
|
||||||
const component = document.querySelector("app-reader");
|
|
||||||
if (component && this.isManhwa) {
|
|
||||||
this.scrollSubscription = fromEvent(component, "scroll")
|
|
||||||
.pipe(
|
|
||||||
throttleTime(300),
|
|
||||||
map((data) => {
|
|
||||||
console.log("throttle");
|
|
||||||
return data;
|
|
||||||
}),
|
|
||||||
takeUntil(this.destroy$),
|
|
||||||
)
|
|
||||||
.subscribe((event) => {
|
|
||||||
this.handleScrollManhwa(event);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private noManhwaScroll() {
|
|
||||||
const component = document.querySelector("app-reader");
|
|
||||||
if (component && !this.isManhwa) {
|
|
||||||
this.scrollSubscription.unsubscribe();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backToTitle() {
|
backToTitle() {
|
||||||
@@ -136,6 +109,15 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
next: (data) => {
|
next: (data) => {
|
||||||
this.currentChapterInfo = data.data;
|
this.currentChapterInfo = data.data;
|
||||||
this.pages = data.data.pages;
|
this.pages = data.data.pages;
|
||||||
|
this.pages.forEach((page, index) => {
|
||||||
|
this.cachedPages.set(index, {
|
||||||
|
...page,
|
||||||
|
imageUrl: "",
|
||||||
|
isManhwa: this.isManhwa,
|
||||||
|
index,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.loadPage(0);
|
||||||
if (this.fromTowards) {
|
if (this.fromTowards) {
|
||||||
this.currentPageIndex = this.pages.length - 1;
|
this.currentPageIndex = this.pages.length - 1;
|
||||||
this.loadPage(this.pages.length - 1); // Загрузить последнюю страницу при открытии главы
|
this.loadPage(this.pages.length - 1); // Загрузить последнюю страницу при открытии главы
|
||||||
@@ -148,40 +130,61 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public intersectionLoadPage(id: number) {
|
||||||
|
const data = Array.from(this.cachedPages.values()).find((page) => page.id === id)!;
|
||||||
|
this.fetchPage(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private loadPageByIndex(index: number) {
|
||||||
|
const data = this.cachedPages.get(index)!;
|
||||||
|
this.fetchPage(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
get currentPage() {
|
||||||
|
return this.cachedPages.get(this.currentPageIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private fetchPage(page: CachedPage) {
|
||||||
|
if (!page.imageUrl)
|
||||||
|
this.searchService
|
||||||
|
.getImageData(this.searchService.getImageServer() + page.url)
|
||||||
|
.pipe(takeUntil(this.destroy$))
|
||||||
|
.subscribe((data) => {
|
||||||
|
const url = this.getImageUrl(data);
|
||||||
|
this.cachedPages.set(page.index, {
|
||||||
|
...page,
|
||||||
|
imageUrl: url,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private cachePage(index: number) {
|
||||||
|
for (let i = index; i < Math.min(index + 2, this.cachedPages.size); i++) {
|
||||||
|
this.loadPageByIndex(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private clearCache(index: number) {
|
||||||
|
for (let i = 0; i <= index; i++) {
|
||||||
|
const imgUrl = this.cachedPages.get(i)!.imageUrl;
|
||||||
|
this.cachedPages.get(i)!.imageUrl = "";
|
||||||
|
URL.revokeObjectURL(imgUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loadPage(index: number) {
|
loadPage(index: number) {
|
||||||
if (index >= 0 && index < this.pages.length) {
|
if (index >= 0 && index < this.pages.length) {
|
||||||
this.currentPageIndex = index;
|
this.currentPageIndex = index;
|
||||||
this.cachePage(index); // Кэшируем текущую и соседние страницы
|
this.cachePage(index);
|
||||||
if (!this.isManhwa$.value) this.unloadCachedPages(index); // Сгружаем ненужные страницы из кэша
|
this.clearCache(index - 2);
|
||||||
if (!this.isManhwa$.value) {
|
} else if (index == this.cachedPages.size) {
|
||||||
console.log("scroll");
|
|
||||||
const container = document.querySelector("app-reader");
|
|
||||||
if (container) {
|
|
||||||
container.scrollTo({
|
|
||||||
top: 0,
|
|
||||||
behavior: "smooth",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!this.cachedPages[index]?.imageData) {
|
|
||||||
// Если страница не закэширована, загружаем её
|
|
||||||
this.fetchAndCachePage(index)
|
|
||||||
.pipe(takeUntil(this.destroy$))
|
|
||||||
.subscribe(() => {
|
|
||||||
this.updateImage();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Если страница уже в кэше, просто обновляем изображение
|
|
||||||
this.updateImage();
|
|
||||||
}
|
|
||||||
} else if (index == this.pages.length && !this.isManhwa$.value) {
|
|
||||||
const thisChapterIndex = this.chaptersInfo.findIndex((chapter) => {
|
const thisChapterIndex = this.chaptersInfo.findIndex((chapter) => {
|
||||||
return +chapter.number === this.chapterNum && +chapter.volume === this.chapterVol;
|
return +chapter.number === this.chapterNum && +chapter.volume === this.chapterVol;
|
||||||
});
|
});
|
||||||
const nextChapterIndex = Math.min(thisChapterIndex + 1, this.chaptersInfo.length - 1);
|
const nextChapterIndex = Math.min(thisChapterIndex + 1, this.chaptersInfo.length - 1);
|
||||||
const nextChapter = this.chaptersInfo[nextChapterIndex];
|
const nextChapter = this.chaptersInfo[nextChapterIndex];
|
||||||
if (nextChapter !== this.chaptersInfo[thisChapterIndex]) {
|
if (nextChapter !== this.chaptersInfo[thisChapterIndex]) {
|
||||||
this.cachedPages = [];
|
this.cachedPages.clear();
|
||||||
this.router.navigate(["/", "reader"], {
|
this.router.navigate(["/", "reader"], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
@@ -190,14 +193,14 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (index == -1 && !this.isManhwa$.value) {
|
} else if (index == -1) {
|
||||||
const thisChapterIndex = this.chaptersInfo.findIndex((chapter) => {
|
const thisChapterIndex = this.chaptersInfo.findIndex((chapter) => {
|
||||||
return +chapter.number === this.chapterNum && +chapter.volume === this.chapterVol;
|
return +chapter.number === this.chapterNum && +chapter.volume === this.chapterVol;
|
||||||
});
|
});
|
||||||
const prevChapterIndex = Math.max(thisChapterIndex - 1, 0);
|
const prevChapterIndex = Math.max(thisChapterIndex - 1, 0);
|
||||||
const prevChapter = this.chaptersInfo[prevChapterIndex];
|
const prevChapter = this.chaptersInfo[prevChapterIndex];
|
||||||
if (prevChapter !== this.chaptersInfo[thisChapterIndex]) {
|
if (prevChapter !== this.chaptersInfo[thisChapterIndex]) {
|
||||||
this.cachedPages = [];
|
this.cachedPages.clear();
|
||||||
this.router.navigate(["/", "reader"], {
|
this.router.navigate(["/", "reader"], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
url: this.url,
|
url: this.url,
|
||||||
@@ -210,59 +213,16 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Кэширование текущей страницы и несколько соседних для ускорения процесса навигации по страницам
|
@HostListener("window:keydown", ["$event"])
|
||||||
private cachePage(index: number) {
|
onKeydown(event: KeyboardEvent) {
|
||||||
const startIndex = Math.max(0, index - 2);
|
if (event.key === "ArrowRight") {
|
||||||
const endIndex = Math.min(this.pages.length - 1, index + 2);
|
this.nextPage();
|
||||||
|
} else if (event.key === "ArrowLeft") {
|
||||||
for (let i = startIndex; i <= endIndex; i++) {
|
this.prevPage();
|
||||||
if (!this.isPageCached(i)) {
|
|
||||||
this.fetchAndCachePage(i)
|
|
||||||
.pipe(takeUntil(this.destroy$))
|
|
||||||
.subscribe(() => {
|
|
||||||
if (i === this.currentPageIndex) {
|
|
||||||
this.updateImage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private isPageCached(index: number): boolean {
|
private getImageUrl(imageData?: Uint8Array): string {
|
||||||
return !!this.cachedPages[index]?.imageData;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Загрузка и сохранение изображения в кэш
|
|
||||||
private fetchAndCachePage(index: number): Observable<void> {
|
|
||||||
return this.searchService
|
|
||||||
.getImageData(this.searchService.getImageServer() + this.pages[index].url)
|
|
||||||
.pipe(
|
|
||||||
map((imageData) => {
|
|
||||||
const url = this.getImageUrl(imageData);
|
|
||||||
this.cachedPages = {
|
|
||||||
...this.cachedPages,
|
|
||||||
[index]: {
|
|
||||||
...this.pages[index],
|
|
||||||
imageData,
|
|
||||||
imageUrl: url,
|
|
||||||
isManhwa: +this.pages[index].ratio < 0.5,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Выгрузка из кэша старых страниц
|
|
||||||
private unloadCachedPages(index: number) {
|
|
||||||
for (const key in this.cachedPages) {
|
|
||||||
const pageIndex = +key;
|
|
||||||
if (index - pageIndex > 2) {
|
|
||||||
delete this.cachedPages[pageIndex];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getImageUrl(imageData?: Uint8Array): string {
|
|
||||||
if (!imageData) {
|
if (!imageData) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -271,23 +231,6 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
return urlCreator.createObjectURL(blob);
|
return urlCreator.createObjectURL(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обновляем изображение на странице
|
|
||||||
private updateImage() {
|
|
||||||
const currentPage = this.cachedPages[this.currentPageIndex];
|
|
||||||
if (currentPage && currentPage.imageData && !this.isManhwa$.value) {
|
|
||||||
const blob = new Blob([currentPage.imageData], { type: "image/jpeg" });
|
|
||||||
const urlCreator = window.URL || window.webkitURL;
|
|
||||||
this.imageUrl = urlCreator.createObjectURL(blob);
|
|
||||||
const imageUrl = this.imageUrl;
|
|
||||||
const image = new Image();
|
|
||||||
image.onload = () => {
|
|
||||||
if (currentPage.isManhwa) this.isManhwa$.next(currentPage.isManhwa);
|
|
||||||
URL.revokeObjectURL(imageUrl);
|
|
||||||
};
|
|
||||||
image.src = imageUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPage() {
|
nextPage() {
|
||||||
this.loadPage(this.currentPageIndex + 1);
|
this.loadPage(this.currentPageIndex + 1);
|
||||||
}
|
}
|
||||||
@@ -297,6 +240,6 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get imageContainerClass() {
|
get imageContainerClass() {
|
||||||
return `${this.isManhwa ? "h-auto" : "h-[70vh]"} w-[95vw] md:w-[700px] md:h-auto flex flex-col`;
|
return `${this.isManhwa ? "h-auto" : "h-[70vh]"} w-[95vw] md:w-[450px] flex flex-col`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ import { Page } from "../../services/parsers/rulib/rulib.chapter.dto";
|
|||||||
export interface CachedPage extends Page {
|
export interface CachedPage extends Page {
|
||||||
imageData?: Uint8Array;
|
imageData?: Uint8Array;
|
||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
|
index: number;
|
||||||
isManhwa: boolean;
|
isManhwa: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CachedPages {
|
export type CachedPages = Map<number, CachedPage>;
|
||||||
[key: number]: CachedPage;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
<div class="image-container" #container>
|
<div class="image-container" #container>
|
||||||
<img #image [src]="imageSrc" (load)="onImageLoad()" alt="Manga page" />
|
@if (imageSrc) {
|
||||||
|
<img #image [src]="imageSrc" (load)="onImageLoad()" alt="Manga page" />
|
||||||
|
} @else {
|
||||||
|
<div class="h-screen flex flex-col items-center justify-center"><h1>Loading...</h1></div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
import { AfterViewInit, Component, ElementRef, Input, OnDestroy, ViewChild } from "@angular/core";
|
import {
|
||||||
|
AfterViewInit,
|
||||||
|
Component,
|
||||||
|
ElementRef,
|
||||||
|
EventEmitter,
|
||||||
|
Input,
|
||||||
|
OnDestroy,
|
||||||
|
Output,
|
||||||
|
ViewChild,
|
||||||
|
} from "@angular/core";
|
||||||
import { Subscription, debounceTime, fromEvent } from "rxjs";
|
import { Subscription, debounceTime, fromEvent } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -11,15 +20,30 @@ 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;
|
||||||
|
@Output() view = new EventEmitter<void>();
|
||||||
|
@Input() host: ElementRef | null = null;
|
||||||
|
@Input() hostScrollable: boolean = false;
|
||||||
|
|
||||||
private resizeSubscription: Subscription = new Subscription();
|
private resizeSubscription: Subscription = new Subscription();
|
||||||
|
private observer!: IntersectionObserver;
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterViewInit(): void {
|
||||||
this.setupResizeListener();
|
this.setupResizeListener();
|
||||||
|
if (this.host) {
|
||||||
|
this.observer = new IntersectionObserver(
|
||||||
|
([entry]) => entry.isIntersecting && this.view.emit(),
|
||||||
|
{
|
||||||
|
root: this.hostScrollable ? this.host.nativeElement : null,
|
||||||
|
rootMargin: "100px",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (this.containerRef) this.observer.observe(this.containerRef.nativeElement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
if (this.resizeSubscription) this.resizeSubscription.unsubscribe();
|
if (this.resizeSubscription) this.resizeSubscription.unsubscribe();
|
||||||
|
if (this.observer) this.observer.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@@ -84,4 +85,37 @@ export class LibSocialParserService extends Parser {
|
|||||||
catchError((error) => throwError(() => `Now found ${error}`)),
|
catchError((error) => throwError(() => `Now found ${error}`)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isManhwa(slug_url: string): Observable<boolean> {
|
||||||
|
return this.http
|
||||||
|
.get(
|
||||||
|
`${this.url}/api/manga/${slug_url}?fields[]=summary&fields[]=genres&fields[]=tags&fields[]=authors`,
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
map((data) => {
|
||||||
|
const res = data as IRulibDetailResult;
|
||||||
|
return [5, 6, 4].includes(res.data.type.id);
|
||||||
|
}),
|
||||||
|
catchError((error) => throwError(() => `Now found ${error}`)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPopular(): Observable<IRuLIBPopular[]> {
|
||||||
|
//TODO: мб сделать ассинхрон
|
||||||
|
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[];
|
||||||
|
console.log(res);
|
||||||
|
return res;
|
||||||
|
}),
|
||||||
|
catchError((error) => throwError(() => `Now found ${error}`)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from "@angular/common/http";
|
||||||
import { Injectable, OnDestroy } from "@angular/core";
|
import { Injectable, OnDestroy } from "@angular/core";
|
||||||
import { Observable, Subject, catchError, map, of, takeUntil } from "rxjs";
|
import { Observable, Subject, catchError, map, of, takeUntil } from "rxjs";
|
||||||
|
import { IToken } from "../token.dto";
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: "root",
|
providedIn: "root",
|
||||||
})
|
})
|
||||||
@@ -10,19 +11,21 @@ export class RulibAuthService implements OnDestroy {
|
|||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
setToken(token: string): Observable<boolean> {
|
setToken(token: string): Observable<boolean> {
|
||||||
return this.checkToken(token)
|
return this.checkToken(token).pipe(
|
||||||
.pipe(takeUntil(this.destroy$))
|
takeUntil(this.destroy$),
|
||||||
.pipe(
|
map((data) => {
|
||||||
map((data) => {
|
if (!data) return false;
|
||||||
if (!data) return false;
|
const token_data: IToken = JSON.parse(localStorage.getItem("token") ?? "{}");
|
||||||
localStorage.setItem("token", token);
|
token_data.rulib_token = token;
|
||||||
return true;
|
localStorage.setItem("token", JSON.stringify(token_data));
|
||||||
}),
|
return true;
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getToken(): string {
|
getToken(): string {
|
||||||
return localStorage.getItem("token") ?? "";
|
const token_data: IToken = JSON.parse(localStorage.getItem("token") ?? "{}");
|
||||||
|
return token_data.rulib_token ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
checkToken(token: string): Observable<boolean> {
|
checkToken(token: string): Observable<boolean> {
|
||||||
|
|||||||
@@ -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 {}
|
||||||
3
apps/NwaifuAnime/src/app/services/parsers/token.dto.ts
Normal file
3
apps/NwaifuAnime/src/app/services/parsers/token.dto.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export interface IToken {
|
||||||
|
rulib_token?: string;
|
||||||
|
}
|
||||||
@@ -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,25 +1,37 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from "@angular/common/http";
|
||||||
import { Injectable } from "@angular/core";
|
import { Inject, Injectable } from "@angular/core";
|
||||||
import { BehaviorSubject, Observable, map } from "rxjs";
|
import { Observable, map } from "rxjs";
|
||||||
import { MangalibParserService } from "./parsers/rulib/mangalib.parser.service";
|
import { EParser } from "./parsers/enums/parser";
|
||||||
|
import { Parser } from "./parsers/parser";
|
||||||
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";
|
||||||
import { Datum, IRulibSearchResult } from "./parsers/rulib/rulib.search.dto";
|
import { IRulibSearchResult } from "./parsers/rulib/rulib.search.dto";
|
||||||
|
|
||||||
@Injectable({ providedIn: "root" })
|
@Injectable({ providedIn: "root" })
|
||||||
export class SearchService {
|
export class SearchService {
|
||||||
private itemsTerm = new BehaviorSubject<Datum[]>([]);
|
private parser!: Parser;
|
||||||
currentItemsTerm = this.itemsTerm.asObservable();
|
|
||||||
constructor(
|
constructor(
|
||||||
private parser: MangalibParserService,
|
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
|
@Inject(Parser) private parsers: Parser[],
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
setMangalibParser() {
|
||||||
|
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> {
|
||||||
return this.parser.searchManga(query).pipe(
|
return this.parser.searchManga(query).pipe(
|
||||||
map((data) => {
|
map((data) => {
|
||||||
return data;
|
return data as IRulibSearchResult;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -27,7 +39,7 @@ export class SearchService {
|
|||||||
getDetails(slug_url: string): Observable<IRulibDetailResult> {
|
getDetails(slug_url: string): Observable<IRulibDetailResult> {
|
||||||
return this.parser.getDetails(slug_url).pipe(
|
return this.parser.getDetails(slug_url).pipe(
|
||||||
map((data) => {
|
map((data) => {
|
||||||
return data;
|
return data as IRulibDetailResult;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -35,7 +47,7 @@ export class SearchService {
|
|||||||
getChapters(url: string): Observable<IRulibChaptersResult> {
|
getChapters(url: string): Observable<IRulibChaptersResult> {
|
||||||
return this.parser.getChapters(url).pipe(
|
return this.parser.getChapters(url).pipe(
|
||||||
map((data) => {
|
map((data) => {
|
||||||
return data;
|
return data as IRulibChaptersResult;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -43,13 +55,14 @@ export class SearchService {
|
|||||||
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
|
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
|
||||||
return this.parser.getChapter(url, chapter, volume).pipe(
|
return this.parser.getChapter(url, chapter, volume).pipe(
|
||||||
map((data) => {
|
map((data) => {
|
||||||
return data;
|
return data as IRulibChapterResult;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getImageServer() {
|
getImageServer() {
|
||||||
return this.parser.imageServer;
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
return (this.parser as any).imageServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
getImageData(imageUrl: string): Observable<Uint8Array> {
|
getImageData(imageUrl: string): Observable<Uint8Array> {
|
||||||
@@ -59,4 +72,18 @@ export class SearchService {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isManhwa(url: string): Observable<boolean> {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
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