mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Change Book.coverUrl to return null when there is no cover
CoverUrl now returns an undefined when there is no cover. However not having a cover is expected behavior for an epub without a cover.
This commit is contained in:
parent
0b0f2e1b2d
commit
d690dd9d68
4 changed files with 15 additions and 14 deletions
|
@ -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
|
||||
|
||||
|
|
13
src/book.js
13
src/book.js
|
@ -661,19 +661,20 @@ class Book {
|
|||
|
||||
/**
|
||||
* Get the cover url
|
||||
* @return {Promise<string>} coverUrl
|
||||
* @return {Promise<?string>} coverUrl
|
||||
*/
|
||||
coverUrl() {
|
||||
var retrieved = this.loaded.cover.
|
||||
then(() => {
|
||||
if(this.archived && this.cover) {
|
||||
return this.loaded.cover.then(() => {
|
||||
if (!this.cover) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.archived) {
|
||||
return this.archive.createUrl(this.cover);
|
||||
} else {
|
||||
return this.cover;
|
||||
}
|
||||
});
|
||||
|
||||
return retrieved;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,7 +61,7 @@ describe('Book', function() {
|
|||
});
|
||||
it('should have a empty coverUrl', async function() {
|
||||
let coverUrl = await book.coverUrl()
|
||||
assert.equal(coverUrl, undefined, "cover url should be undefined" );
|
||||
assert.equal(coverUrl, null, "cover url should be null" );
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
2
types/book.d.ts
vendored
2
types/book.d.ts
vendored
|
@ -65,7 +65,7 @@ export default class Book {
|
|||
|
||||
canonical(path: string): string;
|
||||
|
||||
coverUrl(): Promise<string>;
|
||||
coverUrl(): Promise<string | null>;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue