修复多个问题
This commit is contained in:
@@ -4,9 +4,9 @@ from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from app.config import settings
|
||||
from app.database import Base, engine, SessionLocal
|
||||
from app.models import HTMLFile
|
||||
from app.database import Base, SessionLocal, engine, ensure_database_schema
|
||||
from app.routers import html
|
||||
from app.routers.html import cleanup_expired_files
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
@@ -14,18 +14,19 @@ logging.basicConfig(
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
settings.html_storage_dir.mkdir(parents=True, exist_ok=True)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
ensure_database_schema()
|
||||
|
||||
# 删除过期记录
|
||||
db = SessionLocal()
|
||||
try:
|
||||
deleted_count = HTMLFile.delete_expired_records(db)
|
||||
if deleted_count > 0:
|
||||
logger.info(f"Deleted {deleted_count} expired HTML file records")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
app = FastAPI(title=settings.app_name)
|
||||
app = FastAPI(
|
||||
title=settings.app_name,
|
||||
version="2.0.0",
|
||||
description=(
|
||||
"Store agent-generated educational HTML pages and return a direct access URL. "
|
||||
"The generated OpenAPI document can be imported directly into Tencent Cloud "
|
||||
"Agent plugins."
|
||||
),
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -38,6 +39,20 @@ app.add_middleware(
|
||||
app.include_router(html.router, prefix=settings.api_prefix)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
@app.on_event("startup")
|
||||
def cleanup_on_startup() -> None:
|
||||
db = SessionLocal()
|
||||
try:
|
||||
deleted_count = cleanup_expired_files(db)
|
||||
if deleted_count > 0:
|
||||
logger.info("Deleted %s expired HTML files during startup", deleted_count)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@app.get("/", summary="Health check")
|
||||
def health_check() -> dict[str, str]:
|
||||
return {"message": "HTML Generator API is running"}
|
||||
return {
|
||||
"message": "HTML Knowledge API is running",
|
||||
"openapi_url": "/openapi.json",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user