This commit is contained in:
TylerCG 2025-04-26 09:49:15 -04:00
parent ec782c4ce1
commit ecfeb5927d
3 changed files with 43 additions and 52 deletions

View File

@ -1,3 +1,3 @@
__pycache__ __pycache__
.DS_Store .DS_Store
data/* data/

View File

@ -1,7 +1,7 @@
from fastapi import FastAPI, Request, Form from fastapi import FastAPI, Request, Form
from fastapi.responses import HTMLResponse, JSONResponse from fastapi.responses import HTMLResponse, JSONResponse
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
# from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
# from fastapi.concurrency import run_in_threadpool # from fastapi.concurrency import run_in_threadpool
from pathlib import Path from pathlib import Path
from functools import partial from functools import partial
@ -11,6 +11,8 @@ from typing import Optional
app = FastAPI() app = FastAPI()
# app.mount("/static", StaticFiles(directory="/app/app/static"), name="static") # app.mount("/static", StaticFiles(directory="/app/app/static"), name="static")
app.mount("/data", StaticFiles(directory="/data"), name="data")
templates = Jinja2Templates(directory="templates") templates = Jinja2Templates(directory="templates")
loop = asyncio.get_running_loop() loop = asyncio.get_running_loop()
@ -69,12 +71,24 @@ async def ydl(url: str, location: str):
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)}) return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
# html # html
@app.get("/", include_in_schema=False, response_class=HTMLResponse) # @app.get("/", include_in_schema=False, response_class=HTMLResponse)
# async def index(request: Request):
# apps = [
# {"name": "Notes", "url": "/notes"},
# {"name": "Todo List", "url": "/todos"},
# {"name": "Weather", "url": "/weather"},
# # Add more apps here
# ]
# return templates.TemplateResponse("index.html", {"request": request, "apps": apps, "title": "Welcome to My App Hub"})
# JSON cache
cached_data = None
@app.get("/", response_class=HTMLResponse)
async def index(request: Request): async def index(request: Request):
apps = [ global cached_data
{"name": "Notes", "url": "/notes"}, if cached_data is None:
{"name": "Todo List", "url": "/todos"}, with open('/data/dropout.json') as f:
{"name": "Weather", "url": "/weather"}, cached_data = json.load(f)
# Add more apps here return templates.TemplateResponse("index.html", {"request": request, "data": cached_data})
]
return templates.TemplateResponse("index.html", {"request": request, "apps": apps, "title": "Welcome to My App Hub"})

View File

@ -2,62 +2,39 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{{ title or "My Apps" }}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Show Posters</title>
<style> <style>
body { body {
margin: 0;
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
display: flex; display: flex;
flex-wrap: wrap;
justify-content: center; justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f4f4f4;
} }
.tile {
.container { width: 400px;
margin: 10px;
text-align: center; text-align: center;
} border: 1px solid #ddd;
h1 {
margin-bottom: 30px;
color: #333;
}
.apps-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 20px;
max-width: 600px;
margin: 0 auto;
}
.app-card {
background: white;
border-radius: 8px; border-radius: 8px;
padding: 20px; overflow: hidden;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
transition: transform 0.2s ease;
cursor: pointer;
} }
.tile img {
.app-card:hover { width: 100%;
transform: scale(1.05); height: auto;
}
.tile .title {
padding: 10px;
background-color: #f4f4f4;
} }
</style> </style>
</head> </head>
<body> <body>
<div class="container"> {% for item in data %}
<h1>{{ title or "My Apps" }}</h1> <div class="tile">
<div class="apps-grid"> <img src="{{ item['POSTER'] }}" alt="{{ item['SHOW'] }}">
{% for app in apps %} <div class="title">{{ item['SHOW'] }}</div>
<div class="app-card">
<a href="{{ app.url }}" style="text-decoration: none; color: inherit;">
{{ app.name }}
</a>
</div>
{% endfor %}
</div> </div>
</div> {% endfor %}
</body> </body>
</html> </html>