Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement of key type testing in recursive build #4

Open
qtipee opened this issue Nov 6, 2019 · 0 comments
Open

Enhancement of key type testing in recursive build #4

qtipee opened this issue Nov 6, 2019 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@qtipee
Copy link
Collaborator

qtipee commented Nov 6, 2019

When recursively re-building the hierarchical structure of the uploaded files from the Map, we need to test if the current key is a file or a folder. For now, the way of testing is by checking wether the key has a dot in its name (for the file extension) ; a folder containing a dot in its name will cause trouble. Need to find a better way to test the type of the key.

Using typeof won't work, because it returns object in both cases (File and Map are objects).

//
function folderRecursiveBuild(currentFolder, parentFolder=zipBuilder)
{
let htmlTree = '';
for (let [k, v] of currentFolder)
{
// Audio file
//FIXME: to improve ; cannot have a folder with a .
if (k.includes('.'))
{
parentFolder.file(v.name, v);
htmlTree += '<li><a href="' + v.webkitRelativePath + '" class="audio-src">' + v.name + '</a><a href="' + v.webkitRelativePath + '" class="cache-audio">Download</a></li>';
}
// Folder
else
{
htmlTree += '<ul><li>' + k + '</li>';
htmlTree += folderRecursiveBuild(v, parentFolder.folder(k));
htmlTree += '</ul>';
}
}
return htmlTree;
}

@qtipee qtipee added the help wanted Extra attention is needed label Nov 6, 2019
@qtipee qtipee changed the title Improvement of file testing in recursive build Improvement of key type testing in recursive build Nov 6, 2019
@qtipee qtipee changed the title Improvement of key type testing in recursive build Enhancement of key type testing in recursive build Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant