-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from chytanka/develop
feat: Read from Telegra.ph
- Loading branch information
Showing
18 changed files
with
153 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './link-parser'; | ||
export * from './imgur-link-parser'; | ||
export * from './mangadex-link-parser'; | ||
export * from './json-link-parser'; | ||
export * from './json-link-parser'; | ||
export * from './telegraph-link-parser'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { LinkParser } from "./link-parser"; | ||
|
||
export class TelegraphLinkParser extends LinkParser { | ||
override regex = /telegra\.ph\/([\w\-_іїґ]+)/; | ||
override site = 'telegr' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { HttpClient, HttpParams } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, map } from 'rxjs'; | ||
import { CompositionEpisode } from '../../shared/utils'; | ||
import { environment } from '../../../environments/environment'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class TelegraphService { | ||
|
||
constructor(private http: HttpClient) { } | ||
|
||
getComposition(id: string): Observable<CompositionEpisode> { | ||
const params = new HttpParams().set('return_content', 'true'); | ||
return this.http.get<any>(environment.telegraphHost + id , { params: params }) | ||
.pipe(map((data) => { return this.map(data) })) | ||
} | ||
|
||
|
||
map(data: any): CompositionEpisode { | ||
const mappedResponse = { | ||
title: data.result.title, | ||
images: (data.result.content.map((item: any) => { | ||
return { | ||
src: item.children.find((child: any) => child.tag === "img")?.attrs.src | ||
}; | ||
})).filter((i: any) => i.src).map((img: any)=> {return {src: 'https://telegra.ph'+ img.src}}) | ||
}; | ||
|
||
|
||
|
||
|
||
return mappedResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule, Routes } from '@angular/router'; | ||
import { TelegraphShellComponent } from './telegraph-shell/telegraph-shell.component'; | ||
|
||
const routes: Routes = [ | ||
{ path: '', redirectTo: '/', pathMatch: 'full' }, | ||
{ | ||
path: ':path', | ||
component: TelegraphShellComponent | ||
} | ||
]; | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forChild(routes)], | ||
exports: [RouterModule] | ||
}) | ||
export class TelegraphRoutingModule { } |
13 changes: 13 additions & 0 deletions
13
src/app/telegraph/telegraph-shell/telegraph-shell.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@if(episode$ | async; as episode){ | ||
<app-viewer [episode]="episode"></app-viewer> | ||
} | ||
@if(error$ | async; as error){ | ||
<div class="error-message"> | ||
{{ error }} <br> | ||
<button (click)="refreshData()">Ше раз</button> <br> | ||
<a [routerLink]="'/'">🏠</a> | ||
</div> | ||
} | ||
@if(loading$ | async; as loading){ | ||
<div class="loading">⏳</div> | ||
} |
Empty file.
29 changes: 29 additions & 0 deletions
29
src/app/telegraph/telegraph-shell/telegraph-shell.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Component } from '@angular/core'; | ||
import { Base64, ReadBaseComponent } from '../../shared/utils'; | ||
import { of, switchMap } from 'rxjs'; | ||
import { TelegraphService } from '../data-access/telegraph.service'; | ||
|
||
@Component({ | ||
selector: 'app-telegraph-shell', | ||
templateUrl: './telegraph-shell.component.html', | ||
styleUrl: './telegraph-shell.component.scss' | ||
}) | ||
export class TelegraphShellComponent extends ReadBaseComponent { | ||
|
||
override episode$ = this.combineParamMapAndRefresh() | ||
.pipe(this.tapStartLoading(), | ||
switchMap(([params]) => { | ||
const pathParam = params?.get('path'); | ||
|
||
if (!pathParam) return of(null); | ||
|
||
const path = (Base64.isBase64(pathParam)) ? Base64.fromBase64(pathParam) : pathParam; | ||
|
||
return (this.telegraph.getComposition(path)).pipe(this.catchError(), this.tapSetTitle(), this.finalizeLoading()); | ||
}) | ||
); | ||
|
||
constructor(public telegraph: TelegraphService){ | ||
super() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
import { TelegraphRoutingModule } from './telegraph-routing.module'; | ||
import { TelegraphShellComponent } from './telegraph-shell/telegraph-shell.component'; | ||
import { SharedModule } from '../shared/shared.module'; | ||
|
||
|
||
@NgModule({ | ||
declarations: [ | ||
TelegraphShellComponent | ||
], | ||
imports: [ | ||
CommonModule, | ||
TelegraphRoutingModule, | ||
SharedModule | ||
] | ||
}) | ||
export class TelegraphModule { } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters