mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-02 14:49:16 +02:00
Merge pull request #1056 from christiaan/master_test-and-fix-coverUrl
Fix broken coverUrl for archived Epubs
This commit is contained in:
commit
0e3104461d
4 changed files with 28 additions and 8 deletions
|
@ -136,7 +136,7 @@ Set headers request should use
|
|||
|
||||
Get the cover url
|
||||
|
||||
Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** coverUrl
|
||||
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
|
||||
|
||||
### getRange
|
||||
|
||||
|
|
|
@ -660,14 +660,13 @@ class Book {
|
|||
|
||||
/**
|
||||
* Get the cover url
|
||||
* @return {string} coverUrl
|
||||
* @return {Promise<string>} coverUrl
|
||||
*/
|
||||
coverUrl() {
|
||||
var retrieved = this.loaded.cover.
|
||||
then((url) => {
|
||||
if(this.archived) {
|
||||
// return this.archive.createUrl(this.cover);
|
||||
return this.resources.get(this.cover);
|
||||
return this.archive.createUrl(this.cover);
|
||||
}else{
|
||||
return this.cover;
|
||||
}
|
||||
|
|
27
test/book.js
27
test/book.js
|
@ -1,11 +1,32 @@
|
|||
var assert = require('assert');
|
||||
|
||||
describe('Book', function() {
|
||||
|
||||
var Book = require('../src/book');
|
||||
|
||||
before(function(){
|
||||
|
||||
describe('Unarchived', function() {
|
||||
var book = new Book("/fixtures/alice/OPS/package.opf");
|
||||
it('should open a epub', async function() {
|
||||
await book.opened
|
||||
assert.equal(book.isOpen, true, "book is opened");
|
||||
assert.equal( book.url.toString(), "http://localhost:9876/fixtures/alice/OPS/package.opf", "book url is passed to new Book" );
|
||||
});
|
||||
it('should have a local coverUrl', async function() {
|
||||
assert.equal( await book.coverUrl(), "http://localhost:9876/fixtures/alice/OPS/images/cover_th.jpg", "cover url is available" );
|
||||
});
|
||||
});
|
||||
|
||||
describe('Archived epub', function() {
|
||||
var book = new Book("/fixtures/alice.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 blob coverUrl', async function() {
|
||||
let coverUrl = await book.coverUrl()
|
||||
assert( /^blob:http:\/\/localhost:9876\/[^\/]+$/.test(coverUrl), "cover url is available and a blob: url" );
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
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(): string;
|
||||
coverUrl(): Promise<string>;
|
||||
|
||||
destroy(): void;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue