Skip to content

Commit

Permalink
fix: correct folder name when uploading multiple files or mix of file…
Browse files Browse the repository at this point in the history
…s & directories (#291)
  • Loading branch information
vojtechsimetka committed Jan 24, 2022
1 parent bc82e67 commit d878747
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]

if (files.length === 1) {
return files[0].name
// 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
}

return files[0].path.split('/')[0]
return 'unknown'
}

0 comments on commit d878747

Please sign in to comment.