feat: auth page

This commit is contained in:
2024-07-10 16:35:14 +03:00
parent 6833105604
commit 112e76ab45
10 changed files with 199 additions and 46 deletions

View File

@@ -1,6 +1,8 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable, catchError, map, throwError } from "rxjs";
import { Parser } from "../parser";
import { RulibAuthService } from "./rulib.auth.service";
import { IRulibChapterResult } from "./rulib.chapter.dto";
import { IRulibChaptersResult } from "./rulib.chapters.dto";
import { IRulibDetailResult } from "./rulib.detail.dto";
@@ -19,6 +21,13 @@ export class LibSocialParserService extends Parser {
return "https://img33.imgslib.link";
}
constructor(
private rulibAuthService: RulibAuthService,
override http: HttpClient,
) {
super(http);
}
searchManga(query: string): Observable<IRulibSearchResult> {
return this.http
.get(
@@ -38,6 +47,7 @@ export class LibSocialParserService extends Parser {
return this.http
.get(
`${this.url}/api/manga/${slug_url}?fields[]=summary&fields[]=genres&fields[]=tags&fields[]=authors`,
{ headers: { Authorization: "Bearer " + this.rulibAuthService.getToken() } },
)
.pipe(
map((data: object) => {
@@ -50,19 +60,25 @@ export class LibSocialParserService extends Parser {
}
getChapters(url: string): Observable<IRulibChaptersResult> {
return this.http.get(`${this.url}/api/manga/${url}/chapters`).pipe(
map((data) => {
return data as IRulibChaptersResult;
}),
catchError((error) => {
return throwError(() => `Now found ${error}`);
}),
);
return this.http
.get(`${this.url}/api/manga/${url}/chapters`, {
headers: { Authorization: "Bearer " + this.rulibAuthService.getToken() },
})
.pipe(
map((data) => {
return data as IRulibChaptersResult;
}),
catchError((error) => {
return throwError(() => `Now found ${error}`);
}),
);
}
getChapter(url: string, chapter: string, volume: string): Observable<IRulibChapterResult> {
return this.http
.get(`${this.url}/api/manga/${url}/chapter?number=${chapter}&volume=${volume}`)
.get(`${this.url}/api/manga/${url}/chapter?number=${chapter}&volume=${volume}`, {
headers: { Authorization: "Bearer " + this.rulibAuthService.getToken() },
})
.pipe(
map((data) => data as IRulibChapterResult),
catchError((error) => throwError(() => `Now found ${error}`)),

View File

@@ -0,0 +1,15 @@
import { Injectable } from "@angular/core";
@Injectable({
providedIn: "root",
})
export class RulibAuthService {
setToken(token: string) {
localStorage.setItem("token", token);
}
getToken(): string {
return localStorage.getItem("token") ?? "";
}
//TODO: Проверка токена
}