Add frontend app
This commit is contained in:
parent
f78f495dbc
commit
7c0d33282a
28
frontend.html
Normal file
28
frontend.html
Normal file
@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Random Image</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
html, body { height: 100%; overflow: hidden; background: #1a1a1a; }
|
||||
img { display: block; max-width: 100%; max-height: 100%; margin: auto; cursor: pointer; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<img id="random-img" src="/random" alt="Random image">
|
||||
<script>
|
||||
function loadNewImage() {
|
||||
document.getElementById('random-img').src = '/random?' + Date.now();
|
||||
}
|
||||
document.getElementById('random-img').addEventListener('click', loadNewImage);
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.code === 'Space') {
|
||||
e.preventDefault();
|
||||
loadNewImage();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
6
main.py
6
main.py
@ -9,7 +9,7 @@ from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import RedirectResponse, StreamingResponse
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
|
||||
app = FastAPI()
|
||||
indexer = None
|
||||
@ -104,8 +104,8 @@ def initialize_server(args: argparse.Namespace):
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""Redirect to /random"""
|
||||
return RedirectResponse(url="/random")
|
||||
"""Serve the Frontend app"""
|
||||
return FileResponse("frontend.html")
|
||||
|
||||
|
||||
@app.get("/random")
|
||||
|
||||
@ -24,3 +24,8 @@ ignore = []
|
||||
|
||||
[tool.ruff.format]
|
||||
quote-style = "double"
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"ruff>=0.15.5",
|
||||
]
|
||||
|
||||
8
uv.lock
generated
8
uv.lock
generated
@ -82,6 +82,11 @@ dev = [
|
||||
{ name = "ruff" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
dev = [
|
||||
{ name = "ruff" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "fastapi", specifier = ">=0.128.0" },
|
||||
@ -90,6 +95,9 @@ requires-dist = [
|
||||
]
|
||||
provides-extras = ["dev"]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [{ name = "ruff", specifier = ">=0.15.5" }]
|
||||
|
||||
[[package]]
|
||||
name = "h11"
|
||||
version = "0.16.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user