mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-31 18:10:50 +01:00
feat: optimized dependencies for spider
This commit is contained in:
35
core/utils/spider.go
Normal file
35
core/utils/spider.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/crawlab-team/crawlab/core/models/models"
|
||||
"github.com/spf13/viper"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func GetSpiderRootPath(s *models.Spider) (rootPath string, err error) {
|
||||
// check git permission
|
||||
if !IsPro() && !s.GitId.IsZero() {
|
||||
return "", errors.New("git is not allowed in the community version")
|
||||
}
|
||||
|
||||
// if git id is zero, return spider id as root path
|
||||
if s.GitId.IsZero() {
|
||||
return s.Id.Hex(), nil
|
||||
}
|
||||
|
||||
return filepath.Join(s.GitId.Hex(), s.GitRootPath), nil
|
||||
}
|
||||
|
||||
func GetSpiderFullRootPath(s *models.Spider) (rootPath string, err error) {
|
||||
// workspace path
|
||||
workspacePath := viper.GetString("workspace")
|
||||
|
||||
// get spider root path
|
||||
rootPath, err = GetSpiderRootPath(s)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return filepath.Join(workspacePath, rootPath), nil
|
||||
}
|
||||
Reference in New Issue
Block a user