RussCoder / djvujs

DjVu.js is a program library for working with .djvu files online without any connection with the server. DjVu.js Viewer is a widget that allows viewing .djvu files right in the browser and can be easily embedded into any web page.
https://djvu.js.org/
Other
186 stars 37 forks source link

Error with loadDocumentByUrl #92

Open aalexei opened 10 months ago

aalexei commented 10 months ago

Hi, I'm trying to set up a viewer for djvu files I serve on a local url line /file/uid.djvu. Using the code

 const viewer = new DjVu.Viewer();
 viewer.render(document.getElementById('djvu-view'));
 viewer.loadDocumentByUrl('/file/{{fuid}}.djvu');

but I just get the error:

Unexpected error
{}

What am I doing wrong?

RussCoder commented 10 months ago

Hello, is the code processed by a template engine? I'm asking because of the string '/file/{{fuid}}.djvu'. Try to hardcode the URL and try to open another file.

aalexei commented 10 months ago

Same error, and I've checked it all get's expanded correctly and there is a file at that url.

aalexei commented 10 months ago

The following variant works, but requires loading data into array buffer:

async function loadDocument1() {
     // Working
     const viewer = new DjVu.Viewer();
     viewer.render(document.getElementById('djvu-view'));
     const indexFileBuffer = await fetch('/file/{{fuid}}').then(r => r.arrayBuffer());
     await viewer.loadDocument(indexFileBuffer);
 }

 async function loadDocument2() {
     // Not working
     const viewer = new DjVu.Viewer();
     viewer.render(document.getElementById('djvu-view'));
     await viewer.loadDocumentByUrl('/file/{{fuid}}');
 }

loadDocument1();

So seems to be something with the parsing of the url?

RussCoder commented 10 months ago

Please, check the browser console (Ctrl+Shift+I). I need more information. And is it a bundled (single file) document or an indirect (multifile) one?

aalexei commented 10 months ago

This is using the js files from https://djvu.js.org/downloads (DjVu.js 0.5.4, DjVu.js Viewer 0.10.0).

Console reports

TypeError: invalid type format
    at DE (djvu_viewer.js:134:4404)
    at Op.loadDocumentByUrl (djvu_viewer.js:134:17798)
    at loadDocumentByUrl.next (<anonymous>)
    at h (djvu_viewer.js:134:1351)
    at E (djvu_viewer.js:134:1910)
errorAction @ djvu_viewer.js:78
loadDocumentByUrl @ djvu_viewer.js:134
h @ djvu_viewer.js:134
E @ djvu_viewer.js:134
Promise.then (async)
bc @ djvu_viewer.js:131
v @ djvu_viewer.js:134
y @ djvu_viewer.js:134
h @ djvu_viewer.js:134
E @ djvu_viewer.js:134
(anonymous) @ djvu_viewer.js:131
YC @ djvu_viewer.js:131
Qg @ djvu_viewer.js:131
Gg @ djvu_viewer.js:131
Xg.e.put @ djvu_viewer.js:131
(anonymous) @ djvu_viewer.js:134
(anonymous) @ djvu_viewer.js:131
(anonymous) @ djvu_viewer.js:134
loadDocumentByUrl @ djvu_viewer.js:134
loadDocument2 @ UGMDGMH1C25FXGNTWGI1UVEHY:160
(anonymous) @ UGMDGMH1C25FXGNTWGI1UVEHY:162
RussCoder commented 10 months ago

I forgot about this issue. Sorry for that. If you still need it to be solved, please, send me the file. Or at least tell me its type (bundled or indirect) and the final URL that is used to load it.