mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-22 17:31:03 +01:00
35 lines
765 B
Go
35 lines
765 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/crawlab-team/crawlab/core/models/models"
|
|
"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 := GetWorkspace()
|
|
|
|
// get spider root path
|
|
rootPath, err = GetSpiderRootPath(s)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return filepath.Join(workspacePath, rootPath), nil
|
|
}
|