Add Git source management to WebUI
This commit is contained in:
@@ -248,6 +248,43 @@ async def sources_page(request: Request):
|
||||
return templates.TemplateResponse("sources.html", {"request": request, "sources": sources})
|
||||
|
||||
|
||||
def parse_path_list(value: str) -> List[str]:
|
||||
paths = []
|
||||
for line in value.replace(",", "\n").splitlines():
|
||||
item = line.strip()
|
||||
if item:
|
||||
paths.append(item)
|
||||
return paths
|
||||
|
||||
|
||||
@app.post("/sources/add")
|
||||
async def add_source(
|
||||
library_id: str = Form(...),
|
||||
repo_url: str = Form(...),
|
||||
name: str = Form(""),
|
||||
description: str = Form(""),
|
||||
branch: str = Form("main"),
|
||||
include_paths: str = Form("docs"),
|
||||
exclude_paths: str = Form("node_modules\n.git"),
|
||||
):
|
||||
client = get_client()
|
||||
payload = {
|
||||
"library_id": library_id,
|
||||
"repo_url": repo_url,
|
||||
"name": name or None,
|
||||
"description": description or None,
|
||||
"branch": branch or "main",
|
||||
"include_paths": parse_path_list(include_paths),
|
||||
"exclude_paths": parse_path_list(exclude_paths),
|
||||
}
|
||||
try:
|
||||
result = await client.post("/api/v1/sources", json=payload)
|
||||
body = f"<h1>Git Source Saved</h1><pre>{html.escape(str(result))}</pre><a href='/sources'>Back</a>"
|
||||
except Exception as e:
|
||||
body = f"<h1>Save Failed</h1><pre>{html.escape(str(e))}</pre><a href='/sources'>Back</a>"
|
||||
return page("Git Source Saved", body)
|
||||
|
||||
|
||||
@app.post("/sources/sync")
|
||||
async def sync_sources(override: bool = Form(False)):
|
||||
client = get_client()
|
||||
|
||||
Reference in New Issue
Block a user