feat: manhwa check

This commit is contained in:
2024-07-17 16:38:12 +03:00
parent c9c959ce76
commit 8c87401482
4 changed files with 34 additions and 27 deletions

View File

@@ -13,7 +13,7 @@
<div class="flex flex-col items-center"> <div class="flex flex-col items-center">
@if (pages.length > 0 && cachedPages.get(currentPageIndex)) { @if (pages.length > 0 && cachedPages.get(currentPageIndex)) {
<div [class]="imageContainerClass"> <div [class]="imageContainerClass">
@if (!isManhwa$.value) { @if (!isManhwa) {
<app-scale-image [imageSrc]="imageUrl"></app-scale-image> <app-scale-image [imageSrc]="imageUrl"></app-scale-image>
} @else { } @else {
@for (page of manhwaPages; track page.id) { @for (page of manhwaPages; track page.id) {
@@ -21,12 +21,12 @@
} }
} }
</div> </div>
<div appLazyLoad></div> <div #anchor></div>
<div class="flex items-center justify-center space-x-4 my-10"> <div class="flex items-center justify-center space-x-4 my-10">
<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>

View File

@@ -1,16 +1,7 @@
import { CommonModule } from "@angular/common"; import { CommonModule } from "@angular/common";
import { AfterViewInit, Component, OnDestroy } from "@angular/core"; import { AfterViewInit, Component, OnDestroy } from "@angular/core";
import { ActivatedRoute, Router, RouterLink } from "@angular/router"; import { ActivatedRoute, Router, RouterLink } from "@angular/router";
import { import { Observable, Subject, Subscription, fromEvent, map, takeUntil, throttleTime } from "rxjs";
BehaviorSubject,
Observable,
Subject,
Subscription,
fromEvent,
map,
takeUntil,
throttleTime,
} 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";
@@ -34,7 +25,6 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
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;
@@ -50,7 +40,6 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
ngOnDestroy(): void { ngOnDestroy(): void {
this.destroy$.next(); this.destroy$.next();
this.destroy$.complete(); this.destroy$.complete();
this.isManhwa$.complete();
} }
get manhwaPages() { get manhwaPages() {
@@ -76,15 +65,16 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
.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;
});
} 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) { private handleScrollManhwa(event: Event) {
@@ -94,7 +84,7 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
(event.currentTarget as HTMLElement).scrollTop < (event.currentTarget as HTMLElement).scrollTop <
3000 3000
) { ) {
this.loadPage(this.currentPageIndex + 1); // this.loadPage(this.currentPageIndex + 1);
console.log("load"); console.log("load");
} }
} }
@@ -153,8 +143,8 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
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); // Сгружаем ненужные страницы из кэша if (!this.isManhwa) this.unloadCachedPages(index); // Сгружаем ненужные страницы из кэша
if (!this.isManhwa$.value) { if (!this.isManhwa) {
const container = document.querySelector("app-reader"); const container = document.querySelector("app-reader");
if (container) { if (container) {
container.scrollTo({ container.scrollTo({
@@ -174,7 +164,7 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
// Если страница уже в кэше, просто обновляем изображение // Если страница уже в кэше, просто обновляем изображение
this.updateImage(); this.updateImage();
} }
} else if (index == this.pages.length && !this.isManhwa$.value) { } else if (index == this.pages.length && !this.isManhwa) {
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;
}); });
@@ -190,7 +180,7 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
}, },
}); });
} }
} else if (index == -1 && !this.isManhwa$.value) { } else if (index == -1 && !this.isManhwa) {
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;
}); });
@@ -271,14 +261,13 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
// Обновляем изображение на странице // Обновляем изображение на странице
private updateImage() { private updateImage() {
const currentPage = this.cachedPages.get(this.currentPageIndex); const currentPage = this.cachedPages.get(this.currentPageIndex);
if (currentPage && currentPage.imageData && !this.isManhwa$.value) { if (currentPage && currentPage.imageData && !this.isManhwa) {
const blob = new Blob([currentPage.imageData], { type: "image/jpeg" }); const blob = new Blob([currentPage.imageData], { type: "image/jpeg" });
const urlCreator = window.URL || window.webkitURL; const urlCreator = window.URL || window.webkitURL;
this.imageUrl = urlCreator.createObjectURL(blob); this.imageUrl = urlCreator.createObjectURL(blob);
const imageUrl = this.imageUrl; const imageUrl = this.imageUrl;
const image = new Image(); const image = new Image();
image.onload = () => { image.onload = () => {
if (currentPage.isManhwa) this.isManhwa$.next(currentPage.isManhwa);
URL.revokeObjectURL(imageUrl); URL.revokeObjectURL(imageUrl);
}; };
image.src = imageUrl; image.src = imageUrl;

View File

@@ -84,4 +84,18 @@ 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}`)),
);
}
} }

View File

@@ -59,4 +59,8 @@ export class SearchService {
}), }),
); );
} }
isManhwa(url: string): Observable<boolean> {
return this.parser.isManhwa(url);
}
} }