6 Commits

16 changed files with 277 additions and 48 deletions

View File

@@ -3,6 +3,9 @@ import { ApplicationConfig, isDevMode, provideZoneChangeDetection } from "@angul
import { provideRouter } from "@angular/router";
import { provideServiceWorker } from "@angular/service-worker";
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 = {
providers: [
@@ -13,5 +16,7 @@ export const appConfig: ApplicationConfig = {
registrationStrategy: "registerWhenStable:30000",
}),
provideHttpClient(withFetch()),
{ provide: Parser, multi: true, useClass: MangalibParserService },
{ provide: Parser, multi: true, useClass: SlashlibParserService },
],
};

View File

@@ -56,6 +56,7 @@ export class DetailComponent implements AfterViewInit, OnDestroy {
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
const url = params["url"];
if (url) {
this.searchService.setMangalibParser();
this.getDetails(url);
} else {
this.router.navigate(["/"]);

View File

@@ -1,14 +1,37 @@
<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">
<a href="/"><h1 class="text-white" title="Main page">NwaifuAnime</h1></a>
<div class="flex justify-between flex-row w-full align-middle h-8 items-center">
<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 -->
<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>
</button>
</div>
<div
class="flex flex-col md:flex-row md:justify-end justify-center items-center gap-3 md:w-[50vw] h-full w-full"
>
<!-- Search bar on big screens -->
<div [class]="searchBarClass">
<input
@@ -25,4 +48,17 @@
<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')
"
>
<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>
</div>

View File

@@ -1,6 +1,6 @@
import { CommonModule } from "@angular/common";
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";
@Component({
@@ -8,7 +8,7 @@ import { Subject, filter, takeUntil } from "rxjs";
templateUrl: "./header.component.html",
styleUrls: ["./header.component.less"],
standalone: true,
imports: [CommonModule],
imports: [CommonModule, RouterLink],
})
export class HeaderComponent implements AfterViewInit, OnDestroy {
@ViewChild("searchInput") searchInput: ElementRef<HTMLInputElement> | null = null;
@@ -37,7 +37,7 @@ export class HeaderComponent implements AfterViewInit, OnDestroy {
}
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() {

View File

@@ -1,5 +1,19 @@
<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">
@if (loading) {
<h1>Loading...</h1>
}
@if (notFound && !loading) {
<h1>Not found</h1>
}
@for (item of items; track $index) {
<a
routerLink="/detail"

View File

@@ -1,7 +1,8 @@
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 { 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 { SearchService } from "../../services/search.service";
@@ -12,31 +13,77 @@ import { SearchService } from "../../services/search.service";
styleUrls: ["./home.component.less"],
imports: [CommonModule, RouterLink],
})
export class HomeComponent implements OnDestroy, AfterViewInit {
export class HomeComponent implements OnDestroy, OnInit {
@Input() items: Datum[] = [];
loading = false;
notFound = false;
search: string = "";
popularItemsMap: Map<string, IRuLIBPopular[]> = new Map<string, IRuLIBPopular[]>();
private destroy$ = new Subject<void>();
private popularSubscription = new Subscription();
constructor(
private searchService: SearchService,
private route: ActivatedRoute,
) {}
) {
this.searchService.setMangalibParser();
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
this.popularSubscription.unsubscribe();
}
ngAfterViewInit(): void {
this.route.queryParams.subscribe((params) => {
const search = params["search"];
if (search) {
private getPopular() {
if (!this.popularSubscription.closed) this.popularSubscription.unsubscribe();
this.popularSubscription = this.searchService
.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
.search(search)
.search(this.search)
.pipe(takeUntil(this.destroy$))
.subscribe((data) => {
this.loading = false;
this.items = data.data;
this.notFound = this.items.length === 0;
});
} else {
this.getPopularMangalib();
this.getPopularSlashlib();
}
});
}

View File

@@ -35,5 +35,8 @@
</button>
</div>
<div class="hidden md:block md:fixed right-10 top-[50%]">
{{ currentPageIndex + 1 }} / {{ pages.length }}
</div>
}
</div>

View File

@@ -1,11 +1,11 @@
import { CommonModule, isPlatformBrowser } from "@angular/common";
import {
AfterViewInit,
Component,
ElementRef,
HostListener,
Inject,
OnDestroy,
OnInit,
PLATFORM_ID,
} from "@angular/core";
import { ActivatedRoute, Router, RouterLink } from "@angular/router";
@@ -23,8 +23,7 @@ import { CachedPage, CachedPages } from "./reader.dto";
standalone: true,
imports: [CommonModule, ScaleImageComponent, RouterLink],
})
export class ReaderComponent implements AfterViewInit, OnDestroy {
//FIXME: Scrolling to top when manhwa
export class ReaderComponent implements OnInit, OnDestroy {
pages: Page[] = [];
currentPageIndex = 0;
cachedPages: CachedPages = new Map<number, CachedPage>();
@@ -54,13 +53,14 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
return this.cachedPages.values();
}
ngAfterViewInit(): void {
ngOnInit(): void {
this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => {
const url = params["url"];
const chapter = params["chapter"];
const volume = params["volume"];
const fromTowards = params["from_towards"];
if (url && chapter && volume) {
this.searchService.setMangalibParser();
if (fromTowards) this.fromTowards = Boolean(+fromTowards);
else this.fromTowards = false;
this.chapterNum = +chapter;
@@ -166,7 +166,9 @@ export class ReaderComponent implements AfterViewInit, OnDestroy {
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);
}
}

View File

@@ -34,7 +34,7 @@ export class ScaleImageComponent implements AfterViewInit, OnDestroy {
([entry]) => entry.isIntersecting && this.view.emit(),
{
root: this.hostScrollable ? this.host.nativeElement : null,
rootMargin: "1000px",
rootMargin: "100px",
},
);
if (this.containerRef) this.observer.observe(this.containerRef.nativeElement);

View File

@@ -0,0 +1,4 @@
export enum EParser {
MangaLib = 0,
SlashLib = 1,
}

View File

@@ -15,4 +15,6 @@ export abstract class Parser {
abstract getChapters(url: string): Observable<object>;
abstract getChapter(url: string, chapter: string, volume: string): Observable<object>;
abstract getPopular(): Observable<object[]>;
}

View File

@@ -6,6 +6,7 @@ import { RulibAuthService } from "./rulib.auth.service";
import { IRulibChapterResult } from "./rulib.chapter.dto";
import { IRulibChaptersResult } from "./rulib.chapters.dto";
import { IRulibDetailResult } from "./rulib.detail.dto";
import { IRuLIBPopular } from "./rulib.popular.dto";
import { IRulibSearchResult } from "./rulib.search.dto";
//TODO: Make abstract classes
@@ -98,4 +99,23 @@ export class LibSocialParserService extends Parser {
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}`)),
);
}
}

View File

@@ -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;
}

View File

@@ -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 {}

View File

@@ -1,4 +1,5 @@
export enum ESiteUrls {
LIB_SOCIAL = "https://api.lib.social",
MANGALIB = "https://api.mangalib.me",
SLASHLIB = "https://api.slashlib.me",
}

View File

@@ -1,25 +1,37 @@
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 { Inject, Injectable } from "@angular/core";
import { Observable, map } from "rxjs";
import { EParser } from "./parsers/enums/parser";
import { Parser } from "./parsers/parser";
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";
import { IRulibSearchResult } from "./parsers/rulib/rulib.search.dto";
@Injectable({ providedIn: "root" })
export class SearchService {
private itemsTerm = new BehaviorSubject<Datum[]>([]);
currentItemsTerm = this.itemsTerm.asObservable();
private parser!: Parser;
constructor(
private parser: MangalibParserService,
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> {
return this.parser.searchManga(query).pipe(
map((data) => {
return data;
return data as IRulibSearchResult;
}),
);
}
@@ -27,7 +39,7 @@ export class SearchService {
getDetails(slug_url: string): Observable<IRulibDetailResult> {
return this.parser.getDetails(slug_url).pipe(
map((data) => {
return data;
return data as IRulibDetailResult;
}),
);
}
@@ -35,7 +47,7 @@ export class SearchService {
getChapters(url: string): Observable<IRulibChaptersResult> {
return this.parser.getChapters(url).pipe(
map((data) => {
return data;
return data as IRulibChaptersResult;
}),
);
}
@@ -43,13 +55,14 @@ export class SearchService {
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
return this.parser.getChapter(url, chapter, volume).pipe(
map((data) => {
return data;
return data as IRulibChapterResult;
}),
);
}
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> {
@@ -61,6 +74,16 @@ export class SearchService {
}
isManhwa(url: string): Observable<boolean> {
return this.parser.isManhwa(url);
// 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;
}
}