diff --git a/src/components/TorrentDetail/Tabs/Content.vue b/src/components/TorrentDetail/Tabs/Content.vue index 11949fb195b..a6af270ffdd 100644 --- a/src/components/TorrentDetail/Tabs/Content.vue +++ b/src/components/TorrentDetail/Tabs/Content.vue @@ -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 diff --git a/src/helpers.js b/src/helpers.js index 68ad9a298f8..9884118012c 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -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 }