diff --git a/backend/services/repo.go b/backend/services/repo.go index 8e5f02b0..9acc8387 100644 --- a/backend/services/repo.go +++ b/backend/services/repo.go @@ -55,20 +55,31 @@ func DownloadRepo(fullName string, userId bson.ObjectId) (err error) { } // 创建爬虫 - spider := model.Spider{ - Id: bson.NewObjectId(), - Name: spiderName, - DisplayName: spiderName, - Type: constants.Customized, - Src: spiderPath, - ProjectId: bson.ObjectIdHex(constants.ObjectIdNull), - FileId: bson.ObjectIdHex(constants.ObjectIdNull), - UserId: userId, - } - if err := spider.Add(); err != nil { - log.Error("add spider error: " + err.Error()) - debug.PrintStack() - return err + spider := model.GetSpiderByName(spiderName) + if spider.Name == "" { + // 新增 + spider := model.Spider{ + Id: bson.NewObjectId(), + Name: spiderName, + DisplayName: spiderName, + Type: constants.Customized, + Src: spiderPath, + ProjectId: bson.ObjectIdHex(constants.ObjectIdNull), + FileId: bson.ObjectIdHex(constants.ObjectIdNull), + UserId: userId, + } + if err := spider.Add(); err != nil { + log.Error("add spider error: " + err.Error()) + debug.PrintStack() + return err + } + } else { + // 更新 + if err := spider.Save(); err != nil { + log.Error("save spider error: " + err.Error()) + debug.PrintStack() + return err + } } // 上传爬虫 diff --git a/frontend/src/components/InfoView/TaskInfoView.vue b/frontend/src/components/InfoView/TaskInfoView.vue index a36923b2..1fd32852 100644 --- a/frontend/src/components/InfoView/TaskInfoView.vue +++ b/frontend/src/components/InfoView/TaskInfoView.vue @@ -71,6 +71,9 @@ + + {{ $t('Restart') }} + {{ $t('Stop') }} @@ -100,13 +103,28 @@ } }, methods: { - onRestart() { - }, onStop() { this.$store.dispatch('task/cancelTask', this.$route.params.id) .then(() => { this.$message.success(`Task "${this.$route.params.id}" has been sent signal to stop`) }) + this.$st.sendEv('任务详情', '概览', '停止任务') + }, + onRestart() { + this.$confirm(this.$t('Are you sure to restart this task?'), this.$t('Notification'), { + confirmButtonText: this.$t('Confirm'), + cancelButtonText: this.$t('Cancel'), + type: 'warning' + }).then(() => { + this.$store.dispatch('task/restartTask', this.taskForm._id) + .then(() => { + this.$message({ + type: 'success', + message: this.$t('Restarted successfully') + }) + }) + this.$st.sendEv('任务详情', '概览', '重新开始任务') + }) }, getTime(str) { if (!str || str.match('^0001')) return 'NA'