diff --git a/src/khoj/interface/web/config.html b/src/khoj/interface/web/config.html index c65615e1..0fc7d8e9 100644 --- a/src/khoj/interface/web/config.html +++ b/src/khoj/interface/web/config.html @@ -541,16 +541,7 @@ }) .then(response => response.json()) .then(tokenObj => { - apiKeyList.innerHTML += ` - - ${tokenObj.name} - ${tokenObj.token} - - Copy API Key - Delete API Key - - - `; + apiKeyList.innerHTML += generateTokenRow(tokenObj); }); } @@ -561,7 +552,7 @@ const copyApiKeyButton = document.getElementById(`api-key-${token}`); original_html = copyApiKeyButton.innerHTML setTimeout(function() { - copyApiKeyButton.innerHTML = "✅ Copied to your clipboard!"; + copyApiKeyButton.innerHTML = "✅ Copied!"; setTimeout(function() { copyApiKeyButton.innerHTML = original_html; }, 1000); @@ -581,23 +572,30 @@ }); } + function generateTokenRow(tokenObj) { + let token = tokenObj.token; + let tokenName = tokenObj.name; + let truncatedToken = token.slice(0, 4) + "..." + token.slice(-4); + let tokenId = `${tokenName}-${truncatedToken}`; + return ` + + ${tokenName} + ${truncatedToken} + + Copy API Key + Delete API Key + + + `; + + } + function listApiKeys() { const apiKeyList = document.getElementById("api-key-list"); fetch('/auth/token') .then(response => response.json()) .then(tokens => { - apiKeyList.innerHTML = tokens.map(tokenObj => - ` - - ${tokenObj.name} - ${tokenObj.token} - - Copy API Key - Delete API Key - - - `) - .join(""); + apiKeyList.innerHTML = tokens.map(generateTokenRow).join(""); }); }