mirror of
https://github.com/VueTorrent/VueTorrent.git
synced 2025-03-14 12:10:18 +03:00
fix: "409 Conflict" on file/folder rename (#597)
This commit is contained in:
parent
120ea2f2ae
commit
004c8f57d2
2 changed files with 28 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue