fix: "409 Conflict" on file/folder rename (#597)

This commit is contained in:
Rémi Marseault 2023-01-09 09:10:37 +01:00 committed by GitHub
parent 120ea2f2ae
commit 004c8f57d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View file

@ -177,14 +177,34 @@ export default {
this.toggleEditing(item)
},
renameFile(item) {
qbit.renameFile(this.hash, item.name, item.newName)
const lastPathSep = item.fullName.lastIndexOf("/")
const args = [this.hash]
if (lastPathSep === -1)
args.push(item.name, item.newName)
else {
const prefix = item.fullName.substring(0, lastPathSep)
args.push(`${prefix}/${item.name}`, `${prefix}/${item.newName}`)
}
qbit.renameFile(...args)
.catch(() => Vue.$toast.error(this.$t('toast.renameFileFailed')))
item.name = item.newName
this.toggleEditing(item)
},
renameFolder(item) {
qbit.renameFolder(this.hash, item.name, item.newName)
const lastPathSep = item.fullName.lastIndexOf("/")
const args = [this.hash]
if (lastPathSep === -1)
args.push(item.name, item.newName)
else {
const prefix = item.fullName.substring(0, lastPathSep)
args.push(`${prefix}/${item.name}`, `${prefix}/${item.newName}`)
}
qbit.renameFolder(...args)
.catch(() => Vue.$toast.error(this.$t('toast.renameFolderFailed')))
item.name = item.newName

View file

@ -1,7 +1,7 @@
import { isProduction } from './utils'
export function formatBytes(a, b) {
if (a == 0) return '0 B'
if (a === 0) return '0 B'
const c = 1024
const d = b || 2
const e = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
@ -69,10 +69,10 @@ export function treeify(paths) {
// parse folders
result = result.map(el => parseFolder(el))
function parseFolder(el) {
function parseFolder(el, parent) {
if (el.children.length !== 0) {
const folder = createFolder(el.name, el.children)
folder.children = folder.children.map(el => parseFolder(el))
const folder = createFolder(parent, el.name, el.children)
folder.children = folder.children.map(child => parseFolder(child, folder))
return folder
}
@ -96,10 +96,10 @@ function createFile(data, name, children) {
}
}
function createFolder(name, children) {
function createFolder(parent, name, children) {
return {
name: name,
fullName: name,
fullName: parent === undefined ? name : `${parent.fullName}/${name}`,
type: 'directory',
children: children
}