From 469a1cb6a235aeb28d4d8cdbd8ad59adaab0e74b Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 19 Jul 2024 00:00:49 +0530 Subject: [PATCH] Move API endpoints under /api/configure/content/ to /api/content/ Pull out /api/configure/content API endpoints into /api/content to allow for more logical organization of API path hierarchy This should make the url more succinct and API request intent more understandable by using existing HTTP method semantics along with the path. The /configure URL path segment was either - redundant (e.g POST /configure/notion) or - incorrect (e.g GET /configure/files) Some example of naming improvements: - GET /configure/types -> GET /content/types - GET /configure/files -> GET /content/files - DELETE /configure/files -> DELETE /content/files This should also align, merge better the the content indexing API triggered via PUT, PATCH /content Refactor Flow 1. Rename /api/configure/types -> /api/content/types 2. Rename /api/configure -> /api 3. Move /api/content to api_content from under api_config --- src/interface/desktop/search.html | 2 +- src/interface/emacs/khoj.el | 2 +- src/khoj/interface/web/chat.html | 2 +- .../web/content_source_computer_input.html | 6 +- .../web/content_source_github_input.html | 2 +- .../web/content_source_notion_input.html | 2 +- src/khoj/interface/web/search.html | 2 +- src/khoj/interface/web/settings.html | 8 +- src/khoj/routers/api_config.py | 324 +----------------- src/khoj/routers/api_content.py | 315 ++++++++++++++++- tests/test_client.py | 6 +- 11 files changed, 331 insertions(+), 340 deletions(-) diff --git a/src/interface/desktop/search.html b/src/interface/desktop/search.html index 6a6cf694..792470a6 100644 --- a/src/interface/desktop/search.html +++ b/src/interface/desktop/search.html @@ -212,7 +212,7 @@ const headers = { 'Authorization': `Bearer ${khojToken}` }; // Populate type dropdown field with enabled content types only - fetch(`${hostURL}/api/configure/types`, { headers }) + fetch(`${hostURL}/api/content/types`, { headers }) .then(response => response.json()) .then(enabled_types => { // Show warning if no content types are enabled diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index 04c821e1..6f6747a8 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -697,7 +697,7 @@ Optionally apply CALLBACK with JSON parsed response and CBARGS." (defun khoj--get-enabled-content-types () "Get content types enabled for search from API." - (khoj--call-api "/api/configure/types" "GET" nil `(lambda (item) (mapcar #'intern item)))) + (khoj--call-api "/api/content/types" "GET" nil `(lambda (item) (mapcar #'intern item)))) (defun khoj--query-search-api-and-render-results (query content-type buffer-name &optional rerank is-find-similar) "Query Khoj Search API with QUERY, CONTENT-TYPE and RERANK as query params. diff --git a/src/khoj/interface/web/chat.html b/src/khoj/interface/web/chat.html index fbbe6a3a..149a0a66 100644 --- a/src/khoj/interface/web/chat.html +++ b/src/khoj/interface/web/chat.html @@ -1954,7 +1954,7 @@ To get started, just start typing below. You can also type / to see a list of co } var allFiles; function renderAllFiles() { - fetch('/api/configure/content/computer') + fetch('/api/content/computer') .then(response => response.json()) .then(data => { var indexedFiles = document.getElementsByClassName("indexed-files")[0]; diff --git a/src/khoj/interface/web/content_source_computer_input.html b/src/khoj/interface/web/content_source_computer_input.html index e0ffc4e9..fd66360d 100644 --- a/src/khoj/interface/web/content_source_computer_input.html +++ b/src/khoj/interface/web/content_source_computer_input.html @@ -32,7 +32,7 @@