import express from "express" ; import handlebars from "express-handlebars" ; import bodyParser from "body-parser" ; import routers from "./routers" ; import { StoredData , Chapter , Progress , List } from "./types" ; import getIconSrc from "./util/getIconSrc" ; import { getProviderId } from "./routers/manga-page" ; const app = express ( ) ; app . engine ( "handlebars" , handlebars ( { helpers : { stringify ( v ) { return JSON . stringify ( v ) ; } , /**
         * Get progress string to show on page, like 23%
         */ getProgressString ( manga ) { if ( manga . progress && manga . success ) { const curChapter = manga . data . chapters . find ( ( c ) => c . hrefString === manga . progress . chapterId ) ; return ( curChapter ?. label + ( typeof manga ?. progress ?. percentage !== "undefined" ? ` (${ manga . progress . percentage }%)` : "" ) ?? "Chapter not found" ) ; } return "Not started yet" ; } , /**
         * Get icon for each scraper
         */ getScraperIcon ( provider ) { const icons = { mangasee : "https://mangasee123.com/media/favicon.png" , mangadex : "https://mangadex.org/images/misc/navbar.svg" , mangadex5 : "https://mangadex.siteunblocked.info/images/misc/navbar.svg?3" , rco : "/provider/rco.png" , nhentai : "https://nhentai.to/img/logo.650c98bbb08e.svg" , nhentainet : "https://nhentai.net/favicon.ico" , manganelo : "https://manganato.com/favicon-96x96.png" , comicextra : "https://www.comicextra.com/images/site/front/logo.png" , mangahere : "/proxy-image?url=https://www.mangahere.cc/favicon.ico" , guya : "https://guya.moe/static/logo_small.png" } ; return icons [ provider ] ?? "/icons/main-on-white.png" ; } , /**
         * Generate HREF for links in-app
         */ genLink2 ( provider = "mangasee" , slug , hrefString = null , chapter = - 1 ) { const href = `/${ getProviderId ( provider ) }/${ slug }/` ; let seasonLink = typeof hrefString === "string" || typeof hrefString === "number" ? hrefString : "" ; if ( typeof chapter === "number" && chapter !== - 1 ) seasonLink = `${ hrefString }-${ chapter }` ; return `${ href }${ seasonLink }` ; } , /**
         * Compare season/chapter to other season/chapter and get relevant classes
         */ isCurrentChapter ( season1 , season2 , chapter1 , chapter2 ) { return season1 === season2 && chapter1 === chapter2 ? "current-chapter badge-background" : "" ; } , /**
         * Used for small-manga in the sidebar
         * Returns relevant classes to maybe make it blue
         */ checkSmallHighlight ( mangaSlug , currentPage ) { return mangaSlug === currentPage ? "currentManga badge-background" : "" ; } , /**
         * Get dd-mm-yyyy format for chapter's date
         * Used in chapter list
         */ getChapterDate ( chapter ) { function pad ( v , amount = 2 ) { return v . toString ( ) . padStart ( amount , "0" ) ; } const d = new Date ( chapter . date ) ; return `${ pad ( d . getDate ( ) ) }-${ pad ( d . getMonth ( ) + 1 ) }-${ pad ( d . getFullYear ( ) , 4 ) }` ; } , /**
         * Get chapter's existing progress
         * If it's over 90%, return page number 1 so that people can start the chapter over again
         */ getPageProgress ( progress ) { if ( ! progress ) return false ; return progress . percentage < 90 ? progress . current : 1 ; } , /**
         * If statement, used for development
         * AFAIK this is just for the label in the bottom left
         */ ifDev ( options ) { return process . env . dev ? options . fn ( this ) : options . inverse ( this ) ; } , /**
         * Get chapter's name, or label
         * Used in the main cards
         */ getChapterName ( progress , manga ) { if ( ! progress ) return "shrug" ; const current = manga . data . chapters . find ( ( v ) => v . hrefString === progress . chapterId ) ; return current ? current . label : "Unknown chapter" ; } , /**
         * If statement for checking if the list is by the creator
         */ ifNotByCreator ( list , options ) { return list . byCreator ? options . inverse ( ) : options . fn ( ) ; } , getIconSrc } } ) ) ; app . set ( "view engine" , "handlebars" ) ; app . set ( "view options" , { layout : "main" } ) ; app . use ( bodyParser . json ( ) ) ; app . use ( "/" , routers . home ) ; app . use ( "/search" , routers . search ) ; app . use ( "/lists" , routers . lists ) ; app . use ( "/" , routers . settings ) ; app . use ( express . static ( "public" ) ) ; app . use ( "/" , routers . mangaPage ) ; app . use ( "*" , routers . notFound ) ; export default app ;