This commit is contained in:
2026-04-27 02:00:03 +08:00
parent d4378afbc9
commit 459a5299a0
4 changed files with 24 additions and 5 deletions

View File

@@ -17,11 +17,12 @@ from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Union
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 starlette.middleware.sessions import SessionMiddleware
BASE_DIR = Path(__file__).resolve().parent
STATIC_DIR = BASE_DIR / "static"
ENV_FILE = BASE_DIR / ".env"
SCRIPT_FILE = BASE_DIR / "telegram-scraper.py"
STATE_FILE = BASE_DIR / "state.json"
@@ -89,6 +90,25 @@ app.add_middleware(
same_site="lax",
)
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)
_template_response_new_style: Optional[bool] = None
@@ -748,9 +768,6 @@ async def index(request: Request):
"account_channels": account_channels,
"console_authed": authed,
"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(),
"job_running": service.is_job_running(),
"job_name": service.job_name,