mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 21:29:12 +00:00
Fix configuring search types & /config/types API when no plugin configured
- Test /config/types API when no plugin configured, only plugin configured and no content configured scenarios - Do not throw null reference exception while configuring search types when no plugin configured - Do not throw null reference exception on calling /config/types API when no plugin configured Resolves bug introduced by #173
This commit is contained in:
@@ -73,7 +73,9 @@ def configure_search_types(config: FullConfig):
|
||||
# Extract core search types
|
||||
core_search_types = {e.name: e.value for e in SearchType}
|
||||
# Extract configured plugin search types
|
||||
plugin_search_types = {plugin_type: plugin_type for plugin_type in config.content_type.plugins.keys()}
|
||||
plugin_search_types = {}
|
||||
if config.content_type.plugins:
|
||||
plugin_search_types = {plugin_type: plugin_type for plugin_type in config.content_type.plugins.keys()}
|
||||
|
||||
# Dynamically generate search type enum by merging core search types with configured plugin search types
|
||||
return Enum("SearchType", merge_dicts(core_search_types, plugin_search_types))
|
||||
|
||||
@@ -29,11 +29,12 @@ def get_default_config_data():
|
||||
@api.get("/config/types", response_model=List[str])
|
||||
def get_config_types():
|
||||
"""Get configured content types"""
|
||||
configured_content_types = state.config.content_type.dict(exclude_none=True)
|
||||
return [
|
||||
search_type.value
|
||||
for search_type in SearchType
|
||||
if any(search_type.value == ctype[0] and ctype[1] for ctype in state.config.content_type)
|
||||
or search_type.name in state.config.content_type.plugins.keys()
|
||||
if search_type.value in configured_content_types
|
||||
or ("plugins" in configured_content_types and search_type.name in configured_content_types["plugins"])
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user