api_nonce.py 970 B

1234567891011121314151617181920212223
  1. """
  2. API Nonce防重放模型
  3. """
  4. from datetime import datetime
  5. from app.utils.timezone import beijing_now_naive
  6. from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text
  7. from app.database import Base
  8. class APINonce(Base):
  9. """API Nonce防重放表"""
  10. __tablename__ = "api_nonces"
  11. id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
  12. nonce = Column(String(64), unique=True, nullable=False, comment="随机字符串")
  13. endpoint = Column(String(255), nullable=False, comment="接口路径")
  14. session_id = Column(String(64), nullable=True, comment="会话ID")
  15. user_id = Column(Integer, nullable=True, comment="用户ID")
  16. expires_at = Column(DateTime, nullable=False, comment="过期时间")
  17. created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间")
  18. def __repr__(self):
  19. return f"<APINonce(id={self.id}, nonce='{self.nonce}', endpoint='{self.endpoint}')>"