mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 12:19:46 -04:00
Changes in response to Kiwix JS code review
Former-commit-id: 66307ef22aa481d4f5e013992c8fc799a9775aac [formerly e0939860feb9244c3a510575431685cc5f81c5a0] Former-commit-id: 3e4f7a56319cb8484b0cec1a1f708156b01ee575
This commit is contained in:
parent
b08e770651
commit
f8c34ca62c
@ -140,7 +140,7 @@ define(['zimfile', 'zimDirEntry', 'transformZimit', 'util', 'utf8'],
|
||||
|
||||
/**
|
||||
* Detects whether the supplied archive is a Zimit-style archive or an OpenZIM archive and
|
||||
* sets a file.type property accordingly; also returns the detected type. Extends ZIMFile.
|
||||
* sets a _file.zimType property accordingly; also returns the detected type. Extends ZIMFile.
|
||||
* @returns {String} Either 'zimit' for a Zimit archive, or 'open' for an OpenZIM archive
|
||||
*/
|
||||
ZIMArchive.prototype.setZimType = function () {
|
||||
@ -150,7 +150,7 @@ define(['zimfile', 'zimDirEntry', 'transformZimit', 'util', 'utf8'],
|
||||
this._file.mimeTypes.forEach(function (v) {
|
||||
if (/warc-headers/i.test(v)) fileType = 'zimit';
|
||||
});
|
||||
this._file.type = fileType;
|
||||
this._file.zimType = fileType;
|
||||
console.debug('Archive type set to: ' + fileType);
|
||||
} else {
|
||||
console.error('ZIMArchive is not ready! Cannot set ZIM type.');
|
||||
@ -169,7 +169,7 @@ define(['zimfile', 'zimDirEntry', 'transformZimit', 'util', 'utf8'],
|
||||
var that = this;
|
||||
this._file.dirEntryByUrlIndex(mainPageUrlIndex).then(function (dirEntry) {
|
||||
// Filter out Zimit files that we cannot handle without error
|
||||
if (that._file.type === 'zimit') dirEntry = transformZimit.filterReplayFiles(dirEntry);
|
||||
if (that._file.zimType === 'zimit') dirEntry = transformZimit.filterReplayFiles(dirEntry);
|
||||
callback(dirEntry);
|
||||
});
|
||||
}
|
||||
@ -233,7 +233,7 @@ define(['zimfile', 'zimDirEntry', 'transformZimit', 'util', 'utf8'],
|
||||
var prefixNameSpaces = '';
|
||||
if (search.searchUrlIndex) {
|
||||
var rgxSplitPrefix = /^[-ABCHIJMUVWX]\//;
|
||||
if (that._file.type === 'zimit' && cns === 'C') {
|
||||
if (that._file.zimType === 'zimit' && cns === 'C') {
|
||||
// We have to account for the Zimit prefix in Type 1 ZIMs
|
||||
rgxSplitPrefix = /^[CMWX]\/(?:[AH]\/)?/;
|
||||
}
|
||||
@ -412,7 +412,7 @@ define(['zimfile', 'zimDirEntry', 'transformZimit', 'util', 'utf8'],
|
||||
ZIMArchive.prototype.resolveRedirect = function(dirEntry, callback) {
|
||||
var that = this;
|
||||
this._file.dirEntryByUrlIndex(dirEntry.redirectTarget).then(function (resolvedDirEntry) {
|
||||
if (that._file.type === 'zimit') resolvedDirEntry = transformZimit.filterReplayFiles(resolvedDirEntry);
|
||||
if (that._file.zimType === 'zimit') resolvedDirEntry = transformZimit.filterReplayFiles(resolvedDirEntry);
|
||||
callback(resolvedDirEntry);
|
||||
});
|
||||
};
|
||||
@ -526,11 +526,11 @@ define(['zimfile', 'zimDirEntry', 'transformZimit', 'util', 'utf8'],
|
||||
return that._file.dirEntryByUrlIndex(index);
|
||||
}).then(function (dirEntry) {
|
||||
// Filter Zimit dirEntries and do somee initial transforms
|
||||
if (that._file.type === 'zimit')
|
||||
if (that._file.zimType === 'zimit')
|
||||
dirEntry = transformZimit.filterReplayFiles(dirEntry);
|
||||
if (!dirEntry) {
|
||||
// We couldn't get the dirEntry, so look it up the Zimit header
|
||||
if (!zimitResolving && that._file.type === 'zimit' && !/^(H|C\/H)\//.test(path)) {
|
||||
if (!zimitResolving && that._file.zimType === 'zimit' && !/^(H|C\/H)\//.test(path)) {
|
||||
// We need to look the file up in the Header namespace (double replacement ensures both types of ZIM are supported)
|
||||
var oldPath = path;
|
||||
path = path.replace(/^A\//, 'H/').replace(/^(C\/)A\//, '$1H/');
|
||||
|
@ -86,6 +86,7 @@ define(['xzdec_wrapper', 'zstddec_wrapper', 'util', 'utf8', 'zimDirEntry', 'file
|
||||
* A ZIM File
|
||||
*
|
||||
* See https://wiki.openzim.org/wiki/ZIM_file_format#Header
|
||||
* Some properties below are extended and are not part of the official OpenZIM specification
|
||||
*
|
||||
* @typedef {Object} ZIMFile
|
||||
* @property {Array<File>} _files Array of ZIM files
|
||||
@ -101,7 +102,8 @@ define(['xzdec_wrapper', 'zstddec_wrapper', 'util', 'utf8', 'zimDirEntry', 'file
|
||||
* @property {Integer} mimeListPos Position of the MIME type list (also header size)
|
||||
* @property {Integer} mainPage Main page or 0xffffffff if no main page
|
||||
* @property {Integer} layoutPage Layout page or 0xffffffffff if no layout page
|
||||
* @property {Map} mimeTypes The ZIM file's MIME type table rendered as a Map (calculated entry)
|
||||
* @property {String} zimType Extended property: currently either 'open' for OpenZIM file type, or 'zimit' for the warc2zim file type used by Zimit (set in zimArchive.js)
|
||||
* @property {Map} mimeTypes Extended property: the ZIM file's MIME type table rendered as a Map (calculated entry)
|
||||
*/
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user