futurepress / epub.js

Enhanced eBooks in the browser.
http://futurepress.org
Other
6.4k stars 1.1k forks source link

How to force offline storage client side #958

Open davidawad opened 5 years ago

davidawad commented 5 years ago

hey there, there's a lot of issues on storage and i've really tried my best to understand the right way to do this but it's just not clear.

How do I force epubjs to deal with a file exclusively client side?

I have a use case where a user uploads their epub file into a react app and it is dealt with exclusively client side.

I want the ability to parse and work with the book only on the client side. i'm sure this is possible but i'm running into all kinds of strange files.

The offline code example doesn't do this, it handles events for when the browser loses internet, but i'm interested in the case where a user only ever loads the client app a single time and adds their own epub files.

For context I'm using an app built off of Create React App.

Any help would be very appreciated.

thanks

davidawad commented 5 years ago

As an example i'm able to parse out the chapters of an epub file but i can't see any of the actual section content.

    // assume getting the bookData into the epub funciton works

    book = Epub(bookData, {
      store: "epubjs-test",
      storage: true,
    })

   var rendition = book.renderTo("viewer", {
    width: "100%",
    height: 600
   }) ;

   var displayed = rendition.display();

   displayed.then(function(renderer){
     // Add all resources to the store
     // Add `true` to force re-saving resources
     book.storage.add(book.resources, true).then(() => {
       console.log("stored");
     })
   });

    // print out contents ~  
    book.loaded.spine.then((spine) => {

        spine.each((section) => {

            console.log("SECTION: ", section, typeof(section));

            section.load().then((contents) => {

                console.log("SECTION DOC:", contents, typeof(contents), contents.contents, contents.document, contents.innerText)

            })

        });

    });

But all this shows me are objects with the chapter titles.

Screen Shot 2019-07-10 at 4 08 55 PM

It really shouldn't be this hard to read the contents of the epub I've already uploaded myself within the browser.

For some reason when I try to parse or query the section contents themselves, they all make requests back at my react app.

Screen Shot 2019-07-10 at 4 10 01 PM
davidawad commented 5 years ago

my usecase is the EpubParser.js file in this project : https://github.com/davidawad/thoth

brismuth commented 4 years ago

@davidawad I checked out Thoth, it looks cool.

Did you ever get this working? I tried uploading an epub to Thoth and it logged errors to the console and nothing happened, so I'm guessing not but thought I'd check.

brismuth commented 4 years ago

Context: I'm trying to do the same thing (render epubs using epub.js from memory / client side storage).

brismuth commented 4 years ago

Never mind, following the example in https://github.com/futurepress/epub.js/blob/master/examples/input.html I was able to get client side storage to work.