feat: interface web minimale servie sur / (scalper serve) — SCAL-16
- page HTML autonome (aucune dépendance externe) : formulaires check-source + run - 40 tests OK + smoke loopback (GET / -> 200 text/html)
This commit is contained in:
1 parent
67b165e913
commit
5a2f281217
4 files changed
+49
-1
No files matched your search
@@ -73,7 +73,7 @@ CI GitHub Actions (lint + tests) sur chaque PR — voir `.github/workflows/ci.ym
|
||||
|
||||
```bash
|
||||
cp .env.example .env # MISTRAL_API_KEY (jamais committer)
|
||||
docker compose up -d # sert http://localhost:8000 (GET /healthz, GET /check-source, POST /run)
|
||||
docker compose up -d # API sur http://localhost:8000 + interface web sur http://localhost:8000/
|
||||
```
|
||||
|
||||
Déploiement pas à pas sur Coolify : [docs/deploy-coolify.md](docs/deploy-coolify.md).
|
||||
|
||||
@@ -31,6 +31,7 @@ Les résultats sont écrits dans le volume `./out` (monté dans le compose).
|
||||
## Endpoints
|
||||
| Méthode | Chemin | Rôle |
|
||||
|---|---|---|
|
||||
| GET | `/` | **interface web** (formulaires check-source + run) |
|
||||
| GET | `/healthz` | sonde de santé |
|
||||
| GET | `/check-source?source=...` | verdict légal (allowed/blocked) |
|
||||
| POST | `/run` | pipeline complet (check → scrape → clean → translate → QA → export) |
|
||||
|
||||
@@ -19,6 +19,34 @@ from urllib.parse import parse_qs, urlparse
|
||||
|
||||
from . import legal, pipeline
|
||||
|
||||
INDEX_HTML = """<!doctype html>
|
||||
<html lang="fr"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Scalper</title>
|
||||
<style>body{font-family:system-ui,sans-serif;max-width:46rem;margin:2rem auto;padding:0 1rem;color:#222}input,button{padding:.45rem;margin:.2rem}input{width:100%;box-sizing:border-box}fieldset{border:1px solid #ccc;border-radius:8px;margin-bottom:1rem}legend{font-weight:600}button{cursor:pointer;background:#222;color:#fff;border:0;border-radius:6px}pre{background:#f4f4f4;padding:1rem;border-radius:8px;overflow:auto;white-space:pre-wrap}.warn{color:#a00;font-size:.85rem}</style>
|
||||
</head><body>
|
||||
<h1>Scalper</h1>
|
||||
<p>Pipeline légal de scraping + traduction de chapitres. <span class="warn">Sources non déclarées ou bloquées (mangas-origines, keiyoushi.github.io) refusées.</span></p>
|
||||
<fieldset><legend>1. Vérifier une source</legend>
|
||||
<input id="cs-source" placeholder="https://... ou demo ou mangadex"><br>
|
||||
<button onclick="checkSource()">check-source</button>
|
||||
</fieldset>
|
||||
<fieldset><legend>2. Lancer un pipeline (check → scrape → clean → translate → QA → export)</legend>
|
||||
<input id="r-source" placeholder="source (demo, mangadex)" value="demo">
|
||||
<input id="r-series" placeholder="id série" value="demo-1">
|
||||
<input id="r-lang" placeholder="langue cible (fr, en, ...)" value="fr">
|
||||
<input id="r-group" placeholder="groupe optionnel (ex. Keiyoushi, mangadex uniquement)">
|
||||
<input id="r-max" placeholder="max chapitres (optionnel)">
|
||||
<label><input type="checkbox" id="r-mock" style="width:auto"> mock-llm (démo hors ligne)</label><br>
|
||||
<button onclick="runPipeline()">Lancer le pipeline</button>
|
||||
</fieldset>
|
||||
<pre id="out">résultats ici…</pre>
|
||||
<script>
|
||||
async function checkSource(){const s=document.getElementById('cs-source').value;const r=await fetch('/check-source?source='+encodeURIComponent(s));document.getElementById('out').textContent=r.status+'\\n'+JSON.stringify(await r.json(),null,2);}
|
||||
async function runPipeline(){const g=document.getElementById('r-group').value;const m=document.getElementById('r-max').value;const body={source:document.getElementById('r-source').value,series:document.getElementById('r-series').value,lang:document.getElementById('r-lang').value,mock_llm:document.getElementById('r-mock').checked};if(g)body.group=g;if(m)body.max_chapters=Number(m);document.getElementById('out').textContent='en cours…';const r=await fetch('/run',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});document.getElementById('out').textContent=r.status+'\\n'+JSON.stringify(await r.json(),null,2);}
|
||||
</script>
|
||||
</body></html>
|
||||
"""
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def log_message(self, *args) -> None: # silence les logs par requête
|
||||
@@ -32,8 +60,18 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def _html(self, code: int, content: str) -> None:
|
||||
body = content.encode("utf-8")
|
||||
self.send_response(code)
|
||||
self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def do_GET(self) -> None:
|
||||
u = urlparse(self.path)
|
||||
if u.path == "/":
|
||||
return self._html(200, INDEX_HTML)
|
||||
if u.path == "/healthz":
|
||||
return self._json(200, {"status": "ok"})
|
||||
if u.path == "/check-source":
|
||||
|
||||
@@ -44,6 +44,15 @@ class TestServer(unittest.TestCase):
|
||||
self.assertEqual(status, 200)
|
||||
self.assertEqual(body["status"], "ok")
|
||||
|
||||
def test_web_ui_served(self):
|
||||
with urllib.request.urlopen(f"http://127.0.0.1:{self.port}/") as r:
|
||||
body = r.read().decode("utf-8")
|
||||
self.assertEqual(r.status, 200)
|
||||
self.assertIn("text/html", r.headers.get("Content-Type", ""))
|
||||
self.assertIn("Scalper", body)
|
||||
self.assertIn("/run", body)
|
||||
self.assertIn("/check-source", body)
|
||||
|
||||
def test_check_source_demo_allowed(self):
|
||||
status, body = self._get("/check-source?source=demo")
|
||||
self.assertEqual(status, 200)
|
||||
|
||||
Reference in new issue
Block a user