added upload functionality

This commit is contained in:
Marvin Zhang
2019-06-04 20:45:56 +08:00
parent 44a941c72a
commit dd08a8b0dc
2 changed files with 22 additions and 3 deletions

View File

@@ -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'
}

View File

@@ -87,7 +87,7 @@
:action="$request.baseUrl + '/spiders/manage/upload'"
:on-success="onUploadSuccess"
:file-list="fileList">
<el-button size="small" type="primary">{{$t('Upload')}}</el-button>
<el-button type="primary" icon="el-icon-upload">{{$t('Upload')}}</el-button>
</el-upload>
</el-form-item>
</el-form>
@@ -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 () {