Add GET /api/diff/:hash endpoint; WikiLog collapsible diffs

This commit is contained in:
brutsalvadi
2026-05-11 14:57:13 +02:00
parent 4bd74c6667
commit 4a6c0401be
2 changed files with 18 additions and 1 deletions
+17
View File
@@ -43,6 +43,7 @@ _SESSION_COOKIE = "bincio_session"
_SAFE_SLUG = re.compile(r"^[a-zA-Z0-9_][a-zA-Z0-9_\-/]*$")
_SAFE_HANDLE = re.compile(r"^[a-z][a-z0-9_-]{1,19}$")
_SAFE_HASH = re.compile(r"^[0-9a-f]{4,40}$")
_ALLOWED_IMAGE_TYPES = {"image/jpeg", "image/png", "image/webp", "image/gif"}
_MAX_IMAGE_BYTES = 10 * 1024 * 1024 # 10 MB
@@ -286,6 +287,22 @@ async def get_wiki_log(user: User = Depends(require_auth)) -> JSONResponse:
return JSONResponse({"log": entries})
@app.get("/api/diff/{commit_hash}")
async def get_diff(commit_hash: str, user: User = Depends(require_auth)) -> JSONResponse:
if not _SAFE_HASH.match(commit_hash):
raise HTTPException(status_code=400, detail="invalid hash")
env = _git_env()
proc = await asyncio.create_subprocess_exec(
"git", "show", commit_hash, "-p", "--no-color", "--format=", "--", "pages/", "blog/",
cwd=str(_ROOT), env=env,
stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
)
stdout, _ = await proc.communicate()
if proc.returncode != 0:
raise HTTPException(status_code=404, detail="commit not found")
return JSONResponse({"diff": stdout.decode(errors="replace")})
@app.get("/api/me")
async def me(user: User = Depends(require_auth)) -> JSONResponse:
return JSONResponse({
+1 -1
Submodule site updated: 5341988e8d...b78af43122