Skip to content

Commit

Permalink
fix: nested directory upload preserves the directory structure (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechsimetka authored May 16, 2022
1 parent efd3158 commit 86978b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/pages/files/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function Upload(): ReactElement {
return
}

let fls = files.map(packageFile) // Apart from packaging, this is needed to not modify the original files array as it can trigger effects
let fls: FilePath[] = files.map(f => packageFile(f)) // Apart from packaging, this is needed to not modify the original files array as it can trigger effects
let indexDocument: string | undefined = undefined // This means we assume it's folder

if (files.length === 1) indexDocument = files[0].name
Expand All @@ -84,10 +84,10 @@ export function Upload(): ReactElement {
if (idx.commonPrefix) {
const substrStart = idx.commonPrefix.length
indexDocument = idx.indexPath.substr(substrStart)
fls = fls.map(f => {
fls = files.map(f => {
const path = (f.path as string).substr(substrStart)

return { ...f, path, webkitRelativePath: path, fullPath: path }
return packageFile(f, path)
})
} else {
// The website is not packed in a directory
Expand Down
4 changes: 2 additions & 2 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export function getPath(file: FilePath): string {
/**
* Utility function that is needed to have correct directory structure as webkitRelativePath is read only
*/
export function packageFile(file: FilePath): FilePath {
const path = getPath(file)
export function packageFile(file: FilePath, pathOverwrite?: string): FilePath {
const path = pathOverwrite || getPath(file)

return {
path: path,
Expand Down

0 comments on commit 86978b7

Please sign in to comment.