Refactor AIGC ID Handling in Load Function

- Renamed the ID generation function to `aigcID` for clarity and added a new function to parse AIGC IDs from file paths.
- Implemented special handling for `.ai.yml` and `.ai.yaml` extensions to correctly format the AIGC ID by removing the "_ai" suffix, improving ID accuracy in the loading process.
This commit is contained in:
Max 2025-12-15 12:10:01 +08:00
parent 5830c3d177
commit 2a191950d7

View file

@ -28,7 +28,7 @@ func Load(cfg config.Config) error {
return nil
}
id := share.ID(root, file)
id := aigcID(root, file)
_, err := LoadFile(file, id)
if err != nil {
messages = append(messages, err.Error())
@ -48,6 +48,17 @@ func Load(cfg config.Config) error {
return nil
}
// aigcID parses AIGC ID from file path
// Special handling for .ai.yml and .ai.yaml extensions
// e.g., "aigcs/translate.ai.yml" -> "translate"
func aigcID(root, file string) string {
id := share.ID(root, file)
// Remove "_ai" suffix caused by .ai.yml/.ai.yaml extension
// share.ID treats .yml/.yaml as single extension, so "translate.ai.yml" becomes "translate_ai"
id = strings.TrimSuffix(id, "_ai")
return id
}
// LoadFile load AIGC by file
func LoadFile(file string, id string) (*DSL, error) {