Rename API path /api/config to /api/configure

- Update clients calling /api/config to call /api/configure instead
This commit is contained in:
Debanjum Singh Solanky 2024-07-16 15:15:40 +05:30
parent dd31936746
commit de15a7a3fc
12 changed files with 29 additions and 29 deletions

View file

@ -212,7 +212,7 @@
const headers = { 'Authorization': `Bearer ${khojToken}` }; const headers = { 'Authorization': `Bearer ${khojToken}` };
// Populate type dropdown field with enabled content types only // Populate type dropdown field with enabled content types only
fetch(`${hostURL}/api/config/types`, { headers }) fetch(`${hostURL}/api/configure/types`, { headers })
.then(response => response.json()) .then(response => response.json())
.then(enabled_types => { .then(enabled_types => {
// Show warning if no content types are enabled // Show warning if no content types are enabled

View file

@ -697,7 +697,7 @@ Optionally apply CALLBACK with JSON parsed response and CBARGS."
(defun khoj--get-enabled-content-types () (defun khoj--get-enabled-content-types ()
"Get content types enabled for search from API." "Get content types enabled for search from API."
(khoj--call-api "/api/config/types" "GET" nil `(lambda (item) (mapcar #'intern item)))) (khoj--call-api "/api/configure/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) (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. "Query Khoj Search API with QUERY, CONTENT-TYPE and RERANK as query params.

View file

@ -68,8 +68,8 @@ interface ModelPickerProps {
} }
export const ModelPicker: React.FC<any> = (props: ModelPickerProps) => { export const ModelPicker: React.FC<any> = (props: ModelPickerProps) => {
const { data: models } = useOptionsRequest('/api/config/chat/model/options'); const { data: models } = useOptionsRequest('/api/configure/chat/model/options');
const { data: selectedModel } = useSelectedModel('/api/config/chat/model'); const { data: selectedModel } = useSelectedModel('/api/configure/chat/model');
const [openLoginDialog, setOpenLoginDialog] = React.useState(false); const [openLoginDialog, setOpenLoginDialog] = React.useState(false);
let userData = useAuthenticatedData(); let userData = useAuthenticatedData();
@ -94,7 +94,7 @@ export const ModelPicker: React.FC<any> = (props: ModelPickerProps) => {
props.setModelUsed(model); props.setModelUsed(model);
} }
fetch('/api/config/chat/model' + '?id=' + String(model.id), { method: 'POST', body: JSON.stringify(model) }) fetch('/api/configure/chat/model' + '?id=' + String(model.id), { method: 'POST', body: JSON.stringify(model) })
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {
throw new Error('Failed to select model'); throw new Error('Failed to select model');

View file

@ -148,7 +148,7 @@ interface FilesMenuProps {
function FilesMenu(props: FilesMenuProps) { function FilesMenu(props: FilesMenuProps) {
// Use SWR to fetch files // Use SWR to fetch files
const { data: files, error } = useSWR<string[]>(props.conversationId ? '/api/config/content/computer' : null, fetcher); const { data: files, error } = useSWR<string[]>(props.conversationId ? '/api/configure/content/computer' : null, fetcher);
const { data: selectedFiles, error: selectedFilesError } = useSWR(props.conversationId ? `/api/chat/conversation/file-filters/${props.conversationId}` : null, fetcher); const { data: selectedFiles, error: selectedFilesError } = useSWR(props.conversationId ? `/api/chat/conversation/file-filters/${props.conversationId}` : null, fetcher);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [unfilteredFiles, setUnfilteredFiles] = useState<string[]>([]); const [unfilteredFiles, setUnfilteredFiles] = useState<string[]>([]);

View file

@ -316,7 +316,7 @@ def configure_routes(app):
app.include_router(api, prefix="/api") app.include_router(api, prefix="/api")
app.include_router(api_chat, prefix="/api/chat") app.include_router(api_chat, prefix="/api/chat")
app.include_router(api_agents, prefix="/api/agents") app.include_router(api_agents, prefix="/api/agents")
app.include_router(api_config, prefix="/api/config") app.include_router(api_config, prefix="/api/configure")
app.include_router(indexer, prefix="/api/v1/index") app.include_router(indexer, prefix="/api/v1/index")
app.include_router(notion_router, prefix="/api/notion") app.include_router(notion_router, prefix="/api/notion")
app.include_router(web_client) app.include_router(web_client)
@ -336,7 +336,7 @@ def configure_routes(app):
if is_twilio_enabled(): if is_twilio_enabled():
from khoj.routers.api_phone import api_phone from khoj.routers.api_phone import api_phone
app.include_router(api_phone, prefix="/api/config/phone") app.include_router(api_phone, prefix="/api/configure/phone")
logger.info("📞 Enabled Twilio") logger.info("📞 Enabled Twilio")

View file

@ -1954,7 +1954,7 @@ To get started, just start typing below. You can also type / to see a list of co
} }
var allFiles; var allFiles;
function renderAllFiles() { function renderAllFiles() {
fetch('/api/config/content/computer') fetch('/api/configure/content/computer')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
var indexedFiles = document.getElementsByClassName("indexed-files")[0]; var indexedFiles = document.getElementsByClassName("indexed-files")[0];

View file

@ -394,7 +394,7 @@
function saveProfileGivenName() { function saveProfileGivenName() {
const givenName = document.getElementById("profile_given_name").value; const givenName = document.getElementById("profile_given_name").value;
fetch('/api/config/user/name?name=' + givenName, { fetch('/api/configure/user/name?name=' + givenName, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -421,7 +421,7 @@
saveVoiceModelButton.disabled = true; saveVoiceModelButton.disabled = true;
saveVoiceModelButton.textContent = "Saving..."; saveVoiceModelButton.textContent = "Saving...";
fetch('/api/config/voice/model?id=' + voiceModel, { fetch('/api/configure/voice/model?id=' + voiceModel, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -455,7 +455,7 @@
saveModelButton.innerHTML = ""; saveModelButton.innerHTML = "";
saveModelButton.textContent = "Saving..."; saveModelButton.textContent = "Saving...";
fetch('/api/config/chat/model?id=' + chatModel, { fetch('/api/configure/chat/model?id=' + chatModel, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -494,7 +494,7 @@
saveSearchModelButton.disabled = true; saveSearchModelButton.disabled = true;
saveSearchModelButton.textContent = "Saving..."; saveSearchModelButton.textContent = "Saving...";
fetch('/api/config/search/model?id=' + searchModel, { fetch('/api/configure/search/model?id=' + searchModel, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -526,7 +526,7 @@
saveModelButton.disabled = true; saveModelButton.disabled = true;
saveModelButton.innerHTML = "Saving..."; saveModelButton.innerHTML = "Saving...";
fetch('/api/config/paint/model?id=' + paintModel, { fetch('/api/configure/paint/model?id=' + paintModel, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -553,7 +553,7 @@
}; };
function clearContentType(content_source) { function clearContentType(content_source) {
fetch('/api/config/content/' + content_source, { fetch('/api/configure/content/' + content_source, {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -676,7 +676,7 @@
content_sources = ["computer", "github", "notion"]; content_sources = ["computer", "github", "notion"];
content_sources.forEach(content_source => { content_sources.forEach(content_source => {
fetch(`/api/config/content/${content_source}`, { fetch(`/api/configure/content/${content_source}`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -807,7 +807,7 @@
function getIndexedDataSize() { function getIndexedDataSize() {
document.getElementById("indexed-data-size").textContent = "Calculating..."; document.getElementById("indexed-data-size").textContent = "Calculating...";
fetch('/api/config/content/size') fetch('/api/configure/content/size')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
document.getElementById("indexed-data-size").textContent = data.indexed_data_size_in_mb + " MB used"; document.getElementById("indexed-data-size").textContent = data.indexed_data_size_in_mb + " MB used";
@ -815,7 +815,7 @@
} }
function removeFile(path) { function removeFile(path) {
fetch('/api/config/content/file?filename=' + path, { fetch('/api/configure/content/file?filename=' + path, {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -890,7 +890,7 @@
}) })
phonenumberRemoveButton.addEventListener("click", () => { phonenumberRemoveButton.addEventListener("click", () => {
fetch('/api/config/phone', { fetch('/api/configure/phone', {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -917,7 +917,7 @@
}, 5000); }, 5000);
} else { } else {
const mobileNumber = iti.getNumber(); const mobileNumber = iti.getNumber();
fetch('/api/config/phone?phone_number=' + mobileNumber, { fetch('/api/configure/phone?phone_number=' + mobileNumber, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -970,7 +970,7 @@
return; return;
} }
fetch('/api/config/phone/verify?code=' + otp, { fetch('/api/configure/phone/verify?code=' + otp, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View file

@ -32,7 +32,7 @@
</style> </style>
<script> <script>
function removeFile(path) { function removeFile(path) {
fetch('/api/config/content/file?filename=' + path, { fetch('/api/configure/content/file?filename=' + path, {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -48,7 +48,7 @@
// Get all currently indexed files // Get all currently indexed files
function getAllComputerFilenames() { function getAllComputerFilenames() {
fetch('/api/config/content/computer') fetch('/api/configure/content/computer')
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
var indexedFiles = document.getElementsByClassName("indexed-files")[0]; var indexedFiles = document.getElementsByClassName("indexed-files")[0];
@ -122,7 +122,7 @@
deleteAllComputerFilesButton.textContent = "🗑️ Deleting..."; deleteAllComputerFilesButton.textContent = "🗑️ Deleting...";
deleteAllComputerFilesButton.disabled = true; deleteAllComputerFilesButton.disabled = true;
fetch('/api/config/content/computer', { fetch('/api/configure/content/computer', {
method: 'DELETE', method: 'DELETE',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View file

@ -165,7 +165,7 @@
// Save Github config on server // Save Github config on server
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1]; const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
fetch('/api/config/content/github', { fetch('/api/configure/content/github', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View file

@ -45,7 +45,7 @@
// Save Notion config on server // Save Notion config on server
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1]; const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
fetch('/api/config/content/notion', { fetch('/api/configure/content/notion', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View file

@ -209,7 +209,7 @@
function populate_type_dropdown() { function populate_type_dropdown() {
// Populate type dropdown field with enabled content types only // Populate type dropdown field with enabled content types only
fetch("/api/config/types") fetch("/api/configure/types")
.then(response => response.json()) .then(response => response.json())
.then(enabled_types => { .then(enabled_types => {
// Show warning if no content types are enabled, or just one ("all") // Show warning if no content types are enabled, or just one ("all")

View file

@ -269,7 +269,7 @@ def test_get_api_config_types(client, sample_org_data, default_user: KhojUser):
text_search.setup(OrgToEntries, sample_org_data, regenerate=False, user=default_user) text_search.setup(OrgToEntries, sample_org_data, regenerate=False, user=default_user)
# Act # Act
response = client.get(f"/api/config/types", headers=headers) response = client.get(f"/api/configure/types", headers=headers)
# Assert # Assert
assert response.status_code == 200 assert response.status_code == 200
@ -289,7 +289,7 @@ def test_get_configured_types_with_no_content_config(fastapi_app: FastAPI):
client = TestClient(fastapi_app) client = TestClient(fastapi_app)
# Act # Act
response = client.get(f"/api/config/types") response = client.get(f"/api/configure/types")
# Assert # Assert
assert response.status_code == 200 assert response.status_code == 200