完全跑通1.0版本

This commit is contained in:
2026-05-26 12:56:03 +08:00
parent 2ece5174a7
commit 93c714a93b
11557 changed files with 1648225 additions and 36 deletions

View File

@@ -6,18 +6,38 @@ from .database import create_tables, AsyncSessionLocal
from .scheduler import start_scheduler, shutdown_scheduler
from .api import news, admin
from .config import settings
from .models.news import LLMConfig
from .models.news import LLMConfig, NewsSource
@asynccontextmanager
async def lifespan(app: FastAPI):
await create_tables()
await seed_initial_llm_config()
await seed_default_sources()
start_scheduler()
yield
shutdown_scheduler()
async def seed_default_sources():
"""Insert default news sources on first run if the table is empty."""
from .crawler.rss_fetcher import DEFAULT_SOURCES
from sqlalchemy import select
async with AsyncSessionLocal() as db:
result = await db.execute(select(NewsSource).limit(1))
if result.scalar_one_or_none():
return
for src in DEFAULT_SOURCES:
db.add(NewsSource(
name=src["name"],
url=src["url"],
source_type="rss",
language=src["language"],
category=src["category"],
))
await db.commit()
async def seed_initial_llm_config():
"""Insert default LLM config on first run if none exists."""
from sqlalchemy import select