- 搭建 FastAPI、Redis、PostgreSQL、Nginx 与 Docker Compose 基础结构 - 实现反向代理、首用绑定、拦截告警、归档任务和管理接口 - 提供 Vue3 管理后台初版,以及 uv/requirements 双依赖配置
43 lines
903 B
Python
43 lines
903 B
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
|
|
|
|
class BindingItem(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
token_display: str
|
|
bound_ip: str
|
|
status: int
|
|
status_label: str
|
|
first_used_at: datetime
|
|
last_used_at: datetime
|
|
created_at: datetime
|
|
|
|
|
|
class BindingListResponse(BaseModel):
|
|
items: list[BindingItem]
|
|
total: int
|
|
page: int
|
|
page_size: int
|
|
|
|
|
|
class BindingActionRequest(BaseModel):
|
|
id: int = Field(gt=0)
|
|
|
|
|
|
class BindingIPUpdateRequest(BaseModel):
|
|
id: int = Field(gt=0)
|
|
bound_ip: str = Field(min_length=3, max_length=64)
|
|
|
|
@field_validator("bound_ip")
|
|
@classmethod
|
|
def validate_bound_ip(cls, value: str) -> str:
|
|
from ipaddress import ip_network
|
|
|
|
ip_network(value, strict=False)
|
|
return value
|