Skip to content

Commit

Permalink
fix: "409 Conflict" on file/folder rename (VueTorrent#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsluph authored Jan 9, 2023
1 parent 120ea2f commit 004c8f5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
24 changes: 22 additions & 2 deletions src/components/TorrentDetail/Tabs/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -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']
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 004c8f5

Please sign in to comment.