1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Merge pull request #1056 from christiaan/master_test-and-fix-coverUrl

Fix broken coverUrl for archived Epubs
This commit is contained in:
Fred Chasen 2020-05-19 14:41:16 -07:00 committed by GitHub
commit 0e3104461d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 8 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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
View file

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