Added download history

This commit is contained in:
enrilinux
2026-03-08 21:22:47 +01:00
parent 88b58090e4
commit acdb85272c
2 changed files with 61 additions and 2 deletions
+31 -2
View File
@@ -1,8 +1,9 @@
from fastapi import FastAPI, Request, Form
from fastapi.responses import HTMLResponse, FileResponse
from fastapi.responses import HTMLResponse, FileResponse, JSONResponse
from fastapi.templating import Jinja2Templates
import os
import uuid
import json
from datetime import datetime
from app.downloader import download_video
@@ -11,7 +12,14 @@ app = FastAPI()
templates = Jinja2Templates(directory="app/templates")
DOWNLOAD_DIR = "downloads"
HISTORY_FILE = "history.json"
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
os.makedirs("data", exist_ok=True)
if not os.path.exists(HISTORY_FILE):
with open(HISTORY_FILE, "w") as f:
json.dump([], f)
@app.get("/", response_class=HTMLResponse)
@@ -22,9 +30,30 @@ async def home(request: Request):
@app.post("/download")
async def download(url: str = Form(...), mode: str = Form(...)):
path = download_video(url, mode)
# salva nella cronologia
with open(HISTORY_FILE, "r") as f:
history = json.load(f)
history.append({
"url": url,
"mode": mode,
"path": path,
"time": datetime.now().strftime("%Y-%m-%d %H:%M")
})
with open(HISTORY_FILE, "w") as f:
json.dump(history, f, indent=2)
return {"path": path}
@app.get("/history")
async def history():
with open(HISTORY_FILE) as f:
return JSONResponse(json.load(f))
@app.get("/file")
async def file(path: str):
return FileResponse(path)