diff --git a/documentation/md/API.md b/documentation/md/API.md index cfad86d..60a447b 100644 --- a/documentation/md/API.md +++ b/documentation/md/API.md @@ -134,9 +134,9 @@ Set headers request should use ### coverUrl -Get the cover url +Get the cover url if there is a cover -Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** Promise resolves with url string +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[?string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** Promise resolves with maybe a url string ### getRange diff --git a/src/book.js b/src/book.js index 0fcc30b..f5fd332 100644 --- a/src/book.js +++ b/src/book.js @@ -661,19 +661,20 @@ class Book { /** * Get the cover url - * @return {Promise} coverUrl + * @return {Promise} coverUrl */ coverUrl() { - var retrieved = this.loaded.cover. - then((url) => { - if(this.archived) { - return this.archive.createUrl(this.cover); - }else{ - return this.cover; - } - }); + return this.loaded.cover.then(() => { + if (!this.cover) { + return null; + } - return retrieved; + if (this.archived) { + return this.archive.createUrl(this.cover); + } else { + return this.cover; + } + }); } /** diff --git a/test/book.js b/test/book.js index a6c8539..41e2753 100644 --- a/test/book.js +++ b/test/book.js @@ -50,4 +50,18 @@ describe('Book', function() { assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" ); }); }); + + describe('Archived epub without cover', function() { + var book = new Book("/fixtures/alice_without_cover.epub"); + + it('should open a archived epub', async function() { + await book.opened + assert.equal(book.isOpen, true, "book is opened"); + assert(book.archive, "book is unarchived"); + }); + it('should have a empty coverUrl', async function() { + let coverUrl = await book.coverUrl() + assert.equal(coverUrl, null, "cover url should be null" ); + }); + }); }); diff --git a/test/fixtures/alice_without_cover.epub b/test/fixtures/alice_without_cover.epub new file mode 100644 index 0000000..b215b2a Binary files /dev/null and b/test/fixtures/alice_without_cover.epub differ diff --git a/types/book.d.ts b/types/book.d.ts index 6f4a2ee..f1326b2 100644 --- a/types/book.d.ts +++ b/types/book.d.ts @@ -65,7 +65,7 @@ export default class Book { canonical(path: string): string; - coverUrl(): Promise; + coverUrl(): Promise; destroy(): void;