Compare commits
3 Commits
00213d25a1
...
feature/ma
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b209077ef | |||
| 2becf42487 | |||
| 7b2c6d9fc8 |
@@ -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,4 +1,12 @@
|
|||||||
<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) {
|
@if (loading) {
|
||||||
<h1>Loading...</h1>
|
<h1>Loading...</h1>
|
||||||
|
|||||||
@@ -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,32 +17,73 @@ 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() {
|
||||||
|
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 {
|
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 = [];
|
||||||
|
if (this.search) {
|
||||||
this.loading = true;
|
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.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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,8 @@
|
|||||||
→
|
→
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="hidden md:block md:fixed right-10 top-[50%]">
|
||||||
|
{{ currentPageIndex + 1 }} / {{ pages.length }}
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import { CachedPage, CachedPages } from "./reader.dto";
|
|||||||
imports: [CommonModule, ScaleImageComponent, RouterLink],
|
imports: [CommonModule, ScaleImageComponent, RouterLink],
|
||||||
})
|
})
|
||||||
export class ReaderComponent implements OnInit, OnDestroy {
|
export class ReaderComponent implements OnInit, OnDestroy {
|
||||||
//FIXME: Scrolling to top when manhwa
|
|
||||||
pages: Page[] = [];
|
pages: Page[] = [];
|
||||||
currentPageIndex = 0;
|
currentPageIndex = 0;
|
||||||
cachedPages: CachedPages = new Map<number, CachedPage>();
|
cachedPages: CachedPages = new Map<number, CachedPage>();
|
||||||
@@ -61,6 +60,7 @@ export class ReaderComponent implements OnInit, OnDestroy {
|
|||||||
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;
|
||||||
|
|||||||
@@ -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,23 @@ export class LibSocialParserService extends Parser {
|
|||||||
catchError((error) => throwError(() => `Now found ${error}`)),
|
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}`)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,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> {
|
||||||
@@ -61,6 +74,16 @@ export class SearchService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isManhwa(url: string): Observable<boolean> {
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user