mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(rpc): display rpc doc when no query string is provided
Closes #255 Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
60ae676075
commit
43b7fdb61d
3 changed files with 43 additions and 2 deletions
|
@ -12,7 +12,7 @@ from fastapi.responses import JSONResponse
|
|||
|
||||
from aurweb import defaults
|
||||
from aurweb.ratelimit import check_ratelimit
|
||||
from aurweb.rpc import RPC
|
||||
from aurweb.rpc import RPC, documentation
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
@ -74,6 +74,9 @@ async def rpc(request: Request,
|
|||
args: Optional[List[str]] = Query(default=[], alias="arg[]"),
|
||||
callback: Optional[str] = Query(default=None)):
|
||||
|
||||
if not request.url.query:
|
||||
return documentation()
|
||||
|
||||
# Create a handle to our RPC class.
|
||||
rpc = RPC(version=v, type=type)
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import os
|
||||
|
||||
from collections import defaultdict
|
||||
from typing import Any, Callable, Dict, List, NewType, Union
|
||||
|
||||
from fastapi.responses import HTMLResponse
|
||||
from sqlalchemy import and_, literal
|
||||
|
||||
import aurweb.config as config
|
||||
|
@ -23,6 +26,18 @@ DataGenerator = NewType("DataGenerator",
|
|||
Callable[[models.Package], Dict[str, Any]])
|
||||
|
||||
|
||||
def documentation():
|
||||
aurwebdir = config.get("options", "aurwebdir")
|
||||
rpc_doc = os.path.join(aurwebdir, "doc", "rpc.html")
|
||||
|
||||
if not os.path.exists(rpc_doc):
|
||||
raise OSError("doc/rpc.html could not be read")
|
||||
|
||||
with open(rpc_doc) as f:
|
||||
data = f.read()
|
||||
return HTMLResponse(data)
|
||||
|
||||
|
||||
class RPC:
|
||||
""" RPC API handler class.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue