1+ import {
2+ Chapter ,
3+ ChapterDetails ,
4+ HomeSection ,
5+ Manga , MangaTile ,
6+ PagedResults ,
7+ Request ,
8+ SearchRequest ,
9+ Source ,
10+ SourceInfo ,
11+ } from "paperback-extensions-common"
12+ import { VoidScansParser } from "./VoidScansParser" ;
13+
14+ const BASE = "https://voidscans.net"
15+
16+ export const VoidScansInfo : SourceInfo = {
17+ icon : "icon.png" ,
18+ version : "1.1.0" ,
19+ name : "VoidScans" ,
20+ author : "PythonCoderAS" ,
21+ authorWebsite : "https://github.com/PythonCoderAS" ,
22+ description : "Extension that pulls manga from VoidScans" ,
23+ language : "en" ,
24+ hentaiSource : false ,
25+ websiteBaseURL : BASE
26+ }
27+
28+ export class VoidScans extends Source {
29+
30+ private readonly parser : VoidScansParser = new VoidScansParser ( ) ;
31+
32+ getMangaShareUrl ( mangaId : string ) : string | null {
33+ return `${ BASE } /library/${ mangaId } ` ;
34+ }
35+
36+ async getHomePageSections ( sectionCallback : ( section : HomeSection ) => void ) : Promise < void > {
37+ sectionCallback ( createHomeSection ( {
38+ id : "1" ,
39+ items : ( await this . getWebsiteMangaDirectory ( null ) ) . results ,
40+ title : "All Manga"
41+ } ) ) ;
42+ }
43+
44+ async getWebsiteMangaDirectory ( metadata : any ) : Promise < PagedResults > {
45+ const options : Request = createRequestObject ( {
46+ url : `${ BASE } /library` ,
47+ method : 'GET'
48+ } ) ;
49+ let response = await this . requestManager . schedule ( options , 1 ) ;
50+ let $ = this . cheerio . load ( response . data ) ;
51+ return createPagedResults ( {
52+ results : this . parser . parseMangaList ( $ , BASE )
53+ } ) ;
54+ }
55+
56+ async getChapterPage ( mangaId : string , chapterId : string , page : number = 1 ) : Promise < string | null > {
57+ const options : Request = createRequestObject ( {
58+ url : `${ BASE } /read/${ mangaId } /${ chapterId } /${ page } ` ,
59+ method : 'GET'
60+ } ) ;
61+ let response = await this . requestManager . schedule ( options , 1 ) ;
62+ let $ = this . cheerio . load ( response . data ) ;
63+ return this . parser . parsePage ( $ )
64+ }
65+
66+ async getChapterDetails ( mangaId : string , chapterId : string ) : Promise < ChapterDetails > {
67+ const pages : string [ ] = [ ] ;
68+ let page = await this . getChapterPage ( mangaId , chapterId ) ;
69+ let num = 2 ;
70+ while ( page ) {
71+ pages . push ( page )
72+ page = await this . getChapterPage ( mangaId , chapterId , num ) ;
73+ num ++ ;
74+ }
75+ return createChapterDetails ( {
76+ id : chapterId ,
77+ longStrip : true ,
78+ mangaId : mangaId ,
79+ pages : pages
80+ } )
81+ }
82+
83+ async getChapters ( mangaId : string ) : Promise < Chapter [ ] > {
84+ const options : Request = createRequestObject ( {
85+ url : `${ BASE } /library/${ mangaId } ` ,
86+ method : 'GET'
87+ } ) ;
88+ let response = await this . requestManager . schedule ( options , 1 ) ;
89+ let $ = this . cheerio . load ( response . data ) ;
90+ return this . parser . parseChapterList ( $ , mangaId ) ;
91+ }
92+
93+ async getMangaDetails ( mangaId : string ) : Promise < Manga > {
94+ const options : Request = createRequestObject ( {
95+ url : `${ BASE } /library/${ mangaId } ` ,
96+ method : 'GET'
97+ } ) ;
98+ let response = await this . requestManager . schedule ( options , 1 ) ;
99+ let $ = this . cheerio . load ( response . data ) ;
100+ return this . parser . parseManga ( $ , mangaId ) ;
101+ }
102+
103+ async searchRequest ( query : SearchRequest , metadata : any ) : Promise < PagedResults > {
104+ // TODO: Wait for search to be implemented on the website.
105+ const results = ( await this . getWebsiteMangaDirectory ( null ) ) . results ;
106+ const data : MangaTile [ ] = [ ] ;
107+ for ( let i = 0 ; i < results . length ; i ++ ) {
108+ const key = results [ i ] ;
109+ if ( query . title ) {
110+ if ( ( key . primaryText ?. text || "" ) . toLowerCase ( ) . includes ( ( query . title . toLowerCase ( ) ) ) ) {
111+ data . push ( key ) ;
112+ }
113+ }
114+ }
115+ return createPagedResults ( {
116+ results : data
117+ } ) ;
118+ }
119+ }
0 commit comments