diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000000000000000000000000000000000..3dcb5967e1b68e7de342c933f0de945293ab15c7 --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# 环境 +DATABASE_URL=postgresql+asyncpg://postgres:password@localhost:5432/binv +SECRET_KEY=change-me-to-a-random-secret-key +ACCESS_TOKEN_EXPIRE_MINUTES=1440 + +# CORS +CORS_ORIGINS=http://localhost:3000,http://localhost:5555 + +# 同步 +SYNC_CRON_HOUR=1 +SYNC_MAX_CONCURRENT=3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a6b9eba88cc449b60ae2ec2792294ef7b182e014 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +__pycache__/ +*.py[cod] +*$py.class +.venv/ +venv/ +.env +*.egg-info/ +dist/ +build/ +.eggs/ +*.egg +alembic/versions/__pycache__/ +.pytest_cache/ +.mypy_cache/ +.idea/ +.vscode/ +*.sqlite3 diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..c9b576d60c68f66f218502e4091e79c6bd6e0f84 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# BinV API + +影视资源聚合 API 服务 + +## 快速开始 + +```bash +# 创建虚拟环境 +python -m venv .venv +# Windows +.venv\Scripts\activate +# Linux/Mac +source .venv/bin/activate + +# 安装依赖 +pip install -r requirements.txt + +# 复制环境变量 +cp .env.example .env + +# 初始化数据库 +alembic upgrade head + +# 创建超级管理员 +python scripts/create_superadmin.py + +# 初始化权限和角色 +python scripts/seed_permissions.py +python scripts/seed_roles.py + +# 启动开发服务 +uvicorn app.main:app --reload --port 9999 +``` + +## API 文档 + +启动后访问: +- Swagger UI: http://localhost:9999/docs +- ReDoc: http://localhost:9999/redoc diff --git a/alembic.ini b/alembic.ini new file mode 100644 index 0000000000000000000000000000000000000000..38e3dd203c412bc41480819181a7189bd5dc14cc --- /dev/null +++ b/alembic.ini @@ -0,0 +1,36 @@ +[alembic] +script_location = alembic +sqlalchemy.url = postgresql+asyncpg://postgres:password@localhost:5432/binv + +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/alembic/env.py b/alembic/env.py new file mode 100644 index 0000000000000000000000000000000000000000..571e8a199bb79f98de60dd6755e7068294a4eaf7 --- /dev/null +++ b/alembic/env.py @@ -0,0 +1,54 @@ +import asyncio +from logging.config import fileConfig + +from alembic import context +from sqlalchemy import pool +from sqlalchemy.ext.asyncio import async_engine_from_config + +from app.database import Base +from app.models import * # noqa: F401,F403 + +config = context.config +if config.config_file_name is not None: + fileConfig(config.config_file_name) + +target_metadata = Base.metadata + + +def run_migrations_offline() -> None: + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, + target_metadata=target_metadata, + literal_binds=True, + dialect_opts={"paramstyle": "named"}, + ) + with context.begin_transaction(): + context.run_migrations() + + +def do_run_migrations(connection): + context.configure(connection=connection, target_metadata=target_metadata) + with context.begin_transaction(): + context.run_migrations() + + +async def run_async_migrations() -> None: + connectable = async_engine_from_config( + config.get_section(config.config_ini_section, {}), + prefix="sqlalchemy.", + poolclass=pool.NullPool, + ) + async with connectable.connect() as connection: + await connection.run_sync(do_run_migrations) + await connectable.dispose() + + +def run_migrations_online() -> None: + asyncio.run(run_async_migrations()) + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/alembic/script.py.mako b/alembic/script.py.mako new file mode 100644 index 0000000000000000000000000000000000000000..17dcba0ef89f896010374bbb3db808071268aa4c --- /dev/null +++ b/alembic/script.py.mako @@ -0,0 +1,25 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa +${imports if imports else ""} + +revision: str = ${repr(up_revision)} +down_revision: Union[str, None] = ${repr(down_revision)} +branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} +depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} + + +def upgrade() -> None: + ${upgrades if upgrades else "pass"} + + +def downgrade() -> None: + ${downgrades if downgrades else "pass"} diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/config.py b/app/config.py new file mode 100644 index 0000000000000000000000000000000000000000..0917d646a3f269be50ca0ddb5db6ce6bbb21f882 --- /dev/null +++ b/app/config.py @@ -0,0 +1,15 @@ +from pydantic_settings import BaseSettings + + +class Settings(BaseSettings): + DATABASE_URL: str = "postgresql+asyncpg://postgres:password@localhost:5432/binv" + SECRET_KEY: str = "change-me-to-a-random-secret-key" + ACCESS_TOKEN_EXPIRE_MINUTES: int = 1440 + CORS_ORIGINS: str = "http://localhost:3000,http://localhost:5555" + SYNC_CRON_HOUR: int = 1 + SYNC_MAX_CONCURRENT: int = 3 + + model_config = {"env_file": ".env", "extra": "ignore"} + + +settings = Settings() diff --git a/app/database.py b/app/database.py new file mode 100644 index 0000000000000000000000000000000000000000..08f93cbb1df31efb59785f1bf6bacc10f8dc1fe7 --- /dev/null +++ b/app/database.py @@ -0,0 +1,23 @@ +from collections.abc import AsyncGenerator + +from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine +from sqlalchemy.orm import DeclarativeBase + +from app.config import settings + +engine = create_async_engine(settings.DATABASE_URL, echo=False) +async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) + + +class Base(DeclarativeBase): + pass + + +async def get_db() -> AsyncGenerator[AsyncSession, None]: + async with async_session() as session: + try: + yield session + await session.commit() + except Exception: + await session.rollback() + raise diff --git a/app/dependencies.py b/app/dependencies.py new file mode 100644 index 0000000000000000000000000000000000000000..4c741bb34348b442121185367adcd0e8b74e2006 --- /dev/null +++ b/app/dependencies.py @@ -0,0 +1,96 @@ +from collections.abc import AsyncGenerator + +from fastapi import Depends, HTTPException, status +from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer +from jose import JWTError, jwt +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession + +from app.config import settings +from app.database import get_db +from app.models.admin import Admin +from app.models.role import Role, AdminRole +from app.models.permission import Permission, RolePermission +from app.models.user import User + +security = HTTPBearer() + + +async def get_current_admin( + credentials: HTTPAuthorizationCredentials = Depends(security), + db: AsyncSession = Depends(get_db), +) -> Admin: + token = credentials.credentials + try: + payload = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"]) + admin_id: int | None = payload.get("sub") + if admin_id is None: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token") + except JWTError: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token") + + result = await db.execute(select(Admin).where(Admin.id == int(admin_id))) + admin = result.scalar_one_or_none() + if admin is None or not admin.is_active: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Admin not found") + return admin + + +async def get_current_user( + credentials: HTTPAuthorizationCredentials = Depends(security), + db: AsyncSession = Depends(get_db), +) -> User: + token = credentials.credentials + try: + payload = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"]) + user_id: int | None = payload.get("sub") + user_type: str | None = payload.get("type") + if user_id is None or user_type != "user": + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token") + except JWTError: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid token") + + result = await db.execute(select(User).where(User.id == int(user_id))) + user = result.scalar_one_or_none() + if user is None or not user.is_active: + raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="User not found") + return user + + +async def get_admin_roles(admin: Admin, db: AsyncSession = Depends(get_db)) -> list[str]: + result = await db.execute( + select(Role.code) + .join(AdminRole, AdminRole.role_id == Role.id) + .where(AdminRole.admin_id == admin.id, Role.status == 1) + ) + return [r[0] for r in result.all()] + + +async def get_admin_permissions(admin: Admin, db: AsyncSession = Depends(get_db)) -> list[str]: + result = await db.execute( + select(Permission.code) + .join(RolePermission, RolePermission.permission_id == Permission.id) + .join(AdminRole, AdminRole.role_id == RolePermission.role_id) + .where(AdminRole.admin_id == admin.id, Permission.status == 1) + .distinct() + ) + return [p[0] for p in result.all()] + + +def require_permission(permission_code: str): + async def permission_checker( + admin: Admin = Depends(get_current_admin), + db: AsyncSession = Depends(get_db), + ) -> Admin: + roles = await get_admin_roles(admin, db) + if "super_admin" in roles: + return admin + permissions = await get_admin_permissions(admin, db) + if permission_code not in permissions: + raise HTTPException( + status_code=status.HTTP_403_FORBIDDEN, + detail=f"Permission denied: {permission_code}", + ) + return admin + + return permission_checker diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000000000000000000000000000000000000..1e1c48cc91177091766a141285b45d63be7a8c08 --- /dev/null +++ b/app/main.py @@ -0,0 +1,36 @@ +from contextlib import asynccontextmanager + +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +from app.config import settings +from app.routers import admin_router, user_router + + +@asynccontextmanager +async def lifespan(app: FastAPI): + yield + + +app = FastAPI( + title="BinV API", + description="影视资源聚合API服务", + version="0.1.0", + lifespan=lifespan, +) + +app.add_middleware( + CORSMiddleware, + allow_origins=[o.strip() for o in settings.CORS_ORIGINS.split(",")], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +app.include_router(admin_router, prefix="/admin") +app.include_router(user_router, prefix="/user") + + +@app.get("/health") +async def health_check(): + return {"status": "ok"} diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..be67cbf392565c54f9d700238dcf9a8b2a3b628a --- /dev/null +++ b/app/models/__init__.py @@ -0,0 +1,30 @@ +from app.models.source_site import SourceSite +from app.models.vod import Vod +from app.models.vod_source import VodSource +from app.models.category import Category, CategoryMapping +from app.models.admin import Admin +from app.models.role import Role, AdminRole +from app.models.permission import Permission, RolePermission +from app.models.user import User +from app.models.favorite import Favorite +from app.models.play_history import PlayHistory +from app.models.sync_log import SyncLog +from app.models.source_health import SourceHealth + +__all__ = [ + "SourceSite", + "Vod", + "VodSource", + "Category", + "CategoryMapping", + "Admin", + "Role", + "AdminRole", + "Permission", + "RolePermission", + "User", + "Favorite", + "PlayHistory", + "SyncLog", + "SourceHealth", +] diff --git a/app/models/admin.py b/app/models/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..2e49962e0597e46b68a64355d92ea31d1b9d024e --- /dev/null +++ b/app/models/admin.py @@ -0,0 +1,20 @@ +from datetime import datetime + +from sqlalchemy import Boolean, DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class Admin(Base): + __tablename__ = "admin" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + username: Mapped[str] = mapped_column(String(30), unique=True, nullable=False, comment="用户名") + password_hash: Mapped[str] = mapped_column(String(128), nullable=False, comment="bcrypt哈希") + nickname: Mapped[str | None] = mapped_column(String(30), comment="昵称") + avatar: Mapped[str | None] = mapped_column(String(500), comment="头像URL") + is_active: Mapped[bool] = mapped_column(Boolean, default=True, comment="是否启用") + last_login_at: Mapped[datetime | None] = mapped_column(DateTime, comment="最后登录时间") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) diff --git a/app/models/category.py b/app/models/category.py new file mode 100644 index 0000000000000000000000000000000000000000..152c1132ac1d994b1bd58233b5e9e3f4a3ee02e7 --- /dev/null +++ b/app/models/category.py @@ -0,0 +1,27 @@ +from datetime import datetime + +from sqlalchemy import Boolean, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class Category(Base): + __tablename__ = "category" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + name: Mapped[str] = mapped_column(String(30), nullable=False, comment="分类名称") + parent_id: Mapped[int | None] = mapped_column(Integer, comment="父分类ID") + sort_order: Mapped[int] = mapped_column(Integer, default=0, comment="排序") + is_active: Mapped[bool] = mapped_column(Boolean, default=True, comment="是否启用") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + + +class CategoryMapping(Base): + __tablename__ = "category_mapping" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + category_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="统一分类ID") + source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID") + source_type_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="源站分类ID") + source_type_name: Mapped[str] = mapped_column(String(30), nullable=False, comment="源站分类名称") diff --git a/app/models/favorite.py b/app/models/favorite.py new file mode 100644 index 0000000000000000000000000000000000000000..8396e300a49907e047437339f6f072de1da1ea84 --- /dev/null +++ b/app/models/favorite.py @@ -0,0 +1,15 @@ +from datetime import datetime + +from sqlalchemy import DateTime, Integer, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class Favorite(Base): + __tablename__ = "favorite" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + user_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="用户ID") + vod_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="影片ID") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) diff --git a/app/models/permission.py b/app/models/permission.py new file mode 100644 index 0000000000000000000000000000000000000000..311ef316a3a680758df9c4a26949e80d28f4046d --- /dev/null +++ b/app/models/permission.py @@ -0,0 +1,31 @@ +from datetime import datetime + +from sqlalchemy import DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class Permission(Base): + __tablename__ = "permission" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + code: Mapped[str] = mapped_column(String(60), unique=True, nullable=False, comment="权限码") + name: Mapped[str] = mapped_column(String(50), nullable=False, comment="权限名称") + type: Mapped[str] = mapped_column(String(10), nullable=False, comment="menu/page/btn") + parent_id: Mapped[int | None] = mapped_column(Integer, comment="父权限ID") + path: Mapped[str | None] = mapped_column(String(200), comment="路由路径(仅menu)") + component: Mapped[str | None] = mapped_column(String(200), comment="前端组件路径(仅menu)") + redirect: Mapped[str | None] = mapped_column(String(200), comment="重定向路径(仅menu)") + icon: Mapped[str | None] = mapped_column(String(50), comment="菜单图标(仅menu)") + sort_order: Mapped[int] = mapped_column(Integer, default=0, comment="排序") + status: Mapped[int] = mapped_column(Integer, default=1, comment="1=启用 0=禁用") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + + +class RolePermission(Base): + __tablename__ = "role_permission" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + role_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="角色ID") + permission_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="权限ID") diff --git a/app/models/play_history.py b/app/models/play_history.py new file mode 100644 index 0000000000000000000000000000000000000000..b597ebf0f131de4e19113eee977610d392cfea76 --- /dev/null +++ b/app/models/play_history.py @@ -0,0 +1,21 @@ +from datetime import datetime + +from sqlalchemy import DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class PlayHistory(Base): + __tablename__ = "play_history" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + user_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="用户ID") + vod_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="影片ID") + source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID") + episode: Mapped[str | None] = mapped_column(String(50), comment="集名") + play_url: Mapped[str] = mapped_column(String, nullable=False, comment="播放地址") + progress: Mapped[int] = mapped_column(Integer, default=0, comment="播放进度(秒)") + duration: Mapped[int] = mapped_column(Integer, default=0, comment="总时长(秒)") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) diff --git a/app/models/role.py b/app/models/role.py new file mode 100644 index 0000000000000000000000000000000000000000..01563d736850248f864fd3f1c31d2f9a9f9f1a90 --- /dev/null +++ b/app/models/role.py @@ -0,0 +1,27 @@ +from datetime import datetime + +from sqlalchemy import Boolean, DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class Role(Base): + __tablename__ = "role" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + name: Mapped[str] = mapped_column(String(30), unique=True, nullable=False, comment="角色名称") + code: Mapped[str] = mapped_column(String(30), unique=True, nullable=False, comment="角色编码") + description: Mapped[str | None] = mapped_column(String(200), comment="角色描述") + is_builtin: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否内置角色") + status: Mapped[int] = mapped_column(Integer, default=1, comment="1=启用 0=禁用") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) + + +class AdminRole(Base): + __tablename__ = "admin_role" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + admin_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="管理员ID") + role_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="角色ID") diff --git a/app/models/source_health.py b/app/models/source_health.py new file mode 100644 index 0000000000000000000000000000000000000000..09ef51c7a308585d49d985ba13135328d69e922e --- /dev/null +++ b/app/models/source_health.py @@ -0,0 +1,18 @@ +from datetime import datetime + +from sqlalchemy import Boolean, DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class SourceHealth(Base): + __tablename__ = "source_health" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID") + check_type: Mapped[str] = mapped_column(String(20), nullable=False, comment="api/play") + is_success: Mapped[bool] = mapped_column(Boolean, nullable=False, comment="是否成功") + response_time_ms: Mapped[int | None] = mapped_column(Integer, comment="响应时间(ms)") + error_message: Mapped[str | None] = mapped_column(String, comment="错误信息") + checked_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) diff --git a/app/models/source_site.py b/app/models/source_site.py new file mode 100644 index 0000000000000000000000000000000000000000..a48137fae5bbd92286295f767b299e386addd2ef --- /dev/null +++ b/app/models/source_site.py @@ -0,0 +1,29 @@ +from datetime import datetime + +from sqlalchemy import Boolean, DateTime, Integer, String, Text, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class SourceSite(Base): + __tablename__ = "source_site" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + name: Mapped[str] = mapped_column(String(50), nullable=False, comment="站点名称") + code: Mapped[str] = mapped_column(String(30), unique=True, nullable=False, comment="站点编码") + base_url: Mapped[str] = mapped_column(String(500), nullable=False, comment="API基础地址") + site_url: Mapped[str | None] = mapped_column(String(500), comment="官网地址") + play_from_m3u8: Mapped[str | None] = mapped_column(String(30), comment="M3U8来源标识") + play_from_yun: Mapped[str | None] = mapped_column(String(30), comment="云播来源标识") + parse_url: Mapped[str | None] = mapped_column(String(500), comment="M3U8解析接口") + is_active: Mapped[bool] = mapped_column(Boolean, default=True, comment="是否启用") + sync_interval: Mapped[int] = mapped_column(Integer, default=60, comment="同步间隔(分钟)") + last_sync_at: Mapped[datetime | None] = mapped_column(DateTime, comment="最后同步时间") + last_sync_status: Mapped[str | None] = mapped_column(String(20), comment="最后同步状态") + last_sync_count: Mapped[int] = mapped_column(Integer, default=0, comment="最后同步新增数量") + total_count: Mapped[int] = mapped_column(Integer, default=0, comment="资源总数") + sort_order: Mapped[int] = mapped_column(Integer, default=0, comment="排序权重") + remark: Mapped[str | None] = mapped_column(String(200), comment="备注") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) diff --git a/app/models/sync_log.py b/app/models/sync_log.py new file mode 100644 index 0000000000000000000000000000000000000000..cb9467639fbbd1508bab7ad551124aa7db189148 --- /dev/null +++ b/app/models/sync_log.py @@ -0,0 +1,22 @@ +from datetime import datetime + +from sqlalchemy import DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class SyncLog(Base): + __tablename__ = "sync_log" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID") + status: Mapped[str] = mapped_column(String(20), nullable=False, comment="running/success/failed") + started_at: Mapped[datetime] = mapped_column(DateTime, nullable=False, comment="开始时间") + finished_at: Mapped[datetime | None] = mapped_column(DateTime, comment="结束时间") + total_fetched: Mapped[int] = mapped_column(Integer, default=0, comment="拉取总数") + new_count: Mapped[int] = mapped_column(Integer, default=0, comment="新增数") + update_count: Mapped[int] = mapped_column(Integer, default=0, comment="更新数") + fail_count: Mapped[int] = mapped_column(Integer, default=0, comment="失败数") + error_message: Mapped[str | None] = mapped_column(String, comment="错误信息") + duration_seconds: Mapped[int | None] = mapped_column(Integer, comment="耗时秒数") diff --git a/app/models/user.py b/app/models/user.py new file mode 100644 index 0000000000000000000000000000000000000000..7b02385ee2ba847bccd99429731ba8f2d6afe2e2 --- /dev/null +++ b/app/models/user.py @@ -0,0 +1,22 @@ +from datetime import datetime + +from sqlalchemy import Boolean, DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class User(Base): + __tablename__ = "user" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + username: Mapped[str | None] = mapped_column(String(30), unique=True, comment="用户名") + email: Mapped[str | None] = mapped_column(String(100), unique=True, comment="邮箱") + phone: Mapped[str | None] = mapped_column(String(20), unique=True, comment="手机号") + password_hash: Mapped[str] = mapped_column(String(128), nullable=False, comment="bcrypt哈希") + nickname: Mapped[str | None] = mapped_column(String(30), comment="昵称") + avatar: Mapped[str | None] = mapped_column(String(500), comment="头像URL") + is_active: Mapped[bool] = mapped_column(Boolean, default=True, comment="是否启用") + last_login_at: Mapped[datetime | None] = mapped_column(DateTime, comment="最后登录时间") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) diff --git a/app/models/vod.py b/app/models/vod.py new file mode 100644 index 0000000000000000000000000000000000000000..f6dab61b65399b8f5beb5c835f828dd7effbb458 --- /dev/null +++ b/app/models/vod.py @@ -0,0 +1,34 @@ +from datetime import datetime + +from sqlalchemy import Boolean, Float, Integer, String, Text, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class Vod(Base): + __tablename__ = "vod" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + name: Mapped[str] = mapped_column(String(200), nullable=False, comment="影片名称") + sub_name: Mapped[str | None] = mapped_column(String(500), comment="副标题/别名") + en_name: Mapped[str | None] = mapped_column(String(200), comment="英文拼音") + category_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="分类ID") + cover: Mapped[str | None] = mapped_column(String(500), comment="封面图URL") + actor: Mapped[str | None] = mapped_column(String(2000), comment="演员,逗号分隔") + director: Mapped[str | None] = mapped_column(String(200), comment="导演") + area: Mapped[str | None] = mapped_column(String(50), comment="地区") + lang: Mapped[str | None] = mapped_column(String(50), comment="语言") + year: Mapped[str | None] = mapped_column(String(10), comment="年份") + duration: Mapped[str | None] = mapped_column(String(20), comment="时长") + score: Mapped[float | None] = mapped_column(Float, comment="评分 0-10") + douban_id: Mapped[int | None] = mapped_column(Integer, comment="豆瓣ID") + blurb: Mapped[str | None] = mapped_column(Text, comment="简介") + content: Mapped[str | None] = mapped_column(Text, comment="详细介绍(HTML)") + remarks: Mapped[str | None] = mapped_column(String(100), comment="备注(如第39集)") + is_end: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否完结") + is_hidden: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否隐藏") + is_recommended: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否推荐") + view_count: Mapped[int] = mapped_column(Integer, default=0, comment="播放次数") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) diff --git a/app/models/vod_source.py b/app/models/vod_source.py new file mode 100644 index 0000000000000000000000000000000000000000..a07c70384e469c0a4814a9f0fd82f5efb7cf6b05 --- /dev/null +++ b/app/models/vod_source.py @@ -0,0 +1,22 @@ +from datetime import datetime + +from sqlalchemy import Boolean, DateTime, Integer, String, func +from sqlalchemy.orm import Mapped, mapped_column + +from app.database import Base + + +class VodSource(Base): + __tablename__ = "vod_source" + + id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) + vod_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="影片ID") + source_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="资源站ID") + source_vod_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="源站影片ID") + play_from: Mapped[str] = mapped_column(String(30), nullable=False, comment="播放来源") + play_url: Mapped[str] = mapped_column(String, nullable=False, comment="播放地址(原始)") + parse_url: Mapped[str | None] = mapped_column(String, comment="解析后URL") + is_available: Mapped[bool] = mapped_column(Boolean, default=True, comment="是否可用") + last_check_at: Mapped[datetime | None] = mapped_column(DateTime, comment="可用性检查时间") + created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now()) + updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now()) diff --git a/app/routers/__init__.py b/app/routers/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..78762d415a34708389129a15fbdc16e2a3925c67 --- /dev/null +++ b/app/routers/__init__.py @@ -0,0 +1,22 @@ +from fastapi import APIRouter + +from app.routers.admin import auth as admin_auth +from app.routers.admin import source as admin_source +from app.routers.admin import vod as admin_vod +from app.routers.admin import category as admin_category +from app.routers.admin import user_mgmt as admin_user_mgmt +from app.routers.admin import admin_mgmt as admin_admin_mgmt +from app.routers.admin import role_mgmt as admin_role_mgmt +from app.routers.admin import sync as admin_sync +from app.routers.admin import system as admin_system + +admin_router = APIRouter() +admin_router.include_router(admin_auth.router, prefix="/auth", tags=["Admin-Auth"]) +admin_router.include_router(admin_source.router, prefix="/source", tags=["Admin-Source"]) +admin_router.include_router(admin_vod.router, prefix="/vod", tags=["Admin-Vod"]) +admin_router.include_router(admin_category.router, prefix="/category", tags=["Admin-Category"]) +admin_router.include_router(admin_user_mgmt.router, prefix="/user", tags=["Admin-User"]) +admin_router.include_router(admin_admin_mgmt.router, prefix="/admin", tags=["Admin-Admin"]) +admin_router.include_router(admin_role_mgmt.router, prefix="/role", tags=["Admin-Role"]) +admin_router.include_router(admin_sync.router, prefix="/sync", tags=["Admin-Sync"]) +admin_router.include_router(admin_system.router, prefix="/system", tags=["Admin-System"]) diff --git a/app/routers/admin/__init__.py b/app/routers/admin/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/routers/admin/admin_mgmt.py b/app/routers/admin/admin_mgmt.py new file mode 100644 index 0000000000000000000000000000000000000000..02cdb69041289511b82e67258527df4f16d2304d --- /dev/null +++ b/app/routers/admin/admin_mgmt.py @@ -0,0 +1,33 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_admins(): + pass + + +@router.post("") +async def create_admin(): + pass + + +@router.put("/{admin_id}") +async def update_admin(admin_id: int): + pass + + +@router.delete("/{admin_id}") +async def delete_admin(admin_id: int): + pass + + +@router.put("/{admin_id}/reset-password") +async def reset_password(admin_id: int): + pass + + +@router.put("/{admin_id}/assign-roles") +async def assign_roles(admin_id: int): + pass diff --git a/app/routers/admin/auth.py b/app/routers/admin/auth.py new file mode 100644 index 0000000000000000000000000000000000000000..3987099cccced9da9e1433b1236e92019f4d9506 --- /dev/null +++ b/app/routers/admin/auth.py @@ -0,0 +1,33 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.post("/login") +async def login(): + pass + + +@router.post("/logout") +async def logout(): + pass + + +@router.get("/user-info") +async def get_user_info(): + pass + + +@router.get("/codes") +async def get_access_codes(): + pass + + +@router.get("/menus") +async def get_menus(): + pass + + +@router.get("/permissions") +async def get_permissions(): + pass diff --git a/app/routers/admin/category.py b/app/routers/admin/category.py new file mode 100644 index 0000000000000000000000000000000000000000..3ea51be96095ee15f17e6716e3f2b7f52ef6c3e2 --- /dev/null +++ b/app/routers/admin/category.py @@ -0,0 +1,18 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_categories(): + pass + + +@router.put("/{category_id}") +async def update_category(category_id: int): + pass + + +@router.put("/mapping") +async def update_mapping(): + pass diff --git a/app/routers/admin/role_mgmt.py b/app/routers/admin/role_mgmt.py new file mode 100644 index 0000000000000000000000000000000000000000..4954f5183127f8492a27a8906dc5bed511760faf --- /dev/null +++ b/app/routers/admin/role_mgmt.py @@ -0,0 +1,28 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_roles(): + pass + + +@router.post("") +async def create_role(): + pass + + +@router.put("/{role_id}") +async def update_role(role_id: int): + pass + + +@router.delete("/{role_id}") +async def delete_role(role_id: int): + pass + + +@router.put("/{role_id}/permissions") +async def assign_permissions(role_id: int): + pass diff --git a/app/routers/admin/source.py b/app/routers/admin/source.py new file mode 100644 index 0000000000000000000000000000000000000000..d74a6364376f7588c4be822c393916980e34aae4 --- /dev/null +++ b/app/routers/admin/source.py @@ -0,0 +1,43 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_sources(): + pass + + +@router.post("") +async def create_source(): + pass + + +@router.get("/{source_id}") +async def get_source(source_id: int): + pass + + +@router.put("/{source_id}") +async def update_source(source_id: int): + pass + + +@router.delete("/{source_id}") +async def delete_source(source_id: int): + pass + + +@router.post("/{source_id}/test") +async def test_source(source_id: int): + pass + + +@router.post("/{source_id}/sync") +async def sync_source(source_id: int): + pass + + +@router.put("/{source_id}/enable") +async def enable_source(source_id: int): + pass diff --git a/app/routers/admin/sync.py b/app/routers/admin/sync.py new file mode 100644 index 0000000000000000000000000000000000000000..c3e0b7688a8ad40fcd115c167d74bc25b46f8c71 --- /dev/null +++ b/app/routers/admin/sync.py @@ -0,0 +1,13 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("/log") +async def list_sync_logs(): + pass + + +@router.post("/trigger") +async def trigger_sync(): + pass diff --git a/app/routers/admin/system.py b/app/routers/admin/system.py new file mode 100644 index 0000000000000000000000000000000000000000..57d63e1dbe081ff4c1536cae41d9471ffff90864 --- /dev/null +++ b/app/routers/admin/system.py @@ -0,0 +1,13 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("/config") +async def get_config(): + pass + + +@router.put("/config") +async def update_config(): + pass diff --git a/app/routers/admin/user_mgmt.py b/app/routers/admin/user_mgmt.py new file mode 100644 index 0000000000000000000000000000000000000000..ee4b616428696f4fa5c41a111e5621dcfaf09086 --- /dev/null +++ b/app/routers/admin/user_mgmt.py @@ -0,0 +1,23 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_users(): + pass + + +@router.get("/{user_id}") +async def get_user(user_id: int): + pass + + +@router.put("/{user_id}/ban") +async def ban_user(user_id: int): + pass + + +@router.delete("/{user_id}") +async def delete_user(user_id: int): + pass diff --git a/app/routers/admin/vod.py b/app/routers/admin/vod.py new file mode 100644 index 0000000000000000000000000000000000000000..f222e570e29e16a2bc6dfa351cb71fdd10cbb842 --- /dev/null +++ b/app/routers/admin/vod.py @@ -0,0 +1,33 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_vods(): + pass + + +@router.get("/{vod_id}") +async def get_vod(vod_id: int): + pass + + +@router.put("/{vod_id}") +async def update_vod(vod_id: int): + pass + + +@router.delete("/{vod_id}") +async def delete_vod(vod_id: int): + pass + + +@router.put("/{vod_id}/hide") +async def toggle_hide(vod_id: int): + pass + + +@router.put("/{vod_id}/recommend") +async def toggle_recommend(vod_id: int): + pass diff --git a/app/routers/user/__init__.py b/app/routers/user/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..d639f3f12ea6b724d1717d38697802a63c085b30 --- /dev/null +++ b/app/routers/user/__init__.py @@ -0,0 +1,14 @@ +from fastapi import APIRouter + +from app.routers.user import auth as user_auth +from app.routers.user import vod as user_vod +from app.routers.user import category as user_category +from app.routers.user import favorite as user_favorite +from app.routers.user import history as user_history + +user_router = APIRouter() +user_router.include_router(user_auth.router, prefix="/auth", tags=["User-Auth"]) +user_router.include_router(user_vod.router, prefix="/vod", tags=["User-Vod"]) +user_router.include_router(user_category.router, prefix="/category", tags=["User-Category"]) +user_router.include_router(user_favorite.router, prefix="/favorite", tags=["User-Favorite"]) +user_router.include_router(user_history.router, prefix="/history", tags=["User-History"]) diff --git a/app/routers/user/auth.py b/app/routers/user/auth.py new file mode 100644 index 0000000000000000000000000000000000000000..e60ae15daf4a795e22b36eb3a751df7347a18d23 --- /dev/null +++ b/app/routers/user/auth.py @@ -0,0 +1,18 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.post("/register") +async def register(): + pass + + +@router.post("/login") +async def login(): + pass + + +@router.get("/profile") +async def get_profile(): + pass diff --git a/app/routers/user/category.py b/app/routers/user/category.py new file mode 100644 index 0000000000000000000000000000000000000000..e74dddfcf697773af2b8a33bf246f50c9b9a0ba7 --- /dev/null +++ b/app/routers/user/category.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_categories(): + pass diff --git a/app/routers/user/favorite.py b/app/routers/user/favorite.py new file mode 100644 index 0000000000000000000000000000000000000000..3f1b64c67ba10b85d7e25354d87a19c8ae3494ea --- /dev/null +++ b/app/routers/user/favorite.py @@ -0,0 +1,18 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_favorites(): + pass + + +@router.post("") +async def add_favorite(): + pass + + +@router.delete("/{vod_id}") +async def remove_favorite(vod_id: int): + pass diff --git a/app/routers/user/history.py b/app/routers/user/history.py new file mode 100644 index 0000000000000000000000000000000000000000..d7dffea9d051eb1438735e07151d7a5d258886ac --- /dev/null +++ b/app/routers/user/history.py @@ -0,0 +1,18 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_history(): + pass + + +@router.post("") +async def record_history(): + pass + + +@router.delete("/{history_id}") +async def delete_history(history_id: int): + pass diff --git a/app/routers/user/vod.py b/app/routers/user/vod.py new file mode 100644 index 0000000000000000000000000000000000000000..eacd2fe963c566bf63cc47a6b78dc1dec1ee42d0 --- /dev/null +++ b/app/routers/user/vod.py @@ -0,0 +1,28 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("") +async def list_vods(): + pass + + +@router.get("/search") +async def search_vods(): + pass + + +@router.get("/recommended") +async def recommended_vods(): + pass + + +@router.get("/latest") +async def latest_vods(): + pass + + +@router.get("/{vod_id}") +async def get_vod(vod_id: int): + pass diff --git a/app/schemas/__init__.py b/app/schemas/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/__init__.py b/app/schemas/admin/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/admin_mgmt.py b/app/schemas/admin/admin_mgmt.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/auth.py b/app/schemas/admin/auth.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/category.py b/app/schemas/admin/category.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/role_mgmt.py b/app/schemas/admin/role_mgmt.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/source.py b/app/schemas/admin/source.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/sync.py b/app/schemas/admin/sync.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/system.py b/app/schemas/admin/system.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/user_mgmt.py b/app/schemas/admin/user_mgmt.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/admin/vod.py b/app/schemas/admin/vod.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/user/__init__.py b/app/schemas/user/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/user/auth.py b/app/schemas/user/auth.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/user/category.py b/app/schemas/user/category.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/user/favorite.py b/app/schemas/user/favorite.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/user/history.py b/app/schemas/user/history.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/schemas/user/vod.py b/app/schemas/user/vod.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/__init__.py b/app/services/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/auth_admin.py b/app/services/auth_admin.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/auth_user.py b/app/services/auth_user.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/category.py b/app/services/category.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/collector.py b/app/services/collector.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/health.py b/app/services/health.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/rbac.py b/app/services/rbac.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/sync.py b/app/services/sync.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/services/vod.py b/app/services/vod.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/tasks/__init__.py b/app/tasks/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/tasks/sync.py b/app/tasks/sync.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/utils/__init__.py b/app/utils/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/utils/auth.py b/app/utils/auth.py new file mode 100644 index 0000000000000000000000000000000000000000..d2a4e4dee569d56b3552b3c2594d72549dcea4db --- /dev/null +++ b/app/utils/auth.py @@ -0,0 +1,24 @@ +from datetime import datetime, timedelta, timezone + +from jose import jwt +from passlib.context import CryptContext + +from app.config import settings + +pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") + + +def hash_password(password: str) -> str: + return pwd_context.hash(password) + + +def verify_password(plain_password: str, hashed_password: str) -> bool: + return pwd_context.verify(plain_password, hashed_password) + + +def create_access_token(subject: str, token_type: str = "admin", expires_delta: timedelta | None = None) -> str: + if expires_delta is None: + expires_delta = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES) + expire = datetime.now(timezone.utc) + expires_delta + to_encode = {"sub": subject, "type": token_type, "exp": expire} + return jwt.encode(to_encode, settings.SECRET_KEY, algorithm="HS256") diff --git a/app/utils/dedup.py b/app/utils/dedup.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/utils/parse.py b/app/utils/parse.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/docs/01-overview.md b/docs/01-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..6eafebfe69b83f5db02660cd77fdfb8a0849356a --- /dev/null +++ b/docs/01-overview.md @@ -0,0 +1,107 @@ +# D01 - 项目概述 + +## 项目名称 + +BinV API — 影视资源聚合API服务 + +## 项目愿景 + +聚合多个免费影视资源站的数据,提供统一的RESTful API接口,供管理后台(admin)和用户前端(web)消费。屏蔽各资源站接口差异,实现数据去重、多源优选、缓存加速。 + +## 项目类型 + +Profile D — API Service / Microservice + +- 无UI界面 +- 有后端逻辑与数据库 +- HTTP API通信 +- 主要语言:Python +- 框架:FastAPI + +## 目标用户 + +| 用户类型 | 场景 | 需求 | +|---|---|---| +| 管理员 | 通过admin后台管理资源站、影片、同步 | 完整CRUD、RBAC权限、同步监控 | +| 普通用户 | 通过web前端浏览、搜索、播放影片 | 浏览/搜索/播放/收藏/历史 | +| 第三方开发者 | 调用API获取影视数据 | 稳定接口、清晰文档 | + +## 核心价值 + +1. **统一接口**:9+资源站各异接口 → 一套标准化API +2. **数据去重**:同一影片多站重复 → 按名称+年份去重合并 +3. **多源优选**:一个影片多个播放源 → 按速度/可用性排序 +4. **缓存加速**:热门数据缓存 → 响应快、减少源站压力 +5. **增量同步**:定时采集更新 → 数据保持最新 + +## 技术栈 + +| 层 | 技术 | 版本 | +|---|---|---| +| 语言 | Python | 3.11+ | +| 框架 | FastAPI | 0.115+ | +| ORM | SQLAlchemy | 2.0+ | +| 数据库迁移 | Alembic | 1.13+ | +| 数据库 | PostgreSQL | 15+ (Neon免费tier) | +| 缓存 | Redis | 7+ (可选,部署时决定) | +| 定时任务 | APScheduler | 3.10+ | +| HTTP客户端 | httpx | 0.27+ | +| 数据校验 | Pydantic | 2.0+ | +| 鉴权 | python-jose + passlib | JWT | + +## 核心约束 + +1. **端点严格分离**:admin和user端点不共享路径,前缀分别为 `/admin/` 和 `/user/` +2. **RBAC权限**:admin端支持页面级+按钮级权限控制 +3. **可选登录**:user端大部分接口无需鉴权,登录后解锁收藏/历史等 +4. **采集频率**:对源站请求间隔 ≥1秒,避免被封 +5. **免费部署**:目标部署在免费平台(Render/Railway),需注意资源限制 + +## 优先级 + +| 优先级 | 模块 | 说明 | +|---|---|---| +| P0 | 资源站采集与同步 | 核心功能,没有数据一切免谈 | +| P0 | 统一API接口 | 对外服务的基础 | +| P0 | Admin鉴权与RBAC | 管理后台的根基 | +| P1 | 影片去重与多源合并 | 数据质量的关键 | +| P1 | 缓存层 | 性能保障 | +| P2 | User鉴权(可选登录) | 增值功能 | +| P2 | 收藏/历史 | 用户粘性功能 | +| P3 | 播放统计 | 运营数据 | +| P3 | 源站健康监控 | 运维辅助 | + +## 路线图 + +### Phase 1 — MVP(2周) + +- 项目骨架搭建 +- 数据库模型与迁移 +- 资源站配置CRUD(admin) +- 单站采集+存储 +- 影片列表/详情/搜索API(user) +- Admin登录+基础RBAC + +### Phase 2 — 多源聚合(1周) + +- 多站并发采集 +- 影片去重逻辑 +- 多源播放地址合并 +- 增量同步(定时任务) + +### Phase 3 — 完善(1周) + +- User可选登录 +- 收藏/历史功能 +- 缓存层 +- 源站健康监控 +- 播放统计 + +## 风险 + +| 风险 | 影响 | 缓解 | +|---|---|---| +| 源站API变更或失效 | 数据采集中断 | 多源冗余,健康监控告警 | +| 免费平台休眠/限流 | 服务不稳定 | 定时ping保活,优雅降级 | +| 影片去重误判 | 数据错乱 | 人工审核机制,可配置阈值 | +| 源站封禁采集IP | 无法同步 | 控制频率,多IP轮换(后期) | diff --git a/docs/02-feature-design.md b/docs/02-feature-design.md new file mode 100644 index 0000000000000000000000000000000000000000..28dcffade65057e0f048c3dfc4498c8759bc2f26 --- /dev/null +++ b/docs/02-feature-design.md @@ -0,0 +1,512 @@ +# D02 - 功能设计 + +## 模块总览 + +| 模块 | 说明 | 优先级 | +|---|---|---| +| M01 资源站管理 | 配置、启停、测试连通性 | P0 | +| M02 数据采集 | 从资源站拉取数据、解析、存储 | P0 | +| M03 影片管理 | 去重、合并、审核、推荐 | P0 | +| M04 分类管理 | 统一分类、各站分类映射 | P0 | +| M05 Admin鉴权 | 登录、JWT、RBAC(角色+权限) | P0 | +| M06 User鉴权 | 可选登录、注册、JWT | P2 | +| M07 统一API | 影片列表/详情/搜索/播放 | P0 | +| M08 同步任务 | 定时采集、手动触发、日志 | P1 | +| M09 缓存层 | 热门数据缓存 | P1 | +| M10 收藏与历史 | 用户收藏、播放历史 | P2 | +| M11 源站监控 | 健康检查、统计 | P3 | + +--- + +## M01 资源站管理 + +### 数据模型 + +```python +class SourceSite(Base): + __tablename__ = "source_site" + + id: int # PK, 自增 + name: str # 站点名称, 如"金鹰资源", Required, max_length=50 + code: str # 站点编码, 如"jinying", Required, unique, max_length=30, regex: ^[a-z][a-z0-9_]+$ + base_url: str # API基础地址, 如"https://jyzyapi.com/provide/vod/", Required, regex: ^https?://.+ + site_url: str # 官网地址, Optional + play_from_m3u8: str # M3U8来源标识, 如"jinyingm3u8", Optional, max_length=30 + play_from_yun: str # 云播来源标识, 如"jinyingyun", Optional, max_length=30 + parse_url: str # M3U8解析接口, 如"https://hd.iapijy.com/play?url=", Optional + is_active: bool # 是否启用, default=True + sync_interval: int # 同步间隔(分钟), default=60, min=10, max=1440 + last_sync_at: datetime # 最后同步时间, Optional + last_sync_status: str # 最后同步状态, enum: "success"|"failed"|"running", Optional + last_sync_count: int # 最后同步新增数量, default=0 + total_count: int # 该站资源总数, default=0 + sort_order: int # 排序权重, default=0, 越大越优先 + remark: str # 备注, Optional, max_length=200 + created_at: datetime # 创建时间, auto + updated_at: datetime # 更新时间, auto +``` + +### 功能点 + +- CRUD资源站配置 +- 测试连通性(调一次API看是否返回200 + code=1) +- 启用/禁用 +- 手动触发同步 + +--- + +## M02 数据采集 + +### 采集流程 + +``` +1. 读取启用的资源站列表 +2. 按sync_interval判断是否需要同步 +3. 调用源站API: {base_url}?ac=detail&h={间隔小时数} +4. 解析JSON响应,逐条处理 +5. 去重匹配:按 vod_name + vod_year 匹配本地库 +6. 新影片 → 创建vod + vod_source +7. 已有影片 → 更新vod_source(保留多源) +8. 记录同步日志 +``` + +### 数据模型 + +```python +class SyncLog(Base): + __tablename__ = "sync_log" + + id: int # PK + source_id: int # FK → source_site.id, Required + status: str # enum: "running"|"success"|"failed", Required + started_at: datetime # Required + finished_at: datetime # Optional + total_fetched: int # 从源站拉取总数, default=0 + new_count: int # 新增影片数, default=0 + update_count: int # 更新影片数, default=0 + fail_count: int # 失败数, default=0 + error_message: str # 错误信息, Optional + duration_seconds: int # 耗时秒数, Optional +``` + +--- + +## M03 影片管理 + +### 数据模型 + +```python +class Vod(Base): + __tablename__ = "vod" + + id: int # PK + name: str # 影片名称, Required, max_length=200 + sub_name: str # 副标题/别名, Optional, max_length=500 + en_name: str # 英文拼音, Optional, max_length=200 + category_id: int # FK → category.id, Required + cover: str # 封面图URL, Optional, max_length=500 + actor: str # 演员, 逗号分隔, Optional, max_length=2000 + director: str # 导演, Optional, max_length=200 + area: str # 地区, Optional, max_length=50 + lang: str # 语言, Optional, max_length=50 + year: str # 年份, Optional, max_length=10 + duration: str # 时长, Optional, max_length=20 + score: float # 评分, Optional, 0.0-10.0 + douban_id: int # 豆瓣ID, Optional + blurb: str # 简介, Optional + content: str # 详细介绍(HTML), Optional + remarks: str # 备注(如"第39集"), Optional, max_length=100 + is_end: bool # 是否完结, default=False + is_hidden: bool # 是否隐藏(管理端控制), default=False + is_recommended: bool # 是否推荐, default=False + view_count: int # 播放次数, default=0 + created_at: datetime # 创建时间, auto + updated_at: datetime # 更新时间, auto + + +class VodSource(Base): + __tablename__ = "vod_source" + + id: int # PK + vod_id: int # FK → vod.id, Required + source_id: int # FK → source_site.id, Required + source_vod_id: int # 源站影片ID, Required + play_from: str # 播放来源, 如"jinyingm3u8", Required, max_length=30 + play_url: str # 播放地址(原始), Required + parse_url: str # 解析后的播放URL, Optional + is_available: bool # 是否可用, default=True + last_check_at: datetime # 最后可用性检查时间, Optional + created_at: datetime # 创建时间, auto + updated_at: datetime # 更新时间, auto +``` + +### 去重策略 + +``` +优先级: +1. douban_id 匹配(最可靠) +2. name + year 匹配(次可靠) +3. name 模糊匹配 + 人工确认(兜底) + +合并规则: +- 多源同一影片 → vod表一条记录 + vod_source表多条记录 +- 字段取值优先级: 有值覆盖空值,多源取最先非空 +- 播放地址保留所有来源,按 source_site.sort_order 排序 +``` + +--- + +## M04 分类管理 + +### 数据模型 + +```python +class Category(Base): + __tablename__ = "category" + + id: int # PK + name: str # 分类名称, Required, max_length=30, 如"电影" + parent_id: int # 父分类ID, Optional, NULL=一级分类 + sort_order: int # 排序, default=0 + is_active: bool # 是否启用, default=True + created_at: datetime # auto + + +class CategoryMapping(Base): + __tablename__ = "category_mapping" + + id: int # PK + category_id: int # FK → category.id, Required + source_id: int # FK → source_site.id, Required + source_type_id: int # 源站分类ID, Required + source_type_name: str # 源站分类名称, Required, max_length=30 +``` + +### 统一分类体系 + +``` +电影 (1) + ├── 动作片 (2) + ├── 喜剧片 (3) + ├── 爱情片 (4) + ├── 科幻片 (5) + ├── 恐怖片 (6) + ├── 剧情片 (7) + ├── 战争片 (8) + └── 动画片 (9) +电视剧 (10) + ├── 国产剧 (11) + ├── 欧美剧 (12) + ├── 韩剧 (13) + ├── 日剧 (14) + ├── 港剧 (15) + ├── 台剧 (16) + └── 泰剧 (17) +动漫 (18) + ├── 国产动漫 (19) + ├── 日本动漫 (20) + └── 欧美动漫 (21) +综艺 (22) +短剧 (23) +体育赛事 (24) + ├── 足球 (25) + └── 篮球 (26) +纪录片 (27) +``` + +--- + +## M05 Admin鉴权 + +### 数据模型 + +```python +class Admin(Base): + __tablename__ = "admin" + + id: int # PK + username: str # 用户名, Required, unique, max_length=30, regex: ^[a-zA-Z][a-zA-Z0-9_]+$ + password_hash: str # bcrypt哈希, Required + nickname: str # 昵称, Optional, max_length=30 + avatar: str # 头像URL, Optional, max_length=500 + is_active: bool # 是否启用, default=True + last_login_at: datetime # 最后登录时间, Optional + created_at: datetime # auto + updated_at: datetime # auto + + +class Role(Base): + __tablename__ = "role" + + id: int # PK + name: str # 角色名称, Required, unique, max_length=30 + code: str # 角色编码, Required, unique, max_length=30, 如"super_admin" + description: str # 角色描述, Optional, max_length=200 + is_builtin: bool # 是否内置角色(不可删除), default=False + status: int # 状态, default=1, 1=启用 0=禁用 + created_at: datetime # auto + updated_at: datetime # auto + + +class AdminRole(Base): + __tablename__ = "admin_role" + + id: int # PK + admin_id: int # FK → admin.id, Required, unique_with: role_id + role_id: int # FK → role.id, Required + + +class Permission(Base): + __tablename__ = "permission" + + id: int # PK + code: str # 权限码, Required, unique, max_length=60, 如"source:btn:sync" + name: str # 权限名称, Required, max_length=50, 如"同步" + type: str # enum: "menu"|"page"|"btn", Required + parent_id: int # 父权限ID, Optional, NULL=顶级 + path: str # 路由路径(仅menu类型), Optional, max_length=200, 如"/source" + component: str # 前端组件路径(仅menu类型), Optional, max_length=200, 如"/source/index" + redirect: str # 重定向路径(仅menu类型), Optional, max_length=200 + icon: str # 菜单图标(仅menu类型), Optional, max_length=50, 如"lucide:database" + sort_order: int # 排序, default=0 + status: int # 状态, default=1, 1=启用 0=禁用 + created_at: datetime # auto + + +class RolePermission(Base): + __tablename__ = "role_permission" + + id: int # PK + role_id: int # FK → role.id, Required, unique_with: permission_id + permission_id: int # FK → permission.id, Required +``` + +### 角色与权限矩阵 + +内置4个角色: + +| 角色 | code | 说明 | +|---|---|---| +| 超级管理员 | super_admin | 全部权限,含角色管理 | +| 管理员 | admin | 除角色管理外的所有权限 | +| 编辑 | editor | 内容管理,不能动系统配置 | +| 查看者 | viewer | 只读 | + +权限码体系(三段式: 模块:操作 / 模块:btn:操作): + +``` +# menu类型 - 对应左侧菜单项,携带路由信息,用于Vben Admin后端路由模式 +source:menu # 资源站管理菜单, path=/source, component=/source/index +vod:menu # 影片管理菜单, path=/vod, component=/vod/index +category:menu # 分类管理菜单, path=/category, component=/category/index +user:menu # 用户管理菜单, path=/user, component=/user/index +admin:menu # 管理员管理菜单, path=/admin, component=/admin/index +role:menu # 角色管理菜单, path=/role, component=/role/index +sync:menu # 同步管理菜单, path=/sync, component=/sync/index +system:menu # 系统配置菜单, path=/system, component=/system/index + +# page类型 - 页面级访问控制(对应子页面/Tab页) +source:list / source:detail / source:create / source:update +vod:list / vod:detail / vod:create / vod:update +category:list / category:update +user:list / user:detail +admin:list / admin:create / admin:update / admin:delete +role:list / role:create / role:update / role:delete +sync:list +system:config + +# btn类型 - 按钮级控制(Vben Admin通过权限码控制按钮显示/隐藏) +source:btn:sync / source:btn:enable / source:btn:delete / source:btn:test +vod:btn:hide / vod:btn:recommend / vod:btn:delete / vod:btn:audit +category:btn:map +user:btn:ban / user:btn:delete +admin:btn:assign_role / admin:btn:reset_pwd +role:btn:assign_perm +sync:btn:trigger / sync:btn:cancel +system:btn:save +``` + +### 鉴权机制 + +``` +Admin登录 → POST /admin/auth/login → 返回 { accessToken, userInfo } +前端调用 → GET /admin/auth/user-info → 返回 { roles, realName } (Vben Admin要求) +前端调用 → GET /admin/auth/codes → 返回扁平权限码string[] (Vben Admin按钮控制) +前端调用 → GET /admin/auth/menus → 返回菜单路由树 (Vben Admin后端路由模式) + +请求API → Authorization: Bearer {jwt} → 中间件解析 → 获取admin → 查角色 → 查权限 +路由级 → 整个/admin/前缀强制要求admin JWT +菜单级 → Vben Admin后端模式: API返回菜单树 → 动态生成路由 → router.addRoute +按钮级 → Vben Admin通过权限码: v-access:code="'source:btn:sync'" +接口级 → @require_permission("source:create") 装饰器二次校验 +``` + +--- + +## M06 User鉴权 + +### 数据模型 + +```python +class User(Base): + __tablename__ = "user" + + id: int # PK + username: str # 用户名, Optional, unique, max_length=30 + email: str # 邮箱, Optional, unique, max_length=100 + phone: str # 手机号, Optional, unique, max_length=20 + password_hash: str # bcrypt哈希, Required + nickname: str # 昵称, Optional, max_length=30 + avatar: str # 头像URL, Optional + is_active: bool # 是否启用, default=True + last_login_at: datetime # Optional + created_at: datetime # auto + updated_at: datetime # auto +``` + +### 鉴权机制 + +``` +/uesr/vod/* → 无需登录 +/user/auth/* → 注册/登录 +/user/favorite/* → 必须登录 +/user/history/* → 必须登录 + +登录方式: 用户名+密码 / 邮箱+密码 / 手机+验证码(后期) +注册方式: 用户名+密码 / 邮箱+密码 +``` + +--- + +## M07 统一API + +### Admin端点 + +``` +POST /admin/auth/login +POST /admin/auth/logout +GET /admin/auth/user-info +GET /admin/auth/codes +GET /admin/auth/menus +GET /admin/auth/permissions + +GET /admin/source +POST /admin/source +GET /admin/source/{id} +PUT /admin/source/{id} +DELETE /admin/source/{id} +POST /admin/source/{id}/test +POST /admin/source/{id}/sync +PUT /admin/source/{id}/enable + +GET /admin/vod +GET /admin/vod/{id} +PUT /admin/vod/{id} +DELETE /admin/vod/{id} +PUT /admin/vod/{id}/hide +PUT /admin/vod/{id}/recommend + +GET /admin/category +PUT /admin/category/{id} +PUT /admin/category/mapping + +GET /admin/user +GET /admin/user/{id} +PUT /admin/user/{id}/ban +DELETE /admin/user/{id} + +GET /admin/admin +POST /admin/admin +PUT /admin/admin/{id} +DELETE /admin/admin/{id} +PUT /admin/admin/{id}/reset-password +PUT /admin/admin/{id}/assign-roles + +GET /admin/role +POST /admin/role +PUT /admin/role/{id} +DELETE /admin/role/{id} +PUT /admin/role/{id}/permissions + +GET /admin/sync/log +POST /admin/sync/trigger + +GET /admin/system/config +PUT /admin/system/config +``` + +### User端点 + +``` +POST /user/auth/register +POST /user/auth/login +GET /user/auth/profile + +GET /user/vod # 列表(分页、分类筛选、排序) +GET /user/vod/search # 搜索 +GET /user/vod/{id} # 详情(含播放地址) +GET /user/vod/recommended # 推荐列表 +GET /user/vod/latest # 最新更新 + +GET /user/category # 分类列表 + +GET /user/favorite # 收藏列表(需登录) +POST /user/favorite # 添加收藏(需登录) +DELETE /user/favorite/{vod_id} # 取消收藏(需登录) + +GET /user/history # 播放历史(需登录) +POST /user/history # 记录播放(需登录) +DELETE /user/history/{id} # 删除历史(需登录) +``` + +--- + +## M10 收藏与历史 + +### 数据模型 + +```python +class Favorite(Base): + __tablename__ = "favorite" + + id: int # PK + user_id: int # FK → user.id, Required + vod_id: int # FK → vod.id, Required + created_at: datetime # auto + # unique_together: (user_id, vod_id) + + +class PlayHistory(Base): + __tablename__ = "play_history" + + id: int # PK + user_id: int # FK → user.id, Required + vod_id: int # FK → vod.id, Required + source_id: int # FK → source_site.id, Required + episode: str # 集名, Optional, max_length=50 + play_url: str # 播放地址, Required + progress: int # 播放进度(秒), default=0 + duration: int # 总时长(秒), default=0 + created_at: datetime # auto + updated_at: datetime # auto + # 同一用户同一影片同一集 → 更新progress +``` + +--- + +## M11 源站监控 + +### 数据模型 + +```python +class SourceHealth(Base): + __tablename__ = "source_health" + + id: int # PK + source_id: int # FK → source_site.id, Required + check_type: str # enum: "api"|"play", Required + is_success: bool # 是否成功, Required + response_time_ms: int # 响应时间(毫秒), Optional + error_message: str # 错误信息, Optional + checked_at: datetime # auto +``` diff --git a/docs/03-architecture.md b/docs/03-architecture.md new file mode 100644 index 0000000000000000000000000000000000000000..5209e2973e8560ace4a096cad2780c94f300e4ad --- /dev/null +++ b/docs/03-architecture.md @@ -0,0 +1,253 @@ +# D03 - 架构设计 + +## 技术栈 + +| 层 | 技术 | 说明 | +|---|---|---| +| Web框架 | FastAPI 0.115+ | 异步、自动Swagger、依赖注入 | +| ORM | SQLAlchemy 2.0+ | 异步模式 | +| 迁移 | Alembic 1.13+ | 数据库版本管理 | +| 数据库 | PostgreSQL 15+ | Neon免费tier | +| 缓存 | Redis 7+ (可选) | 热门数据缓存 | +| 定时任务 | APScheduler 3.10+ | 增量同步 | +| HTTP客户端 | httpx 0.27+ | 异步请求源站 | +| 鉴权 | python-jose + passlib | JWT + bcrypt | +| 校验 | Pydantic 2.0+ | 请求/响应模型 | + +## 目录结构 + +``` +api/ +├── app/ +│ ├── __init__.py +│ ├── main.py # FastAPI入口,挂载routers,启动事件 +│ ├── config.py # 配置管理(环境变量/默认值) +│ ├── database.py # DB连接、session管理 +│ │ +│ ├── models/ # SQLAlchemy ORM模型 +│ │ ├── __init__.py # 导出所有模型 +│ │ ├── source_site.py +│ │ ├── vod.py +│ │ ├── vod_source.py +│ │ ├── category.py +│ │ ├── category_mapping.py +│ │ ├── admin.py +│ │ ├── role.py +│ │ ├── permission.py +│ │ ├── user.py +│ │ ├── favorite.py +│ │ ├── play_history.py +│ │ ├── sync_log.py +│ │ └── source_health.py +│ │ +│ ├── schemas/ # Pydantic请求/响应模型 +│ │ ├── __init__.py +│ │ ├── admin/ +│ │ │ ├── auth.py # LoginRequest, LoginResponse, ProfileResponse +│ │ │ ├── source.py # SourceCreate, SourceUpdate, SourceResponse +│ │ │ ├── vod.py +│ │ │ ├── category.py +│ │ │ ├── user_mgmt.py +│ │ │ ├── admin_mgmt.py +│ │ │ ├── role_mgmt.py +│ │ │ ├── sync.py +│ │ │ └── system.py +│ │ └── user/ +│ │ ├── auth.py +│ │ ├── vod.py +│ │ ├── category.py +│ │ ├── favorite.py +│ │ └── history.py +│ │ +│ ├── routers/ # API路由 +│ │ ├── __init__.py +│ │ ├── admin/ +│ │ │ ├── __init__.py # 汇总子路由,统一prefix=/admin +│ │ │ ├── auth.py # /admin/auth/* +│ │ │ ├── source.py # /admin/source/* +│ │ │ ├── vod.py # /admin/vod/* +│ │ │ ├── category.py # /admin/category/* +│ │ │ ├── user_mgmt.py # /admin/user/* +│ │ │ ├── admin_mgmt.py # /admin/admin/* +│ │ │ ├── role_mgmt.py # /admin/role/* +│ │ │ ├── sync.py # /admin/sync/* +│ │ │ └── system.py # /admin/system/* +│ │ └── user/ +│ │ ├── __init__.py # 汇总子路由,统一prefix=/user +│ │ ├── auth.py # /user/auth/* +│ │ ├── vod.py # /user/vod/* +│ │ ├── category.py # /user/category/* +│ │ ├── favorite.py # /user/favorite/* +│ │ └── history.py # /user/history/* +│ │ +│ ├── services/ # 业务逻辑层 +│ │ ├── __init__.py +│ │ ├── collector.py # 采集引擎(调源站、解析、去重、存储) +│ │ ├── vod.py # 影片查询/去重/合并逻辑 +│ │ ├── category.py # 分类映射逻辑 +│ │ ├── auth_admin.py # Admin鉴权逻辑 +│ │ ├── auth_user.py # User鉴权逻辑 +│ │ ├── rbac.py # RBAC权限校验 +│ │ ├── sync.py # 同步任务调度 +│ │ └── health.py # 源站健康检查 +│ │ +│ ├── dependencies.py # FastAPI依赖注入 +│ │ # get_db, get_current_admin, get_current_user +│ │ # require_permission("source:create") +│ │ +│ ├── tasks/ # 定时任务 +│ │ ├── __init__.py +│ │ └── sync.py # APScheduler定时采集 +│ │ +│ └── utils/ # 工具函数 +│ ├── __init__.py +│ ├── dedup.py # 去重算法 +│ └── parse.py # 源站响应解析 +│ +├── alembic/ # 数据库迁移 +│ ├── env.py +│ └── versions/ +│ +├── scripts/ # 脚本 +│ ├── seed_permissions.py # 初始化权限数据(含menu/page/btn三级) +│ ├── seed_roles.py # 初始化角色数据(含code字段) +│ └── create_superadmin.py # 创建超级管理员 +│ +├── tests/ # 测试 +│ ├── conftest.py +│ ├── test_admin_auth.py +│ ├── test_user_auth.py +│ ├── test_collector.py +│ └── test_api.py +│ +├── docs/ # 项目文档 +├── requirements.txt +├── .env.example +├── .gitignore +└── README.md +``` + +## 分层架构 + +``` +请求流程: + +HTTP Request + │ + ▼ +FastAPI Router (routers/) ← 路由定义、参数校验 + │ + ▼ +Dependencies (dependencies.py) ← 鉴权、DB session注入 + │ + ▼ +Service (services/) ← 业务逻辑 + │ + ▼ +Model (models/) ← 数据访问 + │ + ▼ +PostgreSQL +``` + +## 数据流 + +### 采集数据流 + +``` +APScheduler (定时/手动) + │ + ▼ +SyncService + │ + ▼ 读取启用的source_site + │ + ▼ httpx并发请求各源站API + │ URL: {base_url}?ac=detail&h={hours} + │ + ▼ CollectorService.parse() + │ 解析JSON → 标准化数据 + │ + ▼ CollectorService.dedup() + │ 按 douban_id / name+year 去重匹配 + │ + ▼ 写入 vod + vod_source + │ + ▼ 写入 sync_log +``` + +### 查询数据流 + +``` +User/Admin Request + │ + ▼ Router + │ 参数校验 (Pydantic schema) + │ + ▼ Dependencies + │ 鉴权 (JWT → admin/user → 权限) + │ + ▼ Service + │ 业务逻辑 (查询/过滤/排序/缓存) + │ + ▼ Model → PostgreSQL + │ + ▼ Service → 组装响应 + │ + ▼ Pydantic Response Schema → JSON +``` + +## 关键设计决策 + +### 1. 为什么用SQLAlchemy而不是Tortoise/Prisma + +- SQLAlchemy 2.0异步模式成熟,Alembic迁移工具链完整 +- Tortoise ORM生态较小,复杂查询支持有限 +- Prisma (Python版) 尚不成熟 + +### 2. 为什么admin和user端点完全分离 + +- 鉴权机制完全不同(admin强制JWT,user可选) +- 返回字段不同(admin返回敏感信息,user不返回) +- 安全隔离(admin端可加IP白名单,user端公开) +- Swagger文档自动按/admin和/user分组 + +### 3. 为什么权限存数据库而不是硬编码 + +- 支持在admin后台动态分配 +- 支持新增角色和权限无需改代码 +- 支持按钮级权限粒度 + +### 4. 为什么采集用httpx而不是aiohttp + +- httpx API更现代,与requests兼容 +- 支持HTTP/2 +- 自动重试和超时控制更好 + +### 5. 为什么登录接口拆分为多个(login/user-info/codes/menus) + +适配 Vue Vben Admin 后端路由模式: +- `login` → 返回 accessToken(Vben Admin约定字段名) +- `user-info` → 返回 roles + realName(Vben Admin要求格式) +- `codes` → 返回扁平权限码 string[](按钮级控制,Vben Admin的 `v-access:code` 指令消费) +- `menus` → 返回菜单路由树(Vben Admin后端模式,动态 `router.addRoute`) +- `permissions` → 返回完整权限树(角色管理页面分配权限用) + +这种拆分让每个接口职责单一,前端可按需调用,且与 Vben Admin 的 `accessMode='backend'` 无缝对接。 + +## 部署架构 + +``` +[ Render / Railway ] [ Neon ] [ Redis Cloud (可选) ] +┌──────────────────┐ ┌──────────┐ ┌──────────┐ +│ FastAPI App │────────▶│PostgreSQL│───────▶│ Redis │ +│ + APScheduler │ │ 免费500MB│ │ 免费30MB │ +└──────────────────┘ └──────────┘ └──────────┘ + ▲ + │ HTTP + │ +┌────┴────┐ +│ admin/ │ 管理后台(独立项目) +│ web/ │ 用户前端(独立项目) +└─────────┘ +``` diff --git a/docs/04-api-design.md b/docs/04-api-design.md new file mode 100644 index 0000000000000000000000000000000000000000..bcf0b46856d9abbfeb2ff97a60552ef066eaf586 --- /dev/null +++ b/docs/04-api-design.md @@ -0,0 +1,1009 @@ +# D04 - API设计 + +## 通用规范 + +### 响应格式 + +```python +# 成功响应 +{ + "code": 0, + "msg": "success", + "data": { ... } +} + +# 列表响应 +{ + "code": 0, + "msg": "success", + "data": { + "list": [ ... ], + "total": 100, + "page": 1, + "page_size": 20 + } +} + +# 错误响应 +{ + "code": 40001, + "msg": "用户名或密码错误", + "data": null +} +``` + +### 错误码 + +| 范围 | 说明 | +|---|---| +| 0 | 成功 | +| 40001-40099 | 鉴权错误(登录失败、token过期、权限不足) | +| 40100-40199 | 参数校验错误 | +| 40200-40299 | 业务逻辑错误(资源站连接失败、去重冲突) | +| 50000-50099 | 服务器内部错误 | + +### 鉴权方式 + +| 端 | 方式 | Header | +|---|---|---| +| Admin | 强制JWT | `Authorization: Bearer {admin_jwt}` | +| User(公开) | 无需 | - | +| User(需登录) | JWT | `Authorization: Bearer {user_jwt}` | + +### 分页参数 + +| 参数 | 类型 | 默认 | 说明 | +|---|---|---|---| +| `page` | int | 1 | 页码 | +| `page_size` | int | 20 | 每页条数,max=100 | + +--- + +## Admin端点 + +### /admin/auth — 管理员鉴权 + +#### POST /admin/auth/login + +登录,获取accessToken(Vben Admin要求返回accessToken字段) + +``` +Request: + username: str # Required, max_length=30 + password: str # Required, min_length=6, max_length=50 + +Response: + accessToken: str # JWT, Vben Admin约定字段名 + expires_in: int # 有效期秒数 +``` + +#### POST /admin/auth/logout + +注销(可选:加入黑名单) + +``` +Request: 无(从JWT解析) +Response: { "code": 0, "msg": "success" } +``` + +#### GET /admin/auth/user-info + +获取当前管理员信息(Vben Admin的getUserInfo接口,要求返回roles和realName) + +``` +Response: + id: int + username: str + realName: str # Vben Admin约定字段, 映射nickname + roles: list[str] # Vben Admin约定字段, 如["super_admin"] + avatar: str | null +``` + +#### GET /admin/auth/codes + +获取当前管理员权限码(Vben Admin按钮级权限控制,返回扁平string[]) + +``` +Response: list[str] # ["source:list", "source:create", "source:btn:sync", ...] +``` + +#### GET /admin/auth/menus + +获取当前管理员的菜单路由树(Vben Admin后端路由模式,动态生成路由) + +``` +Response: list[MenuNode] + +MenuNode: + name: str # 路由名称, 如"SourceManage" + path: str # 路由路径, 如"/source" + component: str | null # 前端组件路径, 去掉views/和.vue, 如"/source/index" + redirect: str | null # 重定向路径 + meta: + title: str # 菜单标题, 如"资源站管理" + icon: str | null # 菜单图标, 如"lucide:database" + order: int # 排序 + hideInMenu: bool # 是否隐藏, default=false + keepAlive: bool # 是否缓存, default=false + children: list[MenuNode] | null +``` + +#### GET /admin/auth/permissions + +获取完整权限树(用于角色管理页面分配权限) + +``` +Response: + permissions: list[PermissionNode] + +PermissionNode: + id: int + code: str # "source" + name: str # "资源站管理" + type: str # "menu" | "page" | "btn" + children: list[PermissionNode] | null +``` + +--- + +### /admin/source — 资源站管理 + +#### GET /admin/source + +资源站列表 + +``` +Query: + is_active: bool | null # 可选,按启用状态筛选 + page: int + page_size: int + +Response: + list: list[SourceItem] + total: int + +SourceItem: + id: int + name: str + code: str + base_url: str + site_url: str | null + play_from_m3u8: str | null + play_from_yun: str | null + parse_url: str | null + is_active: bool + sync_interval: int + last_sync_at: str | null # ISO8601 + last_sync_status: str | null # "success"|"failed"|"running" + last_sync_count: int + total_count: int + sort_order: int + remark: str | null + created_at: str +``` + +#### POST /admin/source + +新增资源站 + +``` +Permission: source:create + +Request: + name: str # Required, max_length=50 + code: str # Required, max_length=30, regex: ^[a-z][a-z0-9_]+$ + base_url: str # Required, regex: ^https?://.+ + site_url: str | null + play_from_m3u8: str | null + play_from_yun: str | null + parse_url: str | null + sync_interval: int # default=60 + sort_order: int # default=0 + remark: str | null + +Response: SourceItem +``` + +#### GET /admin/source/{id} + +资源站详情 + +``` +Permission: source:detail +Response: SourceItem +``` + +#### PUT /admin/source/{id} + +更新资源站 + +``` +Permission: source:update +Request: 同POST,所有字段可选 +Response: SourceItem +``` + +#### DELETE /admin/source/{id} + +删除资源站 + +``` +Permission: source:btn:delete +Response: { "code": 0, "msg": "success" } +注意:删除资源站会级联删除该站的所有vod_source和category_mapping +``` + +#### POST /admin/source/{id}/test + +测试资源站连通性 + +``` +Permission: source:btn:test +Response: + is_success: bool + response_time_ms: int | null + total_count: int | null # 源站返回的资源总数 + error_message: str | null +``` + +#### POST /admin/source/{id}/sync + +手动触发同步 + +``` +Permission: source:btn:sync +Response: + task_id: str # 同步任务ID + status: str # "running" +``` + +#### PUT /admin/source/{id}/enable + +启用/禁用资源站 + +``` +Permission: source:btn:enable +Request: + is_active: bool + +Response: SourceItem +``` + +--- + +### /admin/vod — 影片管理 + +#### GET /admin/vod + +影片列表 + +``` +Permission: vod:list +Query: + keyword: str | null # 搜索关键词 + category_id: int | null # 分类筛选 + source_id: int | null # 按来源站筛选 + is_hidden: bool | null # 按隐藏状态筛选 + is_recommended: bool | null # 按推荐状态筛选 + is_end: bool | null # 按完结状态筛选 + year: str | null # 年份筛选 + area: str | null # 地区筛选 + sort: str # 排序字段, default="updated_at", enum: "updated_at"|"view_count"|"score"|"created_at" + order: str # "desc"|"asc", default="desc" + page: int + page_size: int + +Response: + list: list[VodAdminItem] + total: int + +VodAdminItem: + id: int + name: str + sub_name: str | null + category_id: int + category_name: str + cover: str | null + actor: str | null + director: str | null + area: str | null + lang: str | null + year: str | null + score: float | null + remarks: str | null + is_end: bool + is_hidden: bool + is_recommended: bool + view_count: int + source_count: int # 多少个来源 + sources: list[VodSourceItem] # 来源列表 + created_at: str + updated_at: str +``` + +#### GET /admin/vod/{id} + +影片详情 + +``` +Permission: vod:detail +Response: VodAdminItem (含content字段和完整sources) +``` + +#### PUT /admin/vod/{id} + +更新影片 + +``` +Permission: vod:update +Request: + category_id: int | null + is_hidden: bool | null + is_recommended: bool | null + cover: str | null + score: float | null + +Response: VodAdminItem +``` + +#### DELETE /admin/vod/{id} + +删除影片 + +``` +Permission: vod:btn:delete +注意:级联删除所有vod_source +``` + +#### PUT /admin/vod/{id}/hide + +隐藏/显示影片 + +``` +Permission: vod:btn:hide +Request: { "is_hidden": bool } +Response: VodAdminItem +``` + +#### PUT /admin/vod/{id}/recommend + +推荐/取消推荐 + +``` +Permission: vod:btn:recommend +Request: { "is_recommended": bool } +Response: VodAdminItem +``` + +--- + +### /admin/category — 分类管理 + +#### GET /admin/category + +分类列表(树形) + +``` +Permission: category:list +Response: list[CategoryNode] + +CategoryNode: + id: int + name: str + parent_id: int | null + sort_order: int + is_active: bool + children: list[CategoryNode] | null + mappings: list[CategoryMappingItem] | null + +CategoryMappingItem: + source_id: int + source_name: str + source_type_id: int + source_type_name: str +``` + +#### PUT /admin/category/{id} + +更新分类 + +``` +Permission: category:update +Request: + name: str | null + sort_order: int | null + is_active: bool | null +``` + +#### PUT /admin/category/mapping + +批量更新分类映射 + +``` +Permission: category:btn:map +Request: + mappings: list[ + category_id: int + source_id: int + source_type_id: int + source_type_name: str + ] +``` + +--- + +### /admin/user — 用户管理 + +#### GET /admin/user + +用户列表 + +``` +Permission: user:list +Query: + keyword: str | null + is_active: bool | null + page: int + page_size: int + +Response: + list: list[UserMgmtItem] + total: int + +UserMgmtItem: + id: int + username: str | null + email: str | null + phone: str | null + nickname: str | null + is_active: bool + favorite_count: int + history_count: int + last_login_at: str | null + created_at: str +``` + +#### GET /admin/user/{id} + +用户详情 + +``` +Permission: user:detail +Response: UserMgmtItem +``` + +#### PUT /admin/user/{id}/ban + +封禁/解封用户 + +``` +Permission: user:btn:ban +Request: { "is_active": bool } +``` + +#### DELETE /admin/user/{id} + +删除用户 + +``` +Permission: user:btn:delete +``` + +--- + +### /admin/admin — 管理员管理 + +#### GET /admin/admin + +管理员列表 + +``` +Permission: admin:list +Response: + list: list[AdminMgmtItem] + total: int + +AdminMgmtItem: + id: int + username: str + nickname: str | null + avatar: str | null + is_active: bool + roles: list[RoleItem] + last_login_at: str | null + created_at: str + +RoleItem: + id: int + name: str + code: str # "super_admin" +``` + +#### POST /admin/admin + +新增管理员 + +``` +Permission: admin:create +Request: + username: str # Required + password: str # Required, min_length=6 + nickname: str | null + role_ids: list[int] # Required +``` + +#### PUT /admin/admin/{id} + +更新管理员 + +``` +Permission: admin:update +Request: + nickname: str | null + is_active: bool | null +``` + +#### DELETE /admin/admin/{id} + +删除管理员 + +``` +Permission: admin:delete +注意:不能删除自己 +``` + +#### PUT /admin/admin/{id}/reset-password + +重置密码 + +``` +Permission: admin:btn:reset_pwd +Request: + new_password: str # Required, min_length=6 +``` + +#### PUT /admin/admin/{id}/assign-roles + +分配角色 + +``` +Permission: admin:btn:assign_role +Request: + role_ids: list[int] # Required,完整替换 +``` + +--- + +### /admin/role — 角色管理 + +#### GET /admin/role + +角色列表 + +``` +Permission: role:list +Response: list[RoleDetailItem] + +RoleDetailItem: + id: int + name: str + code: str + description: str | null + is_builtin: bool + status: int # 1=启用 0=禁用 + permissions: list[PermissionItem] + admin_count: int # 拥有此角色的管理员数 + created_at: str + +PermissionItem: + id: int + code: str + name: str + type: str # "menu" | "page" | "btn" +``` + +#### POST /admin/role + +新增角色 + +``` +Permission: role:create +Request: + name: str # Required, unique + code: str # Required, unique, 如"editor" + description: str | null + permission_ids: list[int] # Required +``` + +#### PUT /admin/role/{id} + +更新角色 + +``` +Permission: role:update +Request: + name: str | null + description: str | null + status: int | null # 1=启用 0=禁用 +``` + +#### DELETE /admin/role/{id} + +删除角色 + +``` +Permission: role:delete +注意:内置角色不可删除(is_builtin=True) +``` + +#### PUT /admin/role/{id}/permissions + +分配权限 + +``` +Permission: role:btn:assign_perm +Request: + permission_ids: list[int] # Required,完整替换 +``` + +--- + +### /admin/sync — 同步管理 + +#### GET /admin/sync/log + +同步日志 + +``` +Permission: sync:list +Query: + source_id: int | null + status: str | null # "success"|"failed"|"running" + page: int + page_size: int + +Response: + list: list[SyncLogItem] + total: int + +SyncLogItem: + id: int + source_id: int + source_name: str + status: str + started_at: str + finished_at: str | null + total_fetched: int + new_count: int + update_count: int + fail_count: int + error_message: str | null + duration_seconds: int | null +``` + +#### POST /admin/sync/trigger + +触发全量同步 + +``` +Permission: sync:btn:trigger +Request: + source_id: int | null # null=同步所有启用的站点 + full: bool # default=false, true=忽略h参数全量拉取 + +Response: + task_ids: list[str] +``` + +--- + +### /admin/system — 系统配置 + +#### GET /admin/system/config + +获取系统配置 + +``` +Permission: system:config +Response: + site_name: str + site_description: str | null + sync_cron: str # APScheduler cron表达式 + max_sync_concurrent: int # 最大并发采集数 + cache_ttl: int # 缓存过期时间(秒) + user_register_enabled: bool # 是否开放用户注册 +``` + +#### PUT /admin/system/config + +更新系统配置 + +``` +Permission: system:btn:save +Request: 同Response字段,全部可选 +``` + +--- + +## User端点 + +### /user/auth — 用户鉴权 + +#### POST /user/auth/register + +注册 + +``` +Request: + username: str # Required, max_length=30, regex: ^[a-zA-Z][a-zA-Z0-9_]+$ + password: str # Required, min_length=6, max_length=50 + email: str | null # Optional + +Response: + token: str + expires_in: int + user: + id: int + username: str + nickname: str | null + avatar: str | null +``` + +#### POST /user/auth/login + +登录 + +``` +Request: + username: str # 用户名/邮箱 + password: str + +Response: 同register +``` + +#### GET /user/auth/profile + +获取当前用户信息 + +``` +需登录 +Response: + id: int + username: str + email: str | null + nickname: str | null + avatar: str | null + favorite_count: int + created_at: str +``` + +--- + +### /user/vod — 影片浏览 + +#### GET /user/vod + +影片列表 + +``` +无需登录 +Query: + category_id: int | null + area: str | null + lang: str | null + year: str | null + sort: str # "updated_at"|"view_count"|"score"|"created_at", default="updated_at" + order: str # "desc"|"asc", default="desc" + page: int + page_size: int + +Response: + list: list[VodUserItem] + total: int + +VodUserItem: + id: int + name: str + sub_name: str | null + category_id: int + category_name: str + cover: str | null + actor: str | null + director: str | null + area: str | null + lang: str | null + year: str | null + score: float | null + remarks: str | null + is_end: bool + source_count: int + updated_at: str +``` + +#### GET /user/vod/search + +搜索影片 + +``` +无需登录 +Query: + keyword: str # Required, min_length=1 + category_id: int | null + page: int + page_size: int + +Response: 同/user/vod +``` + +#### GET /user/vod/{id} + +影片详情(含播放地址) + +``` +无需登录 +Response: VodUserDetailItem + +VodUserDetailItem: + id: int + name: str + sub_name: str | null + category_id: int + category_name: str + cover: str | null + actor: str | null + director: str | null + area: str | null + lang: str | null + year: str | null + duration: str | null + score: float | null + blurb: str | null + content: str | null + remarks: str | null + is_end: bool + view_count: int + updated_at: str + + sources: list[VodPlaySource] # 播放来源列表 + +VodPlaySource: + source_id: int + source_name: str # "金鹰资源" + source_code: str # "jinying" + play_from: str # "jinyingm3u8" + play_from_label: str # "金鹰M3U8" + episodes: list[EpisodeItem] + +EpisodeItem: + name: str # "第01集" + url: str # m3u8直链或云播短链 + parse_url: str | null # 解析接口URL(拼接后可直接iframe) +``` + +#### GET /user/vod/recommended + +推荐影片 + +``` +无需登录 +Query: page, page_size +Response: 同/user/vod +``` + +#### GET /user/vod/latest + +最新更新 + +``` +无需登录 +Query: hours: int # 最近N小时内, default=24, max=168 + page: int + page_size: int +Response: 同/user/vod +``` + +--- + +### /user/category — 分类 + +#### GET /user/category + +分类列表(树形) + +``` +无需登录 +Response: list[CategoryUserNode] + +CategoryUserNode: + id: int + name: str + children: list[CategoryUserNode] | null +``` + +--- + +### /user/favorite — 收藏 + +#### GET /user/favorite + +收藏列表 + +``` +需登录 +Query: page, page_size +Response: + list: list[VodUserItem] + total: int +``` + +#### POST /user/favorite + +添加收藏 + +``` +需登录 +Request: + vod_id: int # Required +Response: { "code": 0, "msg": "success" } +``` + +#### DELETE /user/favorite/{vod_id} + +取消收藏 + +``` +需登录 +Response: { "code": 0, "msg": "success" } +``` + +--- + +### /user/history — 播放历史 + +#### GET /user/history + +播放历史 + +``` +需登录 +Query: page, page_size +Response: + list: list[HistoryItem] + total: int + +HistoryItem: + id: int + vod_id: int + vod_name: str + vod_cover: str | null + source_name: str + episode: str | null + progress: int # 播放进度(秒) + duration: int # 总时长(秒) + updated_at: str +``` + +#### POST /user/history + +记录/更新播放历史 + +``` +需登录 +Request: + vod_id: int # Required + source_id: int # Required + episode: str | null + play_url: str # Required + progress: int # default=0 + duration: int # default=0 +Response: { "code": 0, "msg": "success" } +``` + +#### DELETE /user/history/{id} + +删除历史 + +``` +需登录 +Response: { "code": 0, "msg": "success" } +``` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..3fcb04140b516924a27dc7b54478ff899696a9c5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +fastapi==0.115.* +uvicorn[standard]==0.34.* +sqlalchemy[asyncio]==2.0.* +asyncpg==0.30.* +alembic==1.14.* +pydantic==2.10.* +pydantic-settings==2.7.* +python-jose[cryptography]==3.3.* +passlib[bcrypt]==1.7.* +httpx==0.28.* +apscheduler==3.11.* +python-multipart==0.0.* diff --git a/scripts/create_superadmin.py b/scripts/create_superadmin.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scripts/seed_permissions.py b/scripts/seed_permissions.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/scripts/seed_roles.py b/scripts/seed_roles.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/test_admin_auth.py b/tests/test_admin_auth.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/test_collector.py b/tests/test_collector.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/test_user_auth.py b/tests/test_user_auth.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391