mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-21 18:47:38 -04:00
Fix untransformed relative zimit2 URLs without wombat (#569)
This commit is contained in:
parent
13906fa6f1
commit
2d31b84a39
@ -5217,6 +5217,10 @@ function handleClickOnReplayLink (ev, anchor) {
|
||||
// If it starts with the path to the ZIM file, then we are dealing with an untransformed absolute local ZIM link
|
||||
if (!anchor.href.indexOf(pathToZim)) {
|
||||
zimUrl = anchor.href.replace(pathToZim, '');
|
||||
// If it is the same as the pseudoDomainPath, then we are dealing with an untransformed pseuodo relative link that looks like an absolute https:// link
|
||||
// (this probably only applies to zimit2 without Wombat)
|
||||
} else if (anchor.href.replace(/^[^:]+:\/\//, '') === pseudoDomainPath && /\.zim\/[CA]\//.test(anchor.href)) {
|
||||
zimUrl = anchor.href.replace(/^(?:[^.]|\.(?!zim\/[CA]\/))+\.zim\//, '');
|
||||
} else {
|
||||
zimUrl = pseudoNamespace + pseudoDomainPath + anchor.search;
|
||||
}
|
||||
@ -5226,7 +5230,7 @@ function handleClickOnReplayLink (ev, anchor) {
|
||||
ev.stopPropagation();
|
||||
// Note that true in the fourth argument instructs getDirEntryByPath to follow redirects by looking up the Header
|
||||
return appstate.selectedArchive.getDirEntryByPath(zimUrl, null, null, true).then(function (dirEntry) {
|
||||
if (dirEntry) {
|
||||
var processDirEntry = function (dirEntry) {
|
||||
var pathToArticleDocumentRoot = document.location.href.replace(/www\/index\.html.*$/, appstate.selectedArchive.file.name + '/');
|
||||
var mimetype = dirEntry.getMimetype();
|
||||
// Due to the iframe sandbox, we have to prevent the PDF viewer from opening in the iframe and instead open it in a new tab
|
||||
@ -5318,13 +5322,29 @@ function handleClickOnReplayLink (ev, anchor) {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if (dirEntry) {
|
||||
processDirEntry(dirEntry);
|
||||
} else {
|
||||
// If dirEntry was not-found, it's probably an external link, so warn user before opening a new tab/window
|
||||
uiUtil.warnAndOpenExternalLinkInNewTab(null, anchor);
|
||||
// If URL has final slash, we need to try it without the slash
|
||||
if (/\/$/.test(zimUrl)) {
|
||||
zimUrl = zimUrl.replace(/\/$/, '');
|
||||
return appstate.selectedArchive.getDirEntryByPath(zimUrl).then(function (dirEntry) {
|
||||
if (dirEntry) {
|
||||
processDirEntry(dirEntry);
|
||||
} else {
|
||||
// If dirEntry was still not-found, it's probably an external link, so warn user before opening a new tab/window
|
||||
uiUtil.warnAndOpenExternalLinkInNewTab(null, anchor);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// It's probably an external link, so warn user before opening a new tab/window
|
||||
uiUtil.warnAndOpenExternalLinkInNewTab(null, anchor);
|
||||
}
|
||||
}
|
||||
}).catch(function (err) {
|
||||
console.error('Error getting dirEntry for ' + zimUrl, err);
|
||||
appstate.isReplayWorkerAvailable = true;
|
||||
uiUtil.systemAlert('There was an error looking up ' + zimUrl, 'Error reading direcotry entry!');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user