fix: correct folder name when uploading multiple files or mix of files & directories (#291)
This commit is contained in:
+8
-7
@@ -77,13 +77,14 @@ export function convertManifestToFiles(files: Record<string, string>): SwarmFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getAssetNameFromFiles(files: SwarmFile[]): string {
|
export function getAssetNameFromFiles(files: SwarmFile[]): string {
|
||||||
if (!files.length) {
|
if (files.length === 1) return files[0].name
|
||||||
return 'Unknown'
|
|
||||||
|
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 'unknown'
|
||||||
return files[0].name
|
|
||||||
}
|
|
||||||
|
|
||||||
return files[0].path.split('/')[0]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user