1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

Merge pull request #1063 from christiaan/master_fix-coverUrl-thows-unexpected-error

Bugfix calling coverUrl throws error on book without cover
This commit is contained in:
Fred Chasen 2020-05-22 18:37:00 -07:00 committed by GitHub
commit 2e5b2ec684
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 13 deletions

View file

@ -134,9 +134,9 @@ Set headers request should use
### coverUrl ### 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 ### getRange

View file

@ -661,19 +661,20 @@ class Book {
/** /**
* Get the cover url * Get the cover url
* @return {Promise<string>} coverUrl * @return {Promise<?string>} coverUrl
*/ */
coverUrl() { coverUrl() {
var retrieved = this.loaded.cover. return this.loaded.cover.then(() => {
then((url) => { if (!this.cover) {
if(this.archived) { return null;
return this.archive.createUrl(this.cover); }
}else{
return this.cover;
}
});
return retrieved; if (this.archived) {
return this.archive.createUrl(this.cover);
} else {
return this.cover;
}
});
} }
/** /**

View file

@ -50,4 +50,18 @@ describe('Book', function() {
assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" ); 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" );
});
});
}); });

BIN
test/fixtures/alice_without_cover.epub vendored Normal file

Binary file not shown.

2
types/book.d.ts vendored
View file

@ -65,7 +65,7 @@ export default class Book {
canonical(path: string): string; canonical(path: string): string;
coverUrl(): Promise<string>; coverUrl(): Promise<string | null>;
destroy(): void; destroy(): void;