修改logo为上传

This commit is contained in:
2026-06-18 16:38:21 +08:00
parent 6f3faff72d
commit f9b3a51391
6 changed files with 286 additions and 130 deletions
-42
View File
@@ -777,48 +777,6 @@ def create_app() -> FastAPI:
except Exception as e:
return {"success": False, "error": str(e)}
@application.post("/api/admin/upload-pdf")
async def upload_pdf(
file: UploadFile = File(...),
config_key: str = Form(...),
):
"""Upload a PDF file and save URL to system config."""
from app.dependencies import get_db
from app.models.system_config import SystemConfig
from app.models.base import async_session
from sqlalchemy import select
if not file.filename or not file.filename.endswith('.pdf'):
raise HTTPException(status_code=400, detail="仅支持PDF文件")
# Save file
safe_name = f"{config_key}.pdf"
file_path = os.path.join(settings.UPLOAD_LOCAL_PATH, safe_name)
content = await file.read()
with open(file_path, "wb") as f:
f.write(content)
url = f"/uploads/{safe_name}"
# Update system config
async with async_session() as db:
result = await db.execute(
select(SystemConfig).where(SystemConfig.key == config_key).limit(1)
)
config = result.scalar_one_or_none()
if config:
config.value = url
else:
db.add(SystemConfig(
id=f"cfg_{config_key}",
key=config_key,
value=url,
description="用户协议" if "agreement" in config_key else "隐私政策",
))
await db.commit()
return {"url": url}
@application.get("/internal/", response_class=HTMLResponse)
async def index():
return """<!DOCTYPE html>