Skip to content

Commit

Permalink
Semi-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaifroid committed Dec 7, 2023
1 parent ed4f47c commit 72d0911
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
52 changes: 22 additions & 30 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,39 +2102,31 @@ function handleMessageChannelMessage (event) {
console.warn('Title ' + title.replace(/^(.{1,160}).*/, '$1...') + ' not found in archive.');
// DEV: We send null for the content, so that the ServiceWorker knows that the article was not found (as opposed to being merely empty)
messagePort.postMessage({ action: 'giveContent', title: title, content: null, zimType: selectedArchive.zimType });
} else if (dirEntry.isRedirect()) {
selectedArchive.resolveRedirect(dirEntry, function (resolvedDirEntry) {
var redirectURL = resolvedDirEntry.namespace + '/' + resolvedDirEntry.url;
// Ask the ServiceWorker to send an HTTP redirect to the browser.
// We could send the final content directly, but it is necessary to let the browser know in which directory it ends up.
// Else, if the redirect URL is in a different directory than the original URL,
// the relative links in the HTML content would fail. See #312
messagePort.postMessage({ action: 'sendRedirect', title: title, redirectUrl: redirectURL });
});
} else if (dirEntry.isRedirect) {
var redirectPath = dirEntry.redirectPath;
// Ask the ServiceWorker to send an HTTP redirect to the browser.
// We could send the final content directly, but it is necessary to let the browser know in which directory it ends up.
// Else, if the redirect URL is in a different directory than the original URL,
// the relative links in the HTML content would fail. See #312
messagePort.postMessage({ action: 'sendRedirect', title: title, redirectUrl: redirectPath });
} else {
// Let's read the content in the ZIM file
selectedArchive.readBinaryFile(dirEntry, function (fileDirEntry, content) {
var mimetype = fileDirEntry.getMimetype();
// Show the spinner
var shortTitle = dirEntry.getTitleOrUrl().replace(/^.*?([^/]{3,18})[^/]*\/?$/, '$1 ...');
if (!/moved/i.test(shortTitle) && !/image|javascript|warc-headers|jsonp?/.test(mimetype)) {
uiUtil.spinnerDisplay(true, (translateUI.t('spinner-loading') || 'Loading') + ' ' + shortTitle);
clearTimeout(window.timeout);
window.timeout = setTimeout(function () {
uiUtil.spinnerDisplay(false);
}, 1000);
// Ensure the article onload event gets attached to the right iframe
articleLoader();
}
// Let's send the content to the ServiceWorker
var buffer = content.buffer ? content.buffer : content;
var message = { action: 'giveContent', title: title, content: buffer, mimetype: mimetype, zimType: selectedArchive.zimType };
messagePort.postMessage(message);
});
var shortTitle = title.replace(/^.*?([^/]{3,18})[^/]*\/?$/, '$1 ...');
if (!/moved/i.test(shortTitle) && !/image|javascript|warc-headers|jsonp?/.test(dirEntry.mimetype)) {
uiUtil.spinnerDisplay(true, (translateUI.t('spinner-loading') || 'Loading') + ' ' + shortTitle);
clearTimeout(window.timeout);
window.timeout = setTimeout(function () {
uiUtil.spinnerDisplay(false);
}, 1000);
// Ensure the article onload event gets attached to the right iframe
articleLoader();
}

var message = { action: 'giveContent', title: title, content: dirEntry.content, mimetype: dirEntry.mimetype };
messagePort.postMessage(message);
}
};
selectedArchive.getDirEntryByPath(title).then(readFile).catch(function () {
messagePort.postMessage({ action: 'giveContent', title: title, content: new Uint8Array(), zimType: selectedArchive.zimType });
selectedArchive.callLibzimWorker({ action: 'getEntryByPath', path: title, follow: false }).then(readFile).catch(function () {
messagePort.postMessage({ action: 'giveContent', title: title, content: new Uint8Array() });
});
}

Expand Down
6 changes: 5 additions & 1 deletion www/js/lib/zimArchive.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ function ZIMArchive (storage, path, callbackReady, callbackError) {
LZ = new Worker('js/lib/libzim-' + libzimReaderType + '.js');
that.callLibzimWorker({ action: 'init', files: that.file._files }).then(function () {
that.libzimReady = 'ready';
// if (params.useLibzim) whenZimReady();
whenZimReady();
params.searchProvider = 'fulltext: ' + libzimReaderType;
// Update the API panel
uiUtil.reportSearchProviderToAPIStatusPanel(params.searchProvider);
// Archive is set, go home
document.getElementById('btnHome').click();
}).catch(function (err) {
uiUtil.reportSearchProviderToAPIStatusPanel(params.searchProvider + ': ERROR');
console.error('The libzim worker could not be instantiated!', err);
Expand All @@ -172,7 +176,7 @@ function ZIMArchive (storage, path, callbackReady, callbackError) {
// Set the archive file type ('open' or 'zimit')
that.setZimType();
// If user is not using libzim for reading the file, we can call the ready callback now
if (!params.useLibzim) whenZimReady();
// if (!params.useLibzim) whenZimReady();
}).catch(function (err) {
console.warn('Error setting archive listings: ', err);
});
Expand Down

0 comments on commit 72d0911

Please sign in to comment.