- Updated .env.example to include new configuration options for the UltiAI branding and API endpoints. - Enhanced Nginx configuration to support new API routes for the MCP and WebSocket connections. - Introduced sub-filters for branding adjustments in Nginx responses. - Added new JavaScript patch for API endpoint adjustments. - Implemented tests for new API functionalities and improved error handling in the AI gateway.
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package search
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/ultisuite/ulti-backend/internal/api/apivalidate"
|
|
)
|
|
|
|
const (
|
|
minSearchQueryLen = 1
|
|
maxSearchQueryLen = 500
|
|
)
|
|
|
|
var allowedSearchTypes = map[string]struct{}{
|
|
"mail": {},
|
|
"contacts": {},
|
|
"files": {},
|
|
"events": {},
|
|
}
|
|
|
|
func validateSearchQuery(q string) *apivalidate.ValidationError {
|
|
q = strings.TrimSpace(q)
|
|
if q == "" {
|
|
return apivalidate.NewValidationError(apivalidate.FieldDetail{
|
|
Field: "q", Message: "required",
|
|
})
|
|
}
|
|
if len(q) < minSearchQueryLen {
|
|
return apivalidate.NewValidationError(apivalidate.FieldDetail{
|
|
Field: "q", Message: "too short",
|
|
})
|
|
}
|
|
if len(q) > maxSearchQueryLen {
|
|
return apivalidate.NewValidationError(apivalidate.FieldDetail{
|
|
Field: "q", Message: "too long",
|
|
})
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateSearchTypes(typesRaw string) *apivalidate.ValidationError {
|
|
if strings.TrimSpace(typesRaw) == "" {
|
|
return nil
|
|
}
|
|
for _, part := range strings.Split(typesRaw, ",") {
|
|
t := strings.TrimSpace(part)
|
|
if t == "" {
|
|
continue
|
|
}
|
|
if _, ok := allowedSearchTypes[t]; !ok {
|
|
return apivalidate.NewValidationError(apivalidate.FieldDetail{
|
|
Field: "types", Message: "invalid value: " + t,
|
|
})
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func parseSearchOptionalBool(raw string) bool {
|
|
switch strings.ToLower(strings.TrimSpace(raw)) {
|
|
case "1", "true", "yes", "on":
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|