Compare commits
11
Commits
0b134a95ff
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d665203c9c | ||
|
|
096ce23e3a | ||
|
|
2b7d7d228d | ||
|
|
d7a5238fbf | ||
|
|
112f806942 | ||
|
|
2ca9dacb8b | ||
|
|
a0b38ad75b | ||
|
|
c04c480ab7 | ||
|
|
91c25a177f | ||
|
|
14585880df | ||
|
|
492c60d3df |
@@ -0,0 +1,60 @@
|
|||||||
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Docker (for Debian bullseye)
|
||||||
|
run: |
|
||||||
|
# Aggiorna i pacchetti
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y ca-certificates curl gnupg lsb-release
|
||||||
|
|
||||||
|
# Aggiungi la chiave GPG di Docker
|
||||||
|
mkdir -p /etc/apt/keyrings
|
||||||
|
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
|
||||||
|
# Aggiungi il repository DOCKER (usa bullseye, non bookworm!)
|
||||||
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bullseye stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
|
||||||
|
# Installa Docker
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||||
|
|
||||||
|
# Verifica
|
||||||
|
docker --version
|
||||||
|
docker compose version
|
||||||
|
|
||||||
|
- name: Log in to Gitea Container Registry
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.AUTHTOKEN }}" | docker login \
|
||||||
|
-u "${{ secrets.REGISTRY_USER }}" \
|
||||||
|
--password-stdin \
|
||||||
|
gitea.enrilinux.ovh
|
||||||
|
|
||||||
|
- name: Extract metadata
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
echo "REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F'/' '{print $2}')" >> $GITHUB_OUTPUT
|
||||||
|
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
run: |
|
||||||
|
REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F'/' '{print $2}')
|
||||||
|
SHORT_SHA=$(git rev-parse --short HEAD)
|
||||||
|
|
||||||
|
docker build -t gitea.enrilinux.ovh/${{ github.repository_owner }}/${REPO_NAME}:latest .
|
||||||
|
docker tag gitea.enrilinux.ovh/${{ github.repository_owner }}/${REPO_NAME}:latest \
|
||||||
|
gitea.enrilinux.ovh/${{ github.repository_owner }}/${REPO_NAME}:${SHORT_SHA}
|
||||||
|
|
||||||
|
docker push gitea.enrilinux.ovh/${{ github.repository_owner }}/${REPO_NAME}:latest
|
||||||
|
docker push gitea.enrilinux.ovh/${{ github.repository_owner }}/${REPO_NAME}:${SHORT_SHA}
|
||||||
+4
-1
@@ -2,7 +2,7 @@ FROM python:3.11
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y ffmpeg
|
RUN apt-get update && apt-get install -y ffmpeg curl
|
||||||
|
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
|
|
||||||
@@ -11,6 +11,9 @@ RUN pip install -r requirements.txt
|
|||||||
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
||||||
&& apt-get install -y nodejs
|
&& apt-get install -y nodejs
|
||||||
|
|
||||||
|
RUN curl -fsSL https://deno.land/install.sh | sh \
|
||||||
|
&& mv /root/.deno/bin/deno /usr/local/bin/deno
|
||||||
|
|
||||||
COPY app ./app
|
COPY app ./app
|
||||||
RUN mkdir downloads
|
RUN mkdir downloads
|
||||||
|
|
||||||
|
|||||||
+32
-6
@@ -1,6 +1,5 @@
|
|||||||
from fastapi import FastAPI, Request, Form
|
from fastapi import FastAPI, Request, Form
|
||||||
from fastapi.responses import HTMLResponse, FileResponse, JSONResponse
|
from fastapi.responses import HTMLResponse, FileResponse, JSONResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -9,10 +8,9 @@ from app.downloader import download_video
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
templates = Jinja2Templates(directory="app/templates")
|
|
||||||
|
|
||||||
DOWNLOAD_DIR = "downloads"
|
DOWNLOAD_DIR = "downloads"
|
||||||
HISTORY_FILE = "history.json"
|
HISTORY_FILE = "history.json"
|
||||||
|
LOG_FILE = "data/app.log"
|
||||||
|
|
||||||
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
||||||
os.makedirs("data", exist_ok=True)
|
os.makedirs("data", exist_ok=True)
|
||||||
@@ -21,6 +19,10 @@ if not os.path.exists(HISTORY_FILE):
|
|||||||
with open(HISTORY_FILE, "w") as f:
|
with open(HISTORY_FILE, "w") as f:
|
||||||
json.dump([], f)
|
json.dump([], f)
|
||||||
|
|
||||||
|
if not os.path.exists(LOG_FILE):
|
||||||
|
with open(LOG_FILE, "w") as f:
|
||||||
|
f.write("")
|
||||||
|
|
||||||
def write_log(message):
|
def write_log(message):
|
||||||
with open(LOG_FILE, "a") as f:
|
with open(LOG_FILE, "a") as f:
|
||||||
f.write(f"{datetime.now().strftime('%H:%M:%S')} - {message}\n")
|
f.write(f"{datetime.now().strftime('%H:%M:%S')} - {message}\n")
|
||||||
@@ -28,14 +30,26 @@ def write_log(message):
|
|||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
async def home(request: Request):
|
async def home(request: Request):
|
||||||
return templates.TemplateResponse("index.html", {"request": request})
|
# Legge il file HTML direttamente
|
||||||
|
try:
|
||||||
|
with open("/app/app/templates/index.html", "r") as f:
|
||||||
|
html_content = f.read()
|
||||||
|
return HTMLResponse(content=html_content)
|
||||||
|
except Exception as e:
|
||||||
|
return HTMLResponse(content=f"<h1>Errore</h1><p>{str(e)}</p>", status_code=500)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/test")
|
||||||
|
async def test():
|
||||||
|
return {"status": "ok", "message": "Server funzionante"}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/download")
|
@app.post("/download")
|
||||||
async def download(url: str = Form(...), mode: str = Form(...)):
|
async def download(url: str = Form(...), mode: str = Form(...)):
|
||||||
|
try:
|
||||||
path = download_video(url, mode)
|
path = download_video(url, mode)
|
||||||
|
write_log(f"Downloaded: {url} -> {path}")
|
||||||
|
|
||||||
# salva nella cronologia
|
|
||||||
with open(HISTORY_FILE, "r") as f:
|
with open(HISTORY_FILE, "r") as f:
|
||||||
history = json.load(f)
|
history = json.load(f)
|
||||||
|
|
||||||
@@ -50,14 +64,26 @@ async def download(url: str = Form(...), mode: str = Form(...)):
|
|||||||
json.dump(history, f, indent=2)
|
json.dump(history, f, indent=2)
|
||||||
|
|
||||||
return {"path": path}
|
return {"path": path}
|
||||||
|
except Exception as e:
|
||||||
|
write_log(f"Error: {str(e)}")
|
||||||
|
return JSONResponse(status_code=500, content={"error": str(e)})
|
||||||
|
|
||||||
|
|
||||||
@app.get("/history")
|
@app.get("/history")
|
||||||
async def history():
|
async def history():
|
||||||
|
try:
|
||||||
with open(HISTORY_FILE) as f:
|
with open(HISTORY_FILE) as f:
|
||||||
return JSONResponse(json.load(f))
|
return JSONResponse(json.load(f))
|
||||||
|
except Exception as e:
|
||||||
|
return JSONResponse(status_code=500, content={"error": str(e)})
|
||||||
|
|
||||||
|
|
||||||
@app.get("/file")
|
@app.get("/file")
|
||||||
async def file(path: str):
|
async def file(path: str):
|
||||||
return FileResponse(path)
|
try:
|
||||||
|
safe_path = os.path.join(DOWNLOAD_DIR, os.path.basename(path))
|
||||||
|
if not os.path.exists(safe_path):
|
||||||
|
return JSONResponse(status_code=404, content={"error": "File not found"})
|
||||||
|
return FileResponse(safe_path)
|
||||||
|
except Exception as e:
|
||||||
|
return JSONResponse(status_code=500, content={"error": str(e)})
|
||||||
|
|||||||
Reference in New Issue
Block a user