From dd08a8b0dc50b06a1b5fa9f7eabfb87fd4bdb7fa Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Tue, 4 Jun 2019 20:45:56 +0800 Subject: [PATCH] added upload functionality --- crawlab/routes/spiders.py | 15 +++++++++++++-- frontend/src/views/spider/SpiderList.vue | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crawlab/routes/spiders.py b/crawlab/routes/spiders.py index 0f1772e9..de5feb94 100644 --- a/crawlab/routes/spiders.py +++ b/crawlab/routes/spiders.py @@ -837,8 +837,7 @@ class SpiderManageApi(Resource): } def upload(self): - args = self.parser.parse_args() - f = request.files[0] + f = request.files['file'] if get_file_suffix(f.filename) != 'zip': return { @@ -856,3 +855,15 @@ class SpiderManageApi(Resource): if os.path.exists(dir_path): shutil.rmtree(dir_path) unzip_file(file_path, dir_path) + + # copy to source folder + output_path = os.path.join(PROJECT_SOURCE_FILE_FOLDER, f.filename.replace('.zip', '')) + print(output_path) + if os.path.exists(output_path): + shutil.rmtree(output_path) + shutil.copytree(dir_path, output_path) + + return { + 'status': 'ok', + 'message': 'success' + } diff --git a/frontend/src/views/spider/SpiderList.vue b/frontend/src/views/spider/SpiderList.vue index 4b9fa610..0c0cd0c6 100644 --- a/frontend/src/views/spider/SpiderList.vue +++ b/frontend/src/views/spider/SpiderList.vue @@ -87,7 +87,7 @@ :action="$request.baseUrl + '/spiders/manage/upload'" :on-success="onUploadSuccess" :file-list="fileList"> - {{$t('Upload')}} + {{$t('Upload')}} @@ -493,6 +493,14 @@ export default { }) }, onUploadSuccess () { + // clear fileList + this.fileList = [] + + // fetch spider list + this.$store.dispatch('spider/getSpiderList') + + // close popup + this.addCustomizedDialogVisible = false } }, created () {