Skip to content

Enhancement of key type testing in recursive build #4

@qtipee

Description

@qtipee

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions