39 lines
885 B
Go
39 lines
885 B
Go
|
|
package logic
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"img_infinite_canvas/internal/domain/design"
|
||
|
|
)
|
||
|
|
|
||
|
|
func validateRequiredPrompt(prompt string, allowEmpty bool) error {
|
||
|
|
if allowEmpty {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
if hasRequiredPromptText(prompt) {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return fmt.Errorf("%w: prompt is required", design.ErrInvalidInput)
|
||
|
|
}
|
||
|
|
|
||
|
|
func hasRequiredPromptText(prompt string) bool {
|
||
|
|
for _, line := range strings.Split(prompt, "\n") {
|
||
|
|
line = strings.TrimSpace(strings.ReplaceAll(line, "\u00a0", " "))
|
||
|
|
if line == "" || isPromptReferenceDirective(line) {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
return true
|
||
|
|
}
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
|
||
|
|
func isPromptReferenceDirective(line string) bool {
|
||
|
|
lower := strings.ToLower(line)
|
||
|
|
hasURL := strings.Contains(lower, "http://") || strings.Contains(lower, "https://")
|
||
|
|
if !hasURL {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
return strings.HasPrefix(line, "参考图") || strings.HasPrefix(lower, "reference image")
|
||
|
|
}
|