@@ -9,6 +9,7 @@ const epubGen = require("nodepub");
99import mime from "mime" ;
1010import { writeFileSync , createWriteStream , writeFile } from "fs" ;
1111import request from "request" ;
12+ import { async } from "@angular/core/testing" ;
1213
1314@Injectable ( {
1415 providedIn : "root" ,
@@ -38,6 +39,18 @@ export class NovelFactoryService {
3839 // Download the cover and get its path
3940 const coverPath = await this . downloadCover ( novel . cover , novelFolder ) ;
4041
42+ // If the novel doesn't have a genre we default "Unknown"; empty or null will crash the epub creation
43+ if ( novel . genre == null || novel . genre == "" ) {
44+ novel . genre = 'unknown'
45+ }
46+
47+ // If the novel doesnt have a author we default "Unknown"; empty or null will crash the epub creation
48+ if ( novel . author == null || novel . author == "" ) {
49+ novel . author = 'unknown'
50+ }
51+ console . log ( "Creating Epub with metadata" ) ;
52+ console . log ( novel )
53+
4154 // Set some meta data for the epub file
4255 const metadata = {
4356 id : "0000-0000-0001" ,
@@ -59,13 +72,14 @@ export class NovelFactoryService {
5972 for ( const chapter of chapters )
6073 epub . addSection ( chapter . title , chapter . data ) ;
6174
62- setTimeout ( async ( ) => {
63- await epub . writeEPUB ( novelFolder , novelFile ) ;
64-
65- this . database . updateDownloading ( novel . link , false ) ;
66- this . database . updateDownloaded ( novel . link , true ) ;
67- this . database . updateIsUpdated ( novel . link , true ) ;
68- this . database . setDownloaded ( downloadID ) ;
75+ setTimeout ( ( ) => {
76+ ( async ( ) => {
77+ await epub . writeEPUB ( novelFolder , novelFile ) ;
78+ this . database . updateDownloading ( novel . link , false ) ;
79+ this . database . updateDownloaded ( novel . link , true ) ;
80+ this . database . updateIsUpdated ( novel . link , true ) ;
81+ this . database . setDownloaded ( downloadID ) ;
82+ } ) ( ) ;
6983 } , 2000 ) ;
7084 }
7185
0 commit comments