From 80051607c0788025840c15dcfb46be075c34a7da Mon Sep 17 00:00:00 2001 From: yulianfei Date: Fri, 21 Apr 2017 11:51:40 +0800 Subject: [PATCH] [Fix] Archive path may be upper dir of the root dir --- lib/public/js/app.js | 4 ++-- lib/routes.js | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/public/js/app.js b/lib/public/js/app.js index 95e80a1..3fb27fc 100644 --- a/lib/public/js/app.js +++ b/lib/public/js/app.js @@ -186,11 +186,11 @@ FMApp.controller('FileManagerCtr', ['$scope', '$http', '$location', if (!archive.match(/\.zip$/)) { archive += '.zip'; } - var url = 'api' + FM.curFolderPath; + var url = 'api' + FM.curFolderPath + archive; var src = FM.selection.map(function (file) { return file.relPath; }); - httpRequest('PUT', url, {type: 'ARCHIVE'}, {src: src, archive: archive, dirs: FM.archiveEmbedDirs}); + httpRequest('POST', url, {type: 'CREATE_ARCHIVE'}, {src: src, embedDirs: FM.archiveEmbedDirs}); }; FM.rename = function (newName) { diff --git a/lib/routes.js b/lib/routes.js index 7c8ea55..ff03a73 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -61,20 +61,13 @@ router.put('/api/(.*)', Tools.loadRealPath, Tools.checkPathExists, bodyParser(), yield * FileManager.rename(p, FilePath(target)); this.body = 'Rename Succeed!'; } - else if (type === 'ARCHIVE') { - var src = this.request.body.src; - var archive = (p === '.' ? '' : p) + this.request.body.archive; - if (!src) return this.status = 400; - yield * FileManager.archive(C.data.root, archive, src, !!this.request.body.dirs); - this.body = 'Create Archive Succeed!'; - } else { this.status = 400; this.body = 'Arg Type Error!'; } }); -router.post('/api/(.*)', Tools.loadRealPath, Tools.checkPathNotExists, function *() { +router.post('/api/(.*)', Tools.loadRealPath, Tools.checkPathNotExists, bodyParser(), function *() { var type = this.query.type; var p = this.request.fPath; if (!type) { @@ -97,6 +90,12 @@ router.post('/api/(.*)', Tools.loadRealPath, Tools.checkPathNotExists, function this.body = 'Lack Upload File!'; } } + else if (type === 'CREATE_ARCHIVE') { + var src = this.request.body.src; + if (!src) return this.status = 400; + yield * FileManager.archive(C.data.root, p, src, !!this.request.body.embedDirs); + this.body = 'Create Archive Succeed!'; + } else { this.status = 400; this.body = 'Arg Type Error!';