mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-04 21:29:12 +00:00
Short-circuit API rate limiter for unauthenticated users (#607)
### Major - Short-circuit API rate limiter for unauthenticated user Calls by unauthenticated users were failing at API rate limiter as it failed to access user info object. This is a bug. API rate limiter should short-circuit for unauthenicated users so a proper Forbidden response can be returned by API Add regression test to verify that unauthenticated users get 403 response when calling the /chat API endpoint ### Minor - Remove trailing slash to normalize khoj url in obsidian plugin settings - Move used /api/config API controllers into separate module - Delete unused /api/beta API endpoint - Fix error message rendering in khoj.el, khoj obsidian chat - Handle deprecation warnings for subscribe renew date, langchain, pydantic & logger.warn
This commit is contained in:
@@ -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)
|
||||
@@ -432,7 +432,7 @@ Auto invokes setup steps on calling main entrypoint."
|
||||
(khoj--delete-open-network-connections-to-server)
|
||||
(with-current-buffer (current-buffer)
|
||||
(search-forward "\n\n" nil t)
|
||||
(message "khoj.el: Failed to %supdate %s content index. Status: %s%s"
|
||||
(message "khoj.el: Failed to %supdate %scontent index. Status: %s%s"
|
||||
(if force "force " "")
|
||||
(if content-type (format "%s " content-type) "all")
|
||||
(string-trim (format "%s %s" (nth 1 (nth 1 status)) (nth 2 (nth 1 status))))
|
||||
@@ -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))
|
||||
|
||||
@@ -245,7 +245,7 @@ export class KhojChatModal extends Modal {
|
||||
if (responseJson.detail) {
|
||||
// If the server returns error details in response, render a setup hint.
|
||||
let setupMsg = "Hi 👋🏾, to start chatting add available chat models options via [the Django Admin panel](/server/admin) on the Server";
|
||||
this.renderMessage(chatBodyEl, setupMsg, "khoj", undefined, true);
|
||||
this.renderMessage(chatBodyEl, setupMsg, "khoj", undefined);
|
||||
|
||||
return false;
|
||||
} else if (responseJson.response) {
|
||||
|
||||
@@ -42,7 +42,7 @@ export class KhojSettingTab extends PluginSettingTab {
|
||||
.addText(text => text
|
||||
.setValue(`${this.plugin.settings.khojUrl}`)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.khojUrl = value.trim();
|
||||
this.plugin.settings.khojUrl = value.trim().replace(/\/$/, '');
|
||||
await this.plugin.saveSettings();
|
||||
containerEl.firstElementChild?.setText(this.getBackendStatusMessage());
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user