Skip to content

Commit

Permalink
[ADD] Split zim for FS API
Browse files Browse the repository at this point in the history
[ADD] Filter to show only zim file in dropdown
  • Loading branch information
Rishabhg71 committed Oct 19, 2023
1 parent fbfe8d4 commit 91d1ace
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 16 additions & 7 deletions www/js/lib/fileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import cache from './cache.js';
async function updateZimDropdownOptions (fileSystemHandler, selectedFile) {
const select = document.getElementById('zimSelectDropdown')
let options = '<option value="" disabled selected>Select a file...</option>'

fileSystemHandler.files.forEach(fileName => {
options += `<option value="${fileName}">${fileName}</option>`
if (fileName.endsWith('.zim') || fileName.endsWith('.zimaa')) options += `<option value="${fileName}">${fileName}</option>`
});
select.innerHTML = options

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
document.getElementById('zimSelectDropdown').value = selectedFile
Expand Down Expand Up @@ -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])
}
})
})
Expand Down

0 comments on commit 91d1ace

Please sign in to comment.