mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
fix 上传爬虫名称错误的问题
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/apex/log"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -25,6 +26,19 @@ type File struct {
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func GetAllGridFs() []*GridFs {
|
||||
s, gf := database.GetGridFs("files")
|
||||
defer s.Close()
|
||||
|
||||
var files []*GridFs
|
||||
if err := gf.Find(nil).All(&files); err != nil {
|
||||
log.Errorf("get all files error: {}", err.Error())
|
||||
debug.PrintStack()
|
||||
return nil
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
func GetGridFs(id bson.ObjectId) *GridFs {
|
||||
s, gf := database.GetGridFs("files")
|
||||
defer s.Close()
|
||||
@@ -33,6 +47,7 @@ func GetGridFs(id bson.ObjectId) *GridFs {
|
||||
err := gf.Find(bson.M{"_id": id}).One(&gfFile)
|
||||
if err != nil {
|
||||
log.Errorf("get gf file error: %s, file_id: %s", err.Error(), id.Hex())
|
||||
debug.PrintStack()
|
||||
return nil
|
||||
}
|
||||
return &gfFile
|
||||
@@ -41,6 +56,7 @@ func GetGridFs(id bson.ObjectId) *GridFs {
|
||||
func RemoveFile(path string) error {
|
||||
if !utils.Exists(path) {
|
||||
log.Info("file not found: " + path)
|
||||
debug.PrintStack()
|
||||
return nil
|
||||
}
|
||||
if err := os.Remove(path); err != nil {
|
||||
|
||||
@@ -124,6 +124,10 @@ func GetSpiderList(filter interface{}, skip int, limit int) ([]Spider, int, erro
|
||||
return spiders, count, nil
|
||||
}
|
||||
|
||||
func GetSpiderByFileId(fileId bson.ObjectId) {
|
||||
|
||||
}
|
||||
|
||||
func GetSpiderByName(name string) *Spider {
|
||||
s, c := database.GetCol("spiders")
|
||||
defer s.Close()
|
||||
|
||||
@@ -161,8 +161,12 @@ func PutSpider(c *gin.Context) {
|
||||
debug.PrintStack()
|
||||
return
|
||||
}
|
||||
|
||||
idx := strings.LastIndex(uploadFile.Filename, "/")
|
||||
targetFilename := uploadFile.Filename[idx+1:]
|
||||
|
||||
// 判断爬虫是否存在
|
||||
spiderName := strings.Replace(uploadFile.Filename, ".zip", "", -1)
|
||||
spiderName := strings.Replace(targetFilename, ".zip", "", 1)
|
||||
spider := model.GetSpiderByName(spiderName)
|
||||
if spider == nil {
|
||||
// 保存爬虫信息
|
||||
|
||||
Reference in New Issue
Block a user