diff --git a/caricari/private.py b/caricari/private.py index cb3b1e8..84af7de 100644 --- a/caricari/private.py +++ b/caricari/private.py @@ -117,6 +117,17 @@ async def upload( raise -@app.post("/list") -def list(): - return "lista file" +@app.get("/list") +def list(request: Request): + files = [] + with session_pool() as conn: + query = conn.query(database.Original).order_by(-database.Original.id).limit(100) + for original in query: + files.append(original.__dict__) + data = {"files": files} + + if "application/json" in request.headers.get("accept", ""): + return data + return templates.TemplateResponse( + name="list.html", request=request, context=data + ) diff --git a/caricari/templates/list.html b/caricari/templates/list.html new file mode 100644 index 0000000..0af5af4 --- /dev/null +++ b/caricari/templates/list.html @@ -0,0 +1,26 @@ + +
+ + + +Name | +Size | ++ + + {% for orig in files %} + |
---|---|
{{orig.name}} | +{{orig.size}} | +