From 6bbf77bca52ef471d64a19f1714b254ce90a9a7f Mon Sep 17 00:00:00 2001 From: marvzhang Date: Mon, 30 Dec 2019 13:39:36 +0800 Subject: [PATCH] fixed https://github.com/crawlab-team/crawlab/issues/407 --- backend/routes/spider.go | 38 ++++++++++++++++++++++-- frontend/src/views/spider/SpiderList.vue | 11 ++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/backend/routes/spider.go b/backend/routes/spider.go index 1ca45f05..a5623b67 100644 --- a/backend/routes/spider.go +++ b/backend/routes/spider.go @@ -185,10 +185,15 @@ func UploadSpider(c *gin.Context) { return } + // 获取参数 + name := c.PostForm("name") + displayName := c.PostForm("display_name") + col := c.PostForm("col") + cmd := c.PostForm("cmd") + // 如果不为zip文件,返回错误 if !strings.HasSuffix(uploadFile.Filename, ".zip") { - debug.PrintStack() - HandleError(http.StatusBadRequest, c, errors.New("Not a valid zip file")) + HandleError(http.StatusBadRequest, c, errors.New("not a valid zip file")) return } @@ -198,7 +203,7 @@ func UploadSpider(c *gin.Context) { if err := os.MkdirAll(tmpPath, os.ModePerm); err != nil { log.Error("mkdir other.tmppath dir error:" + err.Error()) debug.PrintStack() - HandleError(http.StatusBadRequest, c, errors.New("Mkdir other.tmppath dir error")) + HandleError(http.StatusBadRequest, c, errors.New("mkdir other.tmppath dir error")) return } } @@ -237,6 +242,9 @@ func UploadSpider(c *gin.Context) { // 判断爬虫是否存在 spiderName := strings.Replace(targetFilename, ".zip", "", 1) + if name != "" { + spiderName = name + } spider := model.GetSpiderByName(spiderName) if spider.Name == "" { // 保存爬虫信息 @@ -248,8 +256,32 @@ func UploadSpider(c *gin.Context) { Src: filepath.Join(srcPath, spiderName), FileId: fid, } + if name != "" { + spider.Name = name + } + if displayName != "" { + spider.DisplayName = displayName + } + if col != "" { + spider.Col = col + } + if cmd != "" { + spider.Cmd = cmd + } _ = spider.Add() } else { + if name != "" { + spider.Name = name + } + if displayName != "" { + spider.DisplayName = displayName + } + if col != "" { + spider.Col = col + } + if cmd != "" { + spider.Cmd = cmd + } // 更新file_id spider.FileId = fid _ = spider.Save() diff --git a/frontend/src/views/spider/SpiderList.vue b/frontend/src/views/spider/SpiderList.vue index 09ecab4b..80c3fa0b 100644 --- a/frontend/src/views/spider/SpiderList.vue +++ b/frontend/src/views/spider/SpiderList.vue @@ -51,6 +51,7 @@ @@ -325,7 +326,15 @@ export default { ]), ...mapGetters('user', [ 'token' - ]) + ]), + uploadForm () { + return { + name: this.spiderForm.name, + display_name: this.spiderForm.display_name, + col: this.spiderForm.col, + cmd: this.spiderForm.cmd + } + } }, methods: { onSpiderTypeChange (val) {