Provide list of mirrors for fallback

This commit is contained in:
Jaifroid 2024-12-01 22:49:00 +00:00
parent fb058cb858
commit 24f640f151
6 changed files with 20 additions and 16 deletions

View File

@ -12,7 +12,7 @@ If you have a distribution of this app and want to delete the packaged archive t
params['packagedFile'] = "name_of_your_file.zim"; params['packagedFile'] = "name_of_your_file.zim";
params['fileVersion'] = "descriptive_name_of_your_file (Jan-2020)"; // These values will show in the app params['fileVersion'] = "descriptive_name_of_your_file (Jan-2020)"; // These values will show in the app
params['cachedStartPages'] = false; params['cachedStartPages'] = false;
params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/"; //Include final slash params['kiwixDownloadServer'] = "https://download.kiwix.org/zim/"; //Include final slash
``` ```
You can have more than one ZIM archive in `archives`, but only one will launch on app startup as the packaged file. If you do have more than one, then be sure to set `params['showFileSelectors'] = true;` to aid in discoverability of the other archive, otherwise your users will not easily realize it is there. Keeping that parameter as `false` dedicates the app to the packaged archive, but users can still override and pick a different ZIM by changing the value in Expert Settings (Config). You can have more than one ZIM archive in `archives`, but only one will launch on app startup as the packaged file. If you do have more than one, then be sure to set `params['showFileSelectors'] = true;` to aid in discoverability of the other archive, otherwise your users will not easily realize it is there. Keeping that parameter as `false` dedicates the app to the packaged archive, but users can still override and pick a different ZIM by changing the value in Expert Settings (Config).
@ -21,4 +21,4 @@ You can have more than one ZIM archive in `archives`, but only one will launch o
If you are building a custom packaged version of the app, then remember that ZIMs will not appear in your online GitHub repo, so add a text file to `archives` to show the intended filename, like the `*.zim.txt` file in this directory, e.g. `wikivoyage_en_all_novid_2019-07.zim.txt`. The text file can be empty (0 bytes). You should also set the fields listed above in `www/js/init.js` to match, and additionally decide whether to set `params['showFileSelectors'] = false;` (if you want to simplify the interface in Config). If you are building a custom packaged version of the app, then remember that ZIMs will not appear in your online GitHub repo, so add a text file to `archives` to show the intended filename, like the `*.zim.txt` file in this directory, e.g. `wikivoyage_en_all_novid_2019-07.zim.txt`. The text file can be empty (0 bytes). You should also set the fields listed above in `www/js/init.js` to match, and additionally decide whether to set `params['showFileSelectors'] = false;` (if you want to simplify the interface in Config).
Advanced: If you wish to restrict the files that users can search for on the server, e.g. to ensure your app remains dedicated to WikiMed archives, and to aid discoverability of only those archives, then look in `kiwixServe.js` and search for `DEV:` (first comment labelled `DEV:`) for more info. Also, ensure `params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/";` is set appropriately so that the download library opens in the directory where multilingual or updated versions of your packaged ZIM can be found. Advanced: If you wish to restrict the files that users can search for on the server, e.g. to ensure your app remains dedicated to WikiMed archives, and to aid discoverability of only those archives, then look in `kiwixServe.js` and search for `DEV:` (first comment labelled `DEV:`) for more info. Also, ensure `params['kiwixDownloadServer'] = "https://download.kiwix.org/zim/";` is set appropriately so that the download library opens in the directory where multilingual or updated versions of your packaged ZIM can be found.

View File

@ -74,7 +74,7 @@ let imageDisplay = 'all';
// Kiwix ZIM Archive Download Server and release update server in regex form // Kiwix ZIM Archive Download Server and release update server in regex form
// DEV: The server URL is defined in init.js, but is not available to us in SW // DEV: The server URL is defined in init.js, but is not available to us in SW
const regexpKiwixDownloadLinks = /download\.kiwix\.org|api\.github\.com/i; const regexpkiwixDownloadServers = /download\.kiwix\.org|api\.github\.com/i;
/** /**
* A global Boolean that records whether the ReplayWorker is available * A global Boolean that records whether the ReplayWorker is available
@ -379,7 +379,7 @@ self.addEventListener('fetch', function (event) {
if (!(regexpZIMUrlWithNamespace.test(strippedUrl) && /\.zim\//i.test(strippedUrl))) return; if (!(regexpZIMUrlWithNamespace.test(strippedUrl) && /\.zim\//i.test(strippedUrl))) return;
} }
// Don't cache download links // Don't cache download links
if (regexpKiwixDownloadLinks.test(rqUrl)) return; if (regexpkiwixDownloadServers.test(rqUrl)) return;
// Select cache depending on request format // Select cache depending on request format
var cache = /\.zim\//i.test(strippedUrl) ? ASSETS_CACHE : APP_CACHE; var cache = /\.zim\//i.test(strippedUrl) ? ASSETS_CACHE : APP_CACHE;
cache = /youtube|vimeo/i.test(strippedUrl) ? ASSETS_CACHE : cache; cache = /youtube|vimeo/i.test(strippedUrl) ? ASSETS_CACHE : cache;

View File

@ -1719,7 +1719,7 @@ document.getElementById('btnRefresh').addEventListener('click', function () {
} }
}); });
document.getElementById('downloadTrigger').addEventListener('click', function () { document.getElementById('downloadTrigger').addEventListener('click', function () {
kiwixServe.requestXhttpData(params.kiwixDownloadLink); kiwixServe.requestXhttpData(params.kiwixDownloadServer);
}); });
document.querySelectorAll('input[name="contentInjectionMode"][type="radio"]').forEach(function (element) { document.querySelectorAll('input[name="contentInjectionMode"][type="radio"]').forEach(function (element) {
element.addEventListener('change', function () { element.addEventListener('change', function () {

View File

@ -81,8 +81,9 @@ params['cachedStartPages'] = {
wikivoyage_en_all_maxi: 'A/Main_Page' wikivoyage_en_all_maxi: 'A/Main_Page'
}; };
params['win7ElectronVersion'] = '22.3'; // KEEP UP TO DATE!!! This is the last minor version to support Win 7/8/8.1. Auto-update is embargoed for values starting with this. params['win7ElectronVersion'] = '22.3'; // KEEP UP TO DATE!!! This is the last minor version to support Win 7/8/8.1. Auto-update is embargoed for values starting with this.
params['kiwixDownloadLink'] = 'https://download.kiwix.org/zim/'; // Include final slash params['kiwixDownloadServer'] = 'https://download.kiwix.org/zim/'; // Include final slash
params['kiwixHiddenDownloadLink'] = 'https://master.download.kiwix.org/zim/'; params['kiwixDownloadMirrors'] = ['https://ftp.fau.de/kiwix/zim/', 'https://mirrors.dotsrc.org/kiwix/zim/', 'https://www.mirrorservice.org/sites/download.kiwix.org/zim/', 'https://md.mirrors.hacktegic.com/kiwix-md/zim/', 'https://library.kiwix.org'];
params['kiwixhiddenDownloadServer'] = 'https://master.download.kiwix.org/zim/';
/** ***** DEV: ENSURE SERVERS BELOW ARE LISTED IN package.appxmanifest ************/ /** ***** DEV: ENSURE SERVERS BELOW ARE LISTED IN package.appxmanifest ************/
params['PWAServer'] = 'https://pwa.kiwix.org/'; // Production server params['PWAServer'] = 'https://pwa.kiwix.org/'; // Production server
// params['PWAServer'] = 'https://kiwix.github.io/kiwix-js-pwa/dist/'; // Test server // params['PWAServer'] = 'https://kiwix.github.io/kiwix-js-pwa/dist/'; // Test server

View File

@ -725,12 +725,12 @@ function verifyPermission (fileHandle, withWrite) {
* Download an archive directly into the picked folder (primarily for use with the Origin Private File System) * Download an archive directly into the picked folder (primarily for use with the Origin Private File System)
* *
* @param {String} archiveName The name of the archive to download (will be used as the filename) * @param {String} archiveName The name of the archive to download (will be used as the filename)
* @param {String} archiveUrl An optional URL to download the archive from (if not supplied, will use params.kiwixDownloadLink) * @param {String} archiveUrl An optional URL to download the archive from (if not supplied, will use params.kiwixDownloadServer)
* @param {Function} callback Callback function to report the progress of the download * @param {Function} callback Callback function to report the progress of the download
* @returns {Promise<FileSystemFileHandle>} A Promise for a FileHandle object representing the downloaded file * @returns {Promise<FileSystemFileHandle>} A Promise for a FileHandle object representing the downloaded file
*/ */
function downloadArchiveToPickedFolder (archiveName, archiveUrl, callback) { function downloadArchiveToPickedFolder (archiveName, archiveUrl, callback) {
archiveUrl = archiveUrl || params.kiwixDownloadLink + archiveName; archiveUrl = archiveUrl || params.kiwixDownloadServer + archiveName;
if (params.pickedFolder && params.pickedFolder.getFileHandle) { if (params.pickedFolder && params.pickedFolder.getFileHandle) {
return verifyPermission(params.pickedFolder, true).then(function (permission) { return verifyPermission(params.pickedFolder, true).then(function (permission) {
if (permission) { if (permission) {

View File

@ -478,7 +478,7 @@ function requestXhttpData (URL, lang, subj, kiwixDate) {
torrentURL = URL.replace(/\.meta4$/i, '.torrent'); torrentURL = URL.replace(/\.meta4$/i, '.torrent');
var header = document.getElementById('dl-panel-heading'); var header = document.getElementById('dl-panel-heading');
var headerDoc = 'There is a server issue, but please try the following links to your file:'; var headerDoc = 'There is a server issue, but please try the following links to your file:';
if (~URL.indexOf(params.kiwixHiddenDownloadLink)) { if (~URL.indexOf(params.kiwixhiddenDownloadServer)) {
headerDoc = 'This file is only available via browser-managed download:'; headerDoc = 'This file is only available via browser-managed download:';
altURL = requestedURL.replace(/\/master\./i, '/mirror.'); altURL = requestedURL.replace(/\/master\./i, '/mirror.');
} }
@ -490,7 +490,7 @@ function requestXhttpData (URL, lang, subj, kiwixDate) {
'<p><a href="' + requestedURL + '"' + target + ' class="download">' + requestedURL + '</a></p>' + '<p><a href="' + requestedURL + '"' + target + ' class="download">' + requestedURL + '</a></p>' +
(altURL ? '<p><b>Possible mirror:</b></p>' + (altURL ? '<p><b>Possible mirror:</b></p>' +
'<p><a href="' + altURL + '"' + target + ' class="download">' + altURL + '</a></p>' : '') + '<p><a href="' + altURL + '"' + target + ' class="download">' + altURL + '</a></p>' : '') +
(~URL.indexOf(params.kiwixHiddenDownloadLink) ? '' (~URL.indexOf(params.kiwixhiddenDownloadServer) ? ''
: '<p><b>Download with bittorrent:</b></p>' + : '<p><b>Download with bittorrent:</b></p>' +
'<p><a href="' + torrentURL + '"' + target + '>' + torrentURL + '</a></p>'); '<p><a href="' + torrentURL + '"' + target + '>' + torrentURL + '</a></p>');
body.outerHTML = body.outerHTML.replace(/<pre\b([^>]*)>[\s\S]*?<\/pre>/i, '<div$1>' + bodyDoc + '</div>'); body.outerHTML = body.outerHTML.replace(/<pre\b([^>]*)>[\s\S]*?<\/pre>/i, '<div$1>' + bodyDoc + '</div>');
@ -515,8 +515,11 @@ function requestXhttpData (URL, lang, subj, kiwixDate) {
} else { } else {
downloadLinks.innerHTML = '<span style="font-weight:bold;font-family:consolas,monospace;">' + downloadLinks.innerHTML = '<span style="font-weight:bold;font-family:consolas,monospace;">' +
'<p style="color:salmon;">Unable to access the server. Please see message below for reason.</p>' + '<p style="color:salmon;">Unable to access the server. Please see message below for reason.</p>' +
'<p>You can either try again or else open this link in a new browser window:<br />' + '<p>You can either try again or else open one of these mirror links in a new browser window:</p><ul>';
'<a href="' + params.kiwixDownloadLink + '"' + target + '>' + params.kiwixDownloadLink + '</a></p><br /></span>'; params.kiwixDownloadMirrors.forEach(function (mirror) {
downloadLinks.innerHTML += '<li><a href="' + mirror + '"' + target + '>' + mirror + '</a></li>';
});
downloadLinks.innerHTML += '</ul></span><br />';
} }
downloadLinks.style.display = 'block'; downloadLinks.style.display = 'block';
} }
@ -938,14 +941,14 @@ function requestXhttpData (URL, lang, subj, kiwixDate) {
var dateID = dateSel ? dateSel.value : ''; var dateID = dateSel ? dateSel.value : '';
var subjID = subjSel ? subjSel.value : ''; var subjID = subjSel ? subjSel.value : '';
var replaceURL = URL + this.dataset.kiwixDl; var replaceURL = URL + this.dataset.kiwixDl;
replaceURL = /(custom_apps|endless|dev)\//.test(this.text) ? params.kiwixHiddenDownloadLink + '.hidden/' + this.text : replaceURL; replaceURL = /(custom_apps|endless|dev)\//.test(this.text) ? params.kiwixhiddenDownloadServer + '.hidden/' + this.text : replaceURL;
replaceURL = /(archive)\//.test(this.text) ? params.kiwixDownloadLink.replace(/\/zim\//, '/archive/zim/') : replaceURL; replaceURL = /(archive)\//.test(this.text) ? params.kiwixDownloadServer.replace(/\/zim\//, '/archive/zim/') : replaceURL;
// Allow both zim and zip format // Allow both zim and zip format
if (/\.zi[mp]$/i.test(this.dataset.kiwixDl)) { if (/\.zi[mp]$/i.test(this.dataset.kiwixDl)) {
replaceURL = replaceURL + '.meta4'; replaceURL = replaceURL + '.meta4';
} else if (/parent\s*directory|\.\.\//i.test(this.text)) { } else if (/parent\s*directory|\.\.\//i.test(this.text)) {
replaceURL = URL.replace(/\/[^/]*\/$/i, '/'); replaceURL = URL.replace(/\/[^/]*\/$/i, '/');
replaceURL = replaceURL.replace(params.kiwixHiddenDownloadLink, params.kiwixDownloadLink); replaceURL = replaceURL.replace(params.kiwixhiddenDownloadServer, params.kiwixDownloadServer);
replaceURL = replaceURL.replace(/\.hidden\//, ''); replaceURL = replaceURL.replace(/\.hidden\//, '');
replaceURL = replaceURL.replace(/\/archive\/$/, '/zim/'); replaceURL = replaceURL.replace(/\/archive\/$/, '/zim/');
} else if (/Name|Size|Last\smodified|Description/.test(this.text)) { } else if (/Name|Size|Last\smodified|Description/.test(this.text)) {