@@ -9,12 +9,18 @@ import {
99 type SourceManga ,
1010 type TagSection ,
1111} from "@paperback/types" ;
12- import { filter , jsonParser , MangaWorldGeneric , tags , types } from "./main" ;
12+ import {
13+ cache ,
14+ filter ,
15+ jsonParser ,
16+ MangaWorldGeneric ,
17+ tags ,
18+ types ,
19+ } from "./main" ;
1320import type {
1421 Manga ,
1522 MangaChapterList ,
1623 MangaMetadata ,
17- MangaPageData ,
1824 TrendingManga ,
1925 WindowEntry ,
2026} from "./models" ;
@@ -348,7 +354,7 @@ export class Parsers {
348354 * Parsing most read
349355 * @param {MangaMetadata } metadata - metadata
350356 * @param source
351- * @return {{ items: DiscoverSectionItem[], metadata: Metadata } }
357+ * @return {{ items: DiscoverSectionItem[], metadata: MangaMetadata } }
352358 */
353359 async parseMostReadSection (
354360 metadata : MangaMetadata ,
@@ -362,7 +368,7 @@ export class Parsers {
362368 return { items : latest , metadata : { page : page } } ;
363369 }
364370
365- async parseLastMangaAddedSection (
371+ async parseLastAddedSection (
366372 metadata : MangaMetadata ,
367373 source : MangaWorldGeneric ,
368374 favTags : boolean ,
@@ -412,31 +418,50 @@ export class Parsers {
412418 * Parse new chapters
413419 * @param {MangaMetadata } metadata - manga metadata
414420 * @param source
415- * @param manga
416- * @return {{
417- * items: DiscoverSectionItem[],
418- * metadata: MangaMetadata | undefined
419- * }}
421+ * @return {Promise<{ items: DiscoverSectionItem[]; metadata: MangaMetadata }> }
420422 */
421423
422- async parseLastAddedSection (
424+ async parseChapterUpdateSection (
423425 metadata : MangaMetadata ,
424426 source : MangaWorldGeneric ,
425- manga : MangaPageData ,
426- ) : Promise < ChapterUpdatesCarouselItem | undefined > {
427- return {
428- chapterId : "items.manga" ,
429- metadata : metadata ,
430- type : "chapterUpdatesCarouselItem" ,
431- publishDate : new Date ( manga . manga . createdAt ) ,
432- contentRating :
433- source . defaultContentRating === ContentRating . ADULT
434- ? ContentRating . ADULT
435- : source . defaultContentRating ,
436- imageUrl : manga . manga . imageT ?? manga . manga . image ,
437- mangaId : manga . manga . linkId + "/" + manga . manga . slug ,
438- title : manga . manga . title ?? "" ,
439- subtitle : manga . chapters [ 0 ] ?. name ?? "" ,
440- } ;
427+ ) : Promise < { items : DiscoverSectionItem [ ] ; metadata : MangaMetadata } > {
428+ const page = metadata ?. page ?? 1 ;
429+ let html = "" ;
430+ const updates : ChapterUpdatesCarouselItem [ ] = [ ] ;
431+ if ( page == 1 ) {
432+ html = Application . arrayBufferToUTF8String (
433+ await cache . getPageCache ( "home" , source . base_url ) ,
434+ ) ;
435+ } else {
436+ const data = (
437+ await Application . scheduleRequest ( {
438+ url : `${ source . base_url } /?page=${ page } ` ,
439+ method : "GET" ,
440+ } )
441+ ) [ 1 ] ;
442+ html = Application . arrayBufferToUTF8String ( data ) ;
443+ }
444+ const windowEntry = jsonParser . getWindowEntry ( html ) ;
445+ for ( const { kind, data } of windowEntry ) {
446+ if ( kind !== "manga" ) continue ;
447+ const { manga, chapters } = data ;
448+ const firstChapter = chapters ?. [ 0 ] ;
449+ if ( firstChapter ) {
450+ updates . push ( {
451+ chapterId : firstChapter . id ?? "" ,
452+ type : "chapterUpdatesCarouselItem" ,
453+ publishDate : new Date ( firstChapter . createdAt ) ,
454+ contentRating :
455+ source . defaultContentRating === ContentRating . ADULT
456+ ? ContentRating . ADULT
457+ : source . defaultContentRating ,
458+ imageUrl : manga . imageT ?? manga . image ,
459+ mangaId : `${ manga . linkId } /${ manga . slug } ` ,
460+ title : manga . title ?? "" ,
461+ subtitle : firstChapter . name ?? "" ,
462+ } ) ;
463+ }
464+ }
465+ return { items : updates , metadata : { page : page + 1 } } ;
441466 }
442467}
0 commit comments