mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
修复可配置爬虫无法保存问题
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user