diff --git a/src/router/routes/route_search_images.go b/src/router/routes/route_search_images.go index 7aeb4715..b97e5744 100644 --- a/src/router/routes/route_search_images.go +++ b/src/router/routes/route_search_images.go @@ -121,7 +121,14 @@ func routeSearchImages(w http.ResponseWriter, r *http.Request, ver string, disab Value: fmt.Sprintf("%v", err), }) } - catConf.DisableEngines(disabledEngines) + + if catConf.ContainsDisabledEngines(disabledEngines) { + // User error. + return writeResponseJSON(w, http.StatusBadRequest, ErrorResponse{ + Message: "category contains disabled engines", + Value: "disabled engines", + }) + } // All of these have default values set and validated. opts := options.Options{ diff --git a/src/router/routes/route_search_suggestions.go b/src/router/routes/route_search_suggestions.go index 9dd43ba5..4f630568 100644 --- a/src/router/routes/route_search_suggestions.go +++ b/src/router/routes/route_search_suggestions.go @@ -78,7 +78,14 @@ func routeSearchSuggestions(w http.ResponseWriter, r *http.Request, ver string, Value: fmt.Sprintf("%v", err), }) } - catConf.DisableEngines(disabledEngines) + + if catConf.ContainsDisabledEngines(disabledEngines) { + // User error. + return writeResponseJSON(w, http.StatusBadRequest, ErrorResponse{ + Message: "category contains disabled engines", + Value: "disabled engines", + }) + } // All of these have default values set and validated. opts := options.Options{ diff --git a/src/router/routes/route_search_web.go b/src/router/routes/route_search_web.go index 3db29a7d..8d3c99b8 100644 --- a/src/router/routes/route_search_web.go +++ b/src/router/routes/route_search_web.go @@ -121,7 +121,14 @@ func routeSearchWeb(w http.ResponseWriter, r *http.Request, ver string, disabled Value: fmt.Sprintf("%v", err), }) } - catConf.DisableEngines(disabledEngines) + + if catConf.ContainsDisabledEngines(disabledEngines) { + // User error. + return writeResponseJSON(w, http.StatusBadRequest, ErrorResponse{ + Message: "category contains disabled engines", + Value: "disabled engines", + }) + } // All of these have default values set and validated. opts := options.Options{ diff --git a/src/search/category/disable.go b/src/search/category/disable.go deleted file mode 100644 index 9b8d58a2..00000000 --- a/src/search/category/disable.go +++ /dev/null @@ -1,27 +0,0 @@ -package category - -import ( - "slices" - - "github.com/hearchco/agent/src/search/engines" -) - -// Remove the specified engines from the Category. -// Passed as pointer to modify the original. -func (c *Category) DisableEngines(disabledEngines []engines.Name) { - c.Engines = slices.DeleteFunc(c.Engines, func(e engines.Name) bool { - return slices.Contains(disabledEngines, e) - }) - c.RequiredEngines = slices.DeleteFunc(c.RequiredEngines, func(e engines.Name) bool { - return slices.Contains(disabledEngines, e) - }) - c.RequiredByOriginEngines = slices.DeleteFunc(c.RequiredByOriginEngines, func(e engines.Name) bool { - return slices.Contains(disabledEngines, e) - }) - c.PreferredEngines = slices.DeleteFunc(c.PreferredEngines, func(e engines.Name) bool { - return slices.Contains(disabledEngines, e) - }) - c.PreferredByOriginEngines = slices.DeleteFunc(c.PreferredByOriginEngines, func(e engines.Name) bool { - return slices.Contains(disabledEngines, e) - }) -} diff --git a/src/search/category/disabled.go b/src/search/category/disabled.go new file mode 100644 index 00000000..da8733de --- /dev/null +++ b/src/search/category/disabled.go @@ -0,0 +1,19 @@ +package category + +import ( + "slices" + + "github.com/hearchco/agent/src/search/engines" +) + +// Returns true if the category contains any disabled engines. +// Otherwise, returns false. +func (c Category) ContainsDisabledEngines(disabledEngines []engines.Name) bool { + for _, eng := range disabledEngines { + if slices.Contains(c.Engines, eng) { + return true + } + } + + return false +}