Add a way to detect that an archive is zimit2 (#1200)

This commit is contained in:
Jaifroid 2024-01-23 05:47:35 +00:00 committed by GitHub
parent e972f43609
commit a0a898ad27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -179,10 +179,12 @@ function ZIMArchive (storage, path, callbackReady, callbackError) {
} }
uiUtil.reportSearchProviderToAPIStatusPanel(params.searchProvider); uiUtil.reportSearchProviderToAPIStatusPanel(params.searchProvider);
} }
// Set the archive file type ('open' or 'zimit') // Set the archive file type ('open', 'zimit' or 'zimit2')
that.setZimType(); return that.addMetadataToZIMFile('Scraper').then(function () {
// If user is not using libzim for reading the file, we can call the ready callback now params.zimType = that.setZimType();
if (!params.useLibzim) whenZimReady(); // If user is not using libzim for reading the file, we can call the ready callback now
if (!params.useLibzim) whenZimReady();
});
}).catch(function (err) { }).catch(function (err) {
console.warn('Error setting archive listings: ', err); console.warn('Error setting archive listings: ', err);
}); });
@ -247,7 +249,7 @@ ZIMArchive.prototype.isReady = function () {
/** /**
* Detects whether the supplied archive is a Zimit-style archive or an OpenZIM archive and * Detects whether the supplied archive is a Zimit-style archive or an OpenZIM archive and
* sets a zimType property accordingly; also returns the detected type. Extends ZIMArchive. * sets a zimType property accordingly; also returns the detected type. Extends ZIMArchive.
* @returns {String} Either 'zimit' for a Zimit archive, or 'open' for an OpenZIM archive * @returns {String} 'zimit' for a classic Zimit archive, 'zimit2' for a zimit2 archive, or 'open' for an OpenZIM archive
*/ */
ZIMArchive.prototype.setZimType = function () { ZIMArchive.prototype.setZimType = function () {
var archiveType = null; var archiveType = null;
@ -256,6 +258,10 @@ ZIMArchive.prototype.setZimType = function () {
this.file.mimeTypes.forEach(function (v) { this.file.mimeTypes.forEach(function (v) {
if (/warc-headers/i.test(v)) archiveType = 'zimit'; if (/warc-headers/i.test(v)) archiveType = 'zimit';
}); });
if (archiveType !== 'zimit' && this.scraper) {
// Check if it's a zimit2 type archive by seeing if the scraper contains 'warc2zim'
archiveType = /warc2zim/i.test(this.scraper) ? 'zimit2' : archiveType;
}
this.zimType = archiveType; this.zimType = archiveType;
console.debug('Archive type set to: ' + archiveType); console.debug('Archive type set to: ' + archiveType);
} else { } else {