-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: streamline file service retrieval and enhance spider templa…
…te handling - Replaced direct calls to getBaseFileFsSvc with a new method fs.GetBaseFileFsSvc in base_file.go for improved clarity and maintainability. - Introduced SpiderTemplateService interface and implemented registry service for managing spider templates, enhancing template handling in the spider controller. - Added template-related fields to the Spider model to support template functionality. - Created utility functions for string case conversions in utils/string.go to facilitate consistent formatting across the codebase. - Updated environment configuration to retrieve the Python path dynamically, improving flexibility in the task runner's setup.
- Loading branch information
Marvin Zhang
committed
Jan 6, 2025
1 parent
f5d9ccf
commit 8d8b47e
Showing
9 changed files
with
110 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package fs | ||
|
||
import ( | ||
"github.com/crawlab-team/crawlab/core/interfaces" | ||
"github.com/crawlab-team/crawlab/core/utils" | ||
"path/filepath" | ||
) | ||
|
||
func GetBaseFileFsSvc(rootPath string) (svc interfaces.FsService, err error) { | ||
workspacePath := utils.GetWorkspace() | ||
fsSvc := NewFsService(filepath.Join(workspacePath, rootPath)) | ||
|
||
return fsSvc, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package interfaces | ||
|
||
import "go.mongodb.org/mongo-driver/bson/primitive" | ||
|
||
type SpiderTemplateService interface { | ||
CreateTemplate(id primitive.ObjectID) (err error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package spider | ||
|
||
import "github.com/crawlab-team/crawlab/core/interfaces" | ||
|
||
var templateSvcInstance interfaces.SpiderTemplateService | ||
|
||
func SetSpiderTemplateRegistryService(svc interfaces.SpiderTemplateService) { | ||
templateSvcInstance = svc | ||
} | ||
|
||
func GetSpiderTemplateRegistryService() interfaces.SpiderTemplateService { | ||
return templateSvcInstance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package utils | ||
|
||
import ( | ||
"golang.org/x/text/cases" | ||
"golang.org/x/text/language" | ||
"strings" | ||
) | ||
|
||
func ToSnakeCase(s string) string { | ||
s = strings.TrimSpace(s) | ||
s = strings.ToLower(s) | ||
s = strings.ReplaceAll(s, " ", "_") | ||
s = strings.ReplaceAll(s, "-", "_") | ||
return s | ||
} | ||
|
||
func ToPascalCase(s string) string { | ||
s = strings.TrimSpace(s) | ||
s = strings.ReplaceAll(s, "_", " ") | ||
s = cases.Title(language.English).String(s) | ||
s = strings.ReplaceAll(s, " ", "") | ||
return s | ||
} |