import { Novel } from "./novel" ; import { Chapter } from "./chapter" ; import _ from "lodash" ; export class DownloadItem { public novel : Novel ; public chapters : DownloadChapterItem [ ] ; constructor ( init ? ) { Object . assign ( this , init ) ; } get progress ( ) { return Math . round ( this . downloadedChapters . length / this . chapters . length * 100 ) || 0 ; } get status ( ) { let isPending = _ . every ( this . chapters , chapter => chapter . status === DownloadStatus . Pending ) ; if ( isPending ) { return DownloadStatus . Pending ; } let isOngoing = _ . some ( this . chapters , chapter => chapter . status === DownloadStatus . Ongoing ) ; if ( isOngoing ) { return DownloadStatus . Ongoing ; } let isCompleted = _ . every ( this . chapters , chapter => chapter . status === DownloadStatus . Completed ) ; if ( isCompleted ) { return DownloadStatus . Completed ; } } get downloadedChapters ( ) { return _ . filter ( this . chapters , chapter => chapter . status === DownloadStatus . Completed ) ; } } export class EpubDownloadItem { public novel : Novel ; public progress : number = 0 ; constructor ( init ? ) { Object . assign ( this , init ) ; } } export enum DownloadStatus { Pending , Ongoing , Completed , Error } export class DownloadChapterItem extends Chapter { public status : DownloadStatus = DownloadStatus . Pending ; public checked : boolean = true ; }