diff --git a/backend/routes/config_spider.go b/backend/routes/config_spider.go index ac6a11e0..4c65964e 100644 --- a/backend/routes/config_spider.go +++ b/backend/routes/config_spider.go @@ -51,6 +51,9 @@ func PutConfigSpider(c *gin.Context) { // 将FileId置空 spider.FileId = bson.ObjectIdHex(constants.ObjectIdNull) + // UserId + spider.UserId = services.GetCurrentUserId(c) + // 创建爬虫目录 spiderDir := filepath.Join(viper.GetString("spider.path"), spider.Name) if utils.Exists(spiderDir) { @@ -109,8 +112,12 @@ func UploadConfigSpider(c *gin.Context) { spider, err := model.GetSpider(bson.ObjectIdHex(id)) if err != nil { HandleErrorF(http.StatusBadRequest, c, fmt.Sprintf("cannot find spider (id: %s)", id)) + return } + // UserId + spider.UserId = services.GetCurrentUserId(c) + // 获取上传文件 file, header, err := c.Request.FormFile("file") if err != nil { @@ -205,6 +212,11 @@ func PostConfigSpiderSpiderfile(c *gin.Context) { return } + // UserId + if !spider.UserId.Valid() { + spider.UserId = bson.ObjectIdHex(constants.ObjectIdNull) + } + // 反序列化 var configData entity.ConfigSpiderData if err := yaml.Unmarshal([]byte(content), &configData); err != nil { @@ -247,6 +259,11 @@ func PostConfigSpiderConfig(c *gin.Context) { return } + // UserId + if !spider.UserId.Valid() { + spider.UserId = bson.ObjectIdHex(constants.ObjectIdNull) + } + // 反序列化配置数据 var configData entity.ConfigSpiderData if err := c.ShouldBindJSON(&configData); err != nil { diff --git a/backend/routes/spider.go b/backend/routes/spider.go index b136070b..8f7a513b 100644 --- a/backend/routes/spider.go +++ b/backend/routes/spider.go @@ -126,6 +126,11 @@ func PostSpider(c *gin.Context) { return } + // UserId + if !item.UserId.Valid() { + item.UserId = bson.ObjectIdHex(constants.ObjectIdNull) + } + if err := model.UpdateSpider(bson.ObjectIdHex(id), item); err != nil { HandleError(http.StatusInternalServerError, c, err) return