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:
commit
2e5b2ec684
5 changed files with 28 additions and 13 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
11
src/book.js
11
src/book.js
|
@ -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) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.archived) {
|
if (this.archived) {
|
||||||
return this.archive.createUrl(this.cover);
|
return this.archive.createUrl(this.cover);
|
||||||
} else {
|
} else {
|
||||||
return this.cover;
|
return this.cover;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return retrieved;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
14
test/book.js
14
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" );
|
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
BIN
test/fixtures/alice_without_cover.epub
vendored
Normal file
Binary file not shown.
2
types/book.d.ts
vendored
2
types/book.d.ts
vendored
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue