mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
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
95 lines
3.6 KiB
HTML
95 lines
3.6 KiB
HTML
{% extends "base_config.html" %}
|
|
{% block content %}
|
|
<div class="page">
|
|
<div class="section">
|
|
<h2 class="section-title">
|
|
<img class="card-icon" src="/static/assets/icons/notion.svg?v={{ khoj_version }}" alt="Notion">
|
|
<span class="card-title-text">Notion</span>
|
|
<div class="instructions">
|
|
<a href="https://docs.khoj.dev/data-sources/notion_integration">ⓘ Help</a>
|
|
</div>
|
|
<table>
|
|
<tr>
|
|
<td>
|
|
<label for="token">Token</label>
|
|
</td>
|
|
<td>
|
|
<input type="text" id="token" name="pat" value="{{ current_config['token'] }}">
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<div class="section">
|
|
<div id="success" style="display: none;"></div>
|
|
<button id="submit" type="submit">Sync to Update</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
const submit = document.getElementById("submit");
|
|
|
|
submit.addEventListener("click", function(event) {
|
|
event.preventDefault();
|
|
|
|
const token = document.getElementById("token").value;
|
|
|
|
if (token == "") {
|
|
document.getElementById("success").textContent = "❌ Please enter a Notion Token.";
|
|
document.getElementById("success").style.display = "block";
|
|
return;
|
|
}
|
|
|
|
const submitButton = document.getElementById("submit");
|
|
submitButton.disabled = true;
|
|
submitButton.textContent = "Syncing...";
|
|
|
|
// Save Notion config on server
|
|
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('csrftoken'))?.split('=')[1];
|
|
fetch('/api/content/notion', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFToken': csrfToken,
|
|
},
|
|
body: JSON.stringify({
|
|
"token": token,
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => { data["status"] === "ok" ? data : Promise.reject(data) })
|
|
.catch(error => {
|
|
document.getElementById("success").textContent = "⚠️ Failed to save Notion settings.";
|
|
document.getElementById("success").style.display = "block";
|
|
submitButton.textContent = "⚠️ Failed to save settings";
|
|
setTimeout(function() {
|
|
submitButton.textContent = "Save";
|
|
submitButton.disabled = false;
|
|
}, 2000);
|
|
return;
|
|
});
|
|
|
|
// Index Notion content on server
|
|
fetch('/api/update?t=notion')
|
|
.then(response => response.json())
|
|
.then(data => { data["status"] == "ok" ? data : Promise.reject(data) })
|
|
.then(data => {
|
|
document.getElementById("success").style.display = "none";
|
|
submitButton.textContent = "✅ Successfully updated";
|
|
setTimeout(function() {
|
|
submitButton.textContent = "Save";
|
|
submitButton.disabled = false;
|
|
}, 2000);
|
|
})
|
|
.catch(error => {
|
|
document.getElementById("success").textContent = "⚠️ Failed to save Notion content.";
|
|
document.getElementById("success").style.display = "block";
|
|
submitButton.textContent = "⚠️ Failed to save content";
|
|
setTimeout(function() {
|
|
submitButton.textContent = "Save";
|
|
submitButton.disabled = false;
|
|
}, 2000);
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %}
|