-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
32 lines (24 loc) · 1012 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import deta
import fastapi
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
app = fastapi.FastAPI()
apps = deta.Base("apps")
pages = Jinja2Templates(directory="pages")
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/", response_class=fastapi.responses.HTMLResponse)
async def home(request: fastapi.Request):
res = apps.fetch()
items = res.items
while res.last:
res = apps.fetch(last=res.last)
items += res.items
return pages.TemplateResponse("index.html", {"request": request, "items": items})
@app.post("/add")
async def add_app(name: str, version: str, icon: str, url: str):
data = apps.put({"name": name, "version": version, "icon": icon, "url": url})
return {"key": data["key"]}
@app.patch("/update")
async def update_app(key: str, name: str, version: str, icon: str, url: str):
apps.update({"name": name, "version": version, "icon": icon, "url": url}, key)
return {"key": key}