fix: correct folder name when uploading multiple files or mix of files & directories (#291)

This commit is contained in:
Vojtech Simetka
2022-01-24 18:03:06 +01:00
committed by GitHub
parent bc82e67561
commit d8787476ac
+8 -7
View File
@@ -77,13 +77,14 @@ export function convertManifestToFiles(files: Record<string, string>): SwarmFile
}
export function getAssetNameFromFiles(files: SwarmFile[]): string {
if (!files.length) {
return 'Unknown'
if (files.length === 1) return files[0].name
if (files.length > 0) {
const prefix = files[0].path.split('/')[0]
// Only if all files have a common prefix we can use it as a folder name
if (files.every(f => f.path.split('/')[0] === prefix)) return prefix
}
if (files.length === 1) {
return files[0].name
}
return files[0].path.split('/')[0]
return 'unknown'
}