diff --git a/archives/README.md b/archives/README.md index 92bb151de..c458f2388 100644 --- a/archives/README.md +++ b/archives/README.md @@ -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['fileVersion'] = "descriptive_name_of_your_file (Jan-2020)"; // These values will show in the app 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). @@ -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). -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. diff --git a/service-worker.js b/service-worker.js index 08055bcdb..d1474342d 100644 --- a/service-worker.js +++ b/service-worker.js @@ -74,7 +74,7 @@ let imageDisplay = 'all'; // 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 -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 @@ -379,7 +379,7 @@ self.addEventListener('fetch', function (event) { if (!(regexpZIMUrlWithNamespace.test(strippedUrl) && /\.zim\//i.test(strippedUrl))) return; } // Don't cache download links - if (regexpKiwixDownloadLinks.test(rqUrl)) return; + if (regexpkiwixDownloadServers.test(rqUrl)) return; // Select cache depending on request format var cache = /\.zim\//i.test(strippedUrl) ? ASSETS_CACHE : APP_CACHE; cache = /youtube|vimeo/i.test(strippedUrl) ? ASSETS_CACHE : cache; diff --git a/www/js/app.js b/www/js/app.js index 32027d397..f1b2e8e4a 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1719,7 +1719,7 @@ document.getElementById('btnRefresh').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) { element.addEventListener('change', function () { diff --git a/www/js/init.js b/www/js/init.js index 9275f46ff..ead173110 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -81,8 +81,9 @@ params['cachedStartPages'] = { 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['kiwixDownloadLink'] = 'https://download.kiwix.org/zim/'; // Include final slash -params['kiwixHiddenDownloadLink'] = 'https://master.download.kiwix.org/zim/'; +params['kiwixDownloadServer'] = 'https://download.kiwix.org/zim/'; // Include final slash +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 ************/ params['PWAServer'] = 'https://pwa.kiwix.org/'; // Production server // params['PWAServer'] = 'https://kiwix.github.io/kiwix-js-pwa/dist/'; // Test server diff --git a/www/js/lib/cache.js b/www/js/lib/cache.js index a4400716b..831e80286 100644 --- a/www/js/lib/cache.js +++ b/www/js/lib/cache.js @@ -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) * * @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 * @returns {Promise} A Promise for a FileHandle object representing the downloaded file */ function downloadArchiveToPickedFolder (archiveName, archiveUrl, callback) { - archiveUrl = archiveUrl || params.kiwixDownloadLink + archiveName; + archiveUrl = archiveUrl || params.kiwixDownloadServer + archiveName; if (params.pickedFolder && params.pickedFolder.getFileHandle) { return verifyPermission(params.pickedFolder, true).then(function (permission) { if (permission) { diff --git a/www/js/lib/kiwixServe.js b/www/js/lib/kiwixServe.js index 386605b88..536529b64 100644 --- a/www/js/lib/kiwixServe.js +++ b/www/js/lib/kiwixServe.js @@ -478,7 +478,7 @@ function requestXhttpData (URL, lang, subj, kiwixDate) { torrentURL = URL.replace(/\.meta4$/i, '.torrent'); var header = document.getElementById('dl-panel-heading'); 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:'; altURL = requestedURL.replace(/\/master\./i, '/mirror.'); } @@ -490,7 +490,7 @@ function requestXhttpData (URL, lang, subj, kiwixDate) { '

' + requestedURL + '

' + (altURL ? '

Possible mirror:

' + '

' + altURL + '

' : '') + - (~URL.indexOf(params.kiwixHiddenDownloadLink) ? '' + (~URL.indexOf(params.kiwixhiddenDownloadServer) ? '' : '

Download with bittorrent:

' + '

' + torrentURL + '

'); body.outerHTML = body.outerHTML.replace(/]*)>[\s\S]*?<\/pre>/i, '' + bodyDoc + ''); @@ -515,8 +515,11 @@ function requestXhttpData (URL, lang, subj, kiwixDate) { } else { downloadLinks.innerHTML = '' + '

Unable to access the server. Please see message below for reason.

' + - '

You can either try again or else open this link in a new browser window:
' + - '' + params.kiwixDownloadLink + '


'; + '

You can either try again or else open one of these mirror links in a new browser window:

    '; + params.kiwixDownloadMirrors.forEach(function (mirror) { + downloadLinks.innerHTML += '
  • ' + mirror + '
  • '; + }); + downloadLinks.innerHTML += '

'; } downloadLinks.style.display = 'block'; } @@ -938,14 +941,14 @@ function requestXhttpData (URL, lang, subj, kiwixDate) { var dateID = dateSel ? dateSel.value : ''; var subjID = subjSel ? subjSel.value : ''; var replaceURL = URL + this.dataset.kiwixDl; - replaceURL = /(custom_apps|endless|dev)\//.test(this.text) ? params.kiwixHiddenDownloadLink + '.hidden/' + this.text : replaceURL; - replaceURL = /(archive)\//.test(this.text) ? params.kiwixDownloadLink.replace(/\/zim\//, '/archive/zim/') : replaceURL; + replaceURL = /(custom_apps|endless|dev)\//.test(this.text) ? params.kiwixhiddenDownloadServer + '.hidden/' + this.text : replaceURL; + replaceURL = /(archive)\//.test(this.text) ? params.kiwixDownloadServer.replace(/\/zim\//, '/archive/zim/') : replaceURL; // Allow both zim and zip format if (/\.zi[mp]$/i.test(this.dataset.kiwixDl)) { replaceURL = replaceURL + '.meta4'; } else if (/parent\s*directory|\.\.\//i.test(this.text)) { 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(/\/archive\/$/, '/zim/'); } else if (/Name|Size|Last\smodified|Description/.test(this.text)) {