mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Move web interface to configure application into src/interface/web directory
- Improve code layout by ensuring all web interface specific code under the src/interface/web directory - Rename config API to more specifi /config instead of /ui - Rename config data GET, POST api to /config/data instead of /config
This commit is contained in:
@@ -10,7 +10,7 @@ var emptyValueDefault = "🖊️";
|
|||||||
/**
|
/**
|
||||||
* Fetch the existing config file.
|
* Fetch the existing config file.
|
||||||
*/
|
*/
|
||||||
fetch("/config")
|
fetch("/config/data")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
rawConfig = data;
|
rawConfig = data;
|
||||||
@@ -26,15 +26,16 @@ fetch("/config")
|
|||||||
configForm.addEventListener("submit", (event) => {
|
configForm.addEventListener("submit", (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log(rawConfig);
|
console.log(rawConfig);
|
||||||
const response = fetch("/config", {
|
fetch("/config/data", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(rawConfig)
|
body: JSON.stringify(rawConfig)
|
||||||
}).then(response => response.json())
|
})
|
||||||
.then((data) => console.log(data));
|
.then(response => response.json())
|
||||||
|
.then(data => console.log(data));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
<title>Set directories for your config file.</title>
|
<title>Set directories for your config file.</title>
|
||||||
<link rel="stylesheet" href="views/style.css">
|
<link rel="stylesheet" href="static/assets/config-style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form id="config-form">
|
<form id="config-form">
|
||||||
</form>
|
</form>
|
||||||
<button id="config-regenerate">regenerate</button>
|
<button id="config-regenerate">regenerate</button>
|
||||||
</body>
|
</body>
|
||||||
<script src="views/scripts/config.js"></script>
|
<script src="static/assets/config.js"></script>
|
||||||
</html>
|
</html>
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
function populate_type_dropdown() {
|
function populate_type_dropdown() {
|
||||||
// Populate type dropdown field with enabled search types only
|
// Populate type dropdown field with enabled search types only
|
||||||
var possible_search_types = ["org", "markdown", "ledger", "music", "image"];
|
var possible_search_types = ["org", "markdown", "ledger", "music", "image"];
|
||||||
fetch("/config")
|
fetch("/config/data")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
document.getElementById("type").innerHTML =
|
document.getElementById("type").innerHTML =
|
||||||
|
|||||||
@@ -34,22 +34,21 @@ app = FastAPI()
|
|||||||
web_directory = f'src/interface/web/'
|
web_directory = f'src/interface/web/'
|
||||||
|
|
||||||
app.mount("/static", StaticFiles(directory=web_directory), name="static")
|
app.mount("/static", StaticFiles(directory=web_directory), name="static")
|
||||||
app.mount("/views", StaticFiles(directory="views"), name="views")
|
templates = Jinja2Templates(directory=web_directory)
|
||||||
templates = Jinja2Templates(directory="views/")
|
|
||||||
|
|
||||||
@app.get("/", response_class=FileResponse)
|
@app.get("/", response_class=FileResponse)
|
||||||
def index():
|
def index():
|
||||||
return FileResponse(web_directory + "index.html")
|
return FileResponse(web_directory + "index.html")
|
||||||
|
|
||||||
@app.get('/ui', response_class=HTMLResponse)
|
@app.get('/config', response_class=HTMLResponse)
|
||||||
def ui(request: Request):
|
def ui(request: Request):
|
||||||
return templates.TemplateResponse("config.html", context={'request': request})
|
return templates.TemplateResponse("config.html", context={'request': request})
|
||||||
|
|
||||||
@app.get('/config', response_model=FullConfig)
|
@app.get('/config/data', response_model=FullConfig)
|
||||||
def config_data():
|
def config_data():
|
||||||
return config
|
return config
|
||||||
|
|
||||||
@app.post('/config')
|
@app.post('/config/data')
|
||||||
async def config_data(updated_config: FullConfig):
|
async def config_data(updated_config: FullConfig):
|
||||||
global config
|
global config
|
||||||
config = updated_config
|
config = updated_config
|
||||||
|
|||||||
Reference in New Issue
Block a user