diff --git a/www/js/app.js b/www/js/app.js
index 3fc1431ff..64f0a7810 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -1289,8 +1289,8 @@ function displayFileSelect () {
// handle zim selection from dropdown if multiple files are loaded via webkitdirectory or filesystem api
console.log(e.target.value);
if (isFileSystemAPISupported) {
- const file = await fileSystem.getSelectedZimFromCache(e.target.value)
- setLocalArchiveFromFileList([file]);
+ const files = await fileSystem.getSelectedZimFromCache(e.target.value)
+ setLocalArchiveFromFileList(files);
} else {
const files = fileSystem.getSelectedZimFromWebkitList(webKitFileList, e.target.value)
console.log(files);
diff --git a/www/js/lib/fileSystem.js b/www/js/lib/fileSystem.js
index 77a0410dc..1ae30dadb 100644
--- a/www/js/lib/fileSystem.js
+++ b/www/js/lib/fileSystem.js
@@ -12,8 +12,9 @@ import cache from './cache.js';
async function updateZimDropdownOptions (fileSystemHandler, selectedFile) {
const select = document.getElementById('zimSelectDropdown')
let options = ''
+
fileSystemHandler.files.forEach(fileName => {
- options += ``
+ if (fileName.endsWith('.zim') || fileName.endsWith('.zimaa')) options += ``
});
select.innerHTML = options
document.getElementById('zimSelectDropdown').value = selectedFile
@@ -58,15 +59,23 @@ function getSelectedZimFromCache (selectedFilename) {
return new Promise((resolve, reject) => {
cache.idxDB('zimFiles', async function (FSHandler) {
// const selectedFile = FSHandler.fileOrDirHandle
- console.log(await FSHandler.fileOrDirHandle.queryPermission());
if (await FSHandler.fileOrDirHandle.queryPermission() !== 'granted') await FSHandler.fileOrDirHandle.requestPermission()
- let file = null
+
if (FSHandler.fileOrDirHandle.kind === 'directory') {
- file = await (await FSHandler.fileOrDirHandle.getFileHandle(selectedFilename)).getFile()
- resolve(file)
+ const files = []
+ for await (const entry of FSHandler.fileOrDirHandle.values()) {
+ const filenameWithoutExtension = selectedFilename.replace(/\.zim\w\w$/i, '')
+ const regex = new RegExp(`\\${filenameWithoutExtension}.zim\\w\\w$`, 'i');
+ if (regex.test(entry.name) || entry.name === selectedFilename) {
+ files.push(await entry.getFile())
+ }
+ }
+ // files = await (await FSHandler.fileOrDirHandle.getFileHandle(selectedFilename)).getFile()
+ console.log(files);
+ resolve(files)
} else {
- file = await FSHandler.fileOrDirHandle.getFile();
- resolve(file)
+ const file = await FSHandler.fileOrDirHandle.getFile();
+ resolve([file])
}
})
})