diff --git a/backend/file.js b/backend/file.js index 5f1a5b0d..a2864d03 100644 --- a/backend/file.js +++ b/backend/file.js @@ -39,18 +39,12 @@ const rmRecursiveSync = location => { const resolvePath = (p, repo = 'main') => { p = p.replace(/\.\./g, '') - if (repo === 'trash') { - p = path.join(__dirname, '/../trash/', p) - } else { - const basePath = repository.getPath(repo) - if (!basePath) { - throw new Error(`仓库 ${repo} 不存在`) - } - - p = path.join(basePath, p) + const basePath = repository.getPath(repo) + if (!basePath) { + throw new Error(`仓库 ${repo} 不存在`) } - return p + return path.join(basePath, p) } const travels = (location, repo, basePath = null) => { @@ -105,7 +99,7 @@ exports.write = (repo, p, content) => { exports.rm = (repo, p) => { if (resolvePath(p) !== resolvePath('', repo)) { - const newPath = resolvePath(p, 'trash') + '.' + (new Date).getTime() + const newPath = path.join(repository.getTrashPath(repo), p.replace(/\.\./g, '')) + '.' + (new Date).getTime() mkdirPSync(path.dirname(newPath)) diff --git a/backend/repository.js b/backend/repository.js index dab1f446..9d14c4a5 100644 --- a/backend/repository.js +++ b/backend/repository.js @@ -21,3 +21,7 @@ exports.getPath = name => { return path.join(__dirname, '../', p) } + +exports.getTrashPath = name => { + return path.join(__dirname, '/../trash/', name) +}