Skip to content

Commit

Permalink
fix: file path on upload (#1330)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas authored Jan 29, 2024
1 parent 68a4666 commit 1bb738a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/mixins/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,9 @@ export default class FilesMixin extends Vue {
* @param options Axios request options
*/
async uploadFile (file: File, path: string, root: string, andPrint: boolean, options?: AxiosRequestConfig) {
// let filename = file.name.replace(' ', '_')
let filepath = `${path}${file.name}`
filepath = (filepath.startsWith('/'))
? filepath
: '/' + filepath
const filepath = path
? `${path}/${file.name}`
: file.name

const abortController = new AbortController()

Expand Down Expand Up @@ -205,7 +203,9 @@ export default class FilesMixin extends Vue {
getFullPathAndFile (rootPath: string, file: File | FileWithPath): [string, File] {
if ('path' in file) {
return [
`${rootPath}/${file.path}`,
[rootPath, file.path]
.filter(path => !!path)
.join('/'),
file.file
]
} else {
Expand All @@ -222,10 +222,10 @@ export default class FilesMixin extends Vue {
for (const file of files) {
const [fullPath, fileObject] = this.getFullPathAndFile(path, file)

let filepath = `${fullPath}${fileObject.name}`
filepath = (filepath.startsWith('/'))
? filepath
: '/' + filepath
const filepath = fullPath
? `${fullPath}/${fileObject.name}`
: fileObject.name

this.$store.dispatch('files/updateFileUpload', {
filepath,
size: fileObject.size,
Expand All @@ -244,10 +244,10 @@ export default class FilesMixin extends Vue {
for (const file of files) {
const [fullPath, fileObject] = this.getFullPathAndFile(path, file)

let filepath = `${fullPath}${fileObject.name}`
filepath = (filepath.startsWith('/'))
? filepath
: '/' + filepath
const filepath = fullPath
? `${fullPath}/${fileObject.name}`
: fileObject.name

const fileState = this.$store.state.files.uploads.find((u: FilesUpload) => u.filepath === filepath)

if (fileState && !fileState?.cancelled) {
Expand Down
8 changes: 6 additions & 2 deletions src/util/file-system-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export const convertFilesToFilesWithPath = (files: File[] | FileList) => {
return [...files]
.map((file): FileWithPath => ({
file,
path: file.webkitRelativePath.slice(0, -file.name.length)
path: file.webkitRelativePath === file.name
? ''
: file.webkitRelativePath.slice(0, -file.name.length - 1)
}))
}

Expand Down Expand Up @@ -89,7 +91,9 @@ export const getFilesFromFileSystemEntries = async (entries: readonly FileSystem
for (const entry of subEntries) {
items.push({
entry,
path: item.path + item.entry.name + '/'
path: item.path
? `${item.path}/${item.entry.name}`
: item.entry.name
})
}
}
Expand Down

0 comments on commit 1bb738a

Please sign in to comment.