From 8917228dbbc941e50847924792f62babffaba191 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 16 Jan 2024 18:15:06 +0530 Subject: [PATCH] Remove unused, deprecated /api/config/data API endpoints - Use /api/health for server up check instead of api/config/default - Remove unused `khoj--post-new-config' method - Remove the now unused /config/data GET, POST API endpoints --- src/interface/emacs/khoj.el | 18 +------------ src/khoj/routers/api_config.py | 48 ---------------------------------- 2 files changed, 1 insertion(+), 65 deletions(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index 52cfba88..622fd209 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -348,7 +348,7 @@ Auto invokes setup steps on calling main entrypoint." t ;; else general check via ping to khoj-server-url (if (ignore-errors - (url-retrieve-synchronously (format "%s/api/config/data/default" khoj-server-url))) + (url-retrieve-synchronously (format "%s/api/health" khoj-server-url))) ;; Successful ping to non-emacs khoj server indicates it is started and ready. ;; So update ready state tracker variable (and implicitly return true for started) (setq khoj--server-ready? t) @@ -603,22 +603,6 @@ Use `BOUNDARY' to separate files. This is sent to Khoj server as a POST request. ;; -------------- ;; Query Khoj API ;; -------------- - -(defun khoj--post-new-config (config) - "Configure khoj server with provided CONFIG." - ;; POST provided config to khoj server - (let ((url-request-method "POST") - (url-request-extra-headers `(("Content-Type" . "application/json") - ("Authorization" . ,(format "Bearer %s" khoj-api-key)))) - (url-request-data (encode-coding-string (json-encode-alist config) 'utf-8)) - (config-url (format "%s/api/config/data" khoj-server-url))) - (with-current-buffer (url-retrieve-synchronously config-url) - (buffer-string))) - ;; Update index on khoj server after configuration update - (let ((khoj--server-ready? nil) - (url-request-extra-headers `(("Authorization" . ,(format "\"Bearer %s\"" khoj-api-key))))) - (url-retrieve (format "%s/api/update?client=emacs" khoj-server-url) #'identity))) - (defun khoj--get-enabled-content-types () "Get content types enabled for search from API." (let ((config-url (format "%s/api/config/types" khoj-server-url)) diff --git a/src/khoj/routers/api_config.py b/src/khoj/routers/api_config.py index fb53b638..6169eb4a 100644 --- a/src/khoj/routers/api_config.py +++ b/src/khoj/routers/api_config.py @@ -97,49 +97,6 @@ def _initialize_config(): state.config.search_type = SearchConfig.model_validate(constants.default_config["search-type"]) -@api_config.get("/data", response_model=FullConfig) -@requires(["authenticated"]) -def get_config_data(request: Request): - user = request.user.object - EntryAdapters.get_unique_file_types(user) - - return state.config - - -@api_config.post("/data") -@requires(["authenticated"]) -async def set_config_data( - request: Request, - updated_config: FullConfig, - client: Optional[str] = None, -): - user = request.user.object - await map_config_to_db(updated_config, user) - - configuration_update_metadata = {} - - enabled_content = await sync_to_async(EntryAdapters.get_unique_file_types)(user) - - if state.config.content_type is not None: - configuration_update_metadata["github"] = "github" in enabled_content - configuration_update_metadata["notion"] = "notion" in enabled_content - configuration_update_metadata["org"] = "org" in enabled_content - configuration_update_metadata["pdf"] = "pdf" in enabled_content - configuration_update_metadata["markdown"] = "markdown" in enabled_content - - if state.config.processor is not None: - configuration_update_metadata["conversation_processor"] = state.config.processor.conversation is not None - - update_telemetry_state( - request=request, - telemetry_type="api", - api="set_config", - client=client, - metadata=configuration_update_metadata, - ) - return state.config - - @api_config.post("/data/content-source/github", status_code=200) @requires(["authenticated"]) async def set_content_config_github_data( @@ -322,11 +279,6 @@ async def update_search_model( # Create Routes -@api_config.get("/data/default") -def get_default_config_data(): - return constants.empty_config - - @api_config.get("/index/size", response_model=Dict[str, int]) @requires(["authenticated"]) async def get_indexed_data_size(request: Request, common: CommonQueryParams):