Skip to content

Commit

Permalink
api/main: Add dashboard
Browse files Browse the repository at this point in the history
Add mini-dashboard that allows to see quickly results of builds.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Apr 5, 2024
1 parent ce0b8e5 commit 50fca4b
Show file tree
Hide file tree
Showing 6 changed files with 1,045 additions and 2 deletions.
33 changes: 32 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Request,
Form
)
from fastapi.responses import JSONResponse, PlainTextResponse
from fastapi.responses import JSONResponse, PlainTextResponse, FileResponse
from fastapi.security import OAuth2PasswordRequestForm
from fastapi_pagination import add_pagination
from fastapi_versioning import VersionedFastAPI
Expand Down Expand Up @@ -751,6 +751,37 @@ async def viewer():
return PlainTextResponse(file.read(), headers=hdr)


@app.get('/dashboard')
async def dashboard():
"""Serve simple HTML page to view the API dashboard.html
Set various no-cache tag we might update it often"""

root_dir = os.path.dirname(os.path.abspath(__file__))
dashboard_path = os.path.join(root_dir, 'templates', 'dashboard.html')
with open(dashboard_path, 'r', encoding='utf-8') as file:
# set header to text/html and no-cache stuff
hdr = {
'Content-Type': 'text/html',
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0'
}
return PlainTextResponse(file.read(), headers=hdr)


@app.get('/icons/{icon_name}')
async def icons(icon_name: str):
"""Serve icons from /static/icons"""
root_dir = os.path.dirname(os.path.abspath(__file__))
if not re.match(r'^[A-Za-z0-9_.-]+\.png$', icon_name):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid icon name"
)
icon_path = os.path.join(root_dir, 'templates', icon_name)
return FileResponse(icon_path)


versioned_app = VersionedFastAPI(
app,
version_format='{major}',
Expand Down
Binary file added api/templates/bad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 50fca4b

Please sign in to comment.