aa
This commit is contained in:
@@ -16,6 +16,7 @@ RUN pip install --no-cache-dir -U pip setuptools wheel \
|
|||||||
|
|
||||||
COPY telegram-scraper.py app_web.py ./
|
COPY telegram-scraper.py app_web.py ./
|
||||||
COPY templates ./templates/
|
COPY templates ./templates/
|
||||||
|
COPY static ./static/
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
|
|||||||
25
app_web.py
25
app_web.py
@@ -17,11 +17,12 @@ from pathlib import Path
|
|||||||
from typing import Any, Dict, List, Optional, Tuple, Union
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
from fastapi import FastAPI, Form, Query, Request
|
from fastapi import FastAPI, Form, Query, Request
|
||||||
from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse
|
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, RedirectResponse, Response
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from starlette.middleware.sessions import SessionMiddleware
|
from starlette.middleware.sessions import SessionMiddleware
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent
|
BASE_DIR = Path(__file__).resolve().parent
|
||||||
|
STATIC_DIR = BASE_DIR / "static"
|
||||||
ENV_FILE = BASE_DIR / ".env"
|
ENV_FILE = BASE_DIR / ".env"
|
||||||
SCRIPT_FILE = BASE_DIR / "telegram-scraper.py"
|
SCRIPT_FILE = BASE_DIR / "telegram-scraper.py"
|
||||||
STATE_FILE = BASE_DIR / "state.json"
|
STATE_FILE = BASE_DIR / "state.json"
|
||||||
@@ -89,6 +90,25 @@ app.add_middleware(
|
|||||||
same_site="lax",
|
same_site="lax",
|
||||||
)
|
)
|
||||||
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
|
||||||
|
templates.env.globals["app_url"] = with_url_prefix
|
||||||
|
templates.env.globals["url_prefix"] = web_url_prefix
|
||||||
|
|
||||||
|
@app.get("/favicon.ico", include_in_schema=False)
|
||||||
|
async def favicon_ico():
|
||||||
|
path = STATIC_DIR / "favicon.png"
|
||||||
|
if path.is_file():
|
||||||
|
return FileResponse(path, media_type="image/png")
|
||||||
|
return Response(status_code=204)
|
||||||
|
|
||||||
|
|
||||||
|
_favicon_prefix = web_url_prefix()
|
||||||
|
if _favicon_prefix:
|
||||||
|
app.add_api_route(
|
||||||
|
f"{_favicon_prefix}/favicon.ico",
|
||||||
|
favicon_ico,
|
||||||
|
methods=["GET"],
|
||||||
|
include_in_schema=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Starlette 较新版本:TemplateResponse(request, name, context);旧版:(name, context)
|
# Starlette 较新版本:TemplateResponse(request, name, context);旧版:(name, context)
|
||||||
_template_response_new_style: Optional[bool] = None
|
_template_response_new_style: Optional[bool] = None
|
||||||
@@ -748,9 +768,6 @@ async def index(request: Request):
|
|||||||
"account_channels": account_channels,
|
"account_channels": account_channels,
|
||||||
"console_authed": authed,
|
"console_authed": authed,
|
||||||
"need_auth_banner": request.query_params.get("needauth") == "1",
|
"need_auth_banner": request.query_params.get("needauth") == "1",
|
||||||
"app_url": with_url_prefix,
|
|
||||||
"url_prefix": web_url_prefix(),
|
|
||||||
"app_home": app_home_url(),
|
|
||||||
"connected": service.is_connected(),
|
"connected": service.is_connected(),
|
||||||
"job_running": service.is_job_running(),
|
"job_running": service.is_job_running(),
|
||||||
"job_name": service.job_name,
|
"job_name": service.job_name,
|
||||||
|
|||||||
BIN
static/favicon.png
Normal file
BIN
static/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 619 KiB |
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Telegram Scraper 控制台</title>
|
<title>Telegram Scraper 控制台</title>
|
||||||
|
<link rel="icon" type="image/png" href="{{ app_url('/favicon.ico') }}" sizes="any" />
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
|
||||||
@@ -1037,7 +1038,7 @@
|
|||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
window.__URL_PREFIX__ = {{ url_prefix|tojson }};
|
window.__URL_PREFIX__ = {{ url_prefix()|tojson }};
|
||||||
function appPath(p) {
|
function appPath(p) {
|
||||||
p = p.startsWith("/") ? p : ("/" + p);
|
p = p.startsWith("/") ? p : ("/" + p);
|
||||||
var pre = window.__URL_PREFIX__ || "";
|
var pre = window.__URL_PREFIX__ || "";
|
||||||
|
|||||||
Reference in New Issue
Block a user