mirror of
https://github.com/Gozargah/Marzban.git
synced 2026-05-17 00:25:53 +03:00
* chore: update pydantic to version 2.10.2 and refactor model validators * refactor: simplify field validators by removing unnecessary pre and always flags * remove typing_extensions==4.9.0 from requirements.txt * refactor: remove allow_reuse flag from status field validator * refactor: simplify field validators by removing pre and always flags * refactor: update user model imports and enhance account class with abstract method * refactor: update model_config to use dictionary format in Admin and SubscriptionUserResponse classes * fix typo in UserDataResetByNext * change pre=True to mode="before" * refactor: update validation methods and model configuration in User and Proxy classes * change pre=False with mode="after" * Migrated to Pydantic V2 * fix: custom subscriptions not workong * some small changes * add missing properties to example schema * replace from_orm with model_validate --------- Co-authored-by: MahdiButcher <madibutchercoding@gmail.com> Co-authored-by: Mahdi Butcher <MahdiButcherCoding@gmail.com>
77 lines
1.8 KiB
Python
77 lines
1.8 KiB
Python
from enum import Enum
|
|
from typing import List, Optional
|
|
|
|
from pydantic import ConfigDict, BaseModel, Field
|
|
|
|
|
|
class NodeStatus(str, Enum):
|
|
connected = "connected"
|
|
connecting = "connecting"
|
|
error = "error"
|
|
disabled = "disabled"
|
|
|
|
|
|
class NodeSettings(BaseModel):
|
|
min_node_version: str = "v0.2.0"
|
|
certificate: str
|
|
|
|
|
|
class Node(BaseModel):
|
|
name: str
|
|
address: str
|
|
port: int = 62050
|
|
api_port: int = 62051
|
|
usage_coefficient: float = Field(gt=0, default=1.0)
|
|
|
|
|
|
class NodeCreate(Node):
|
|
add_as_new_host: bool = True
|
|
model_config = ConfigDict(json_schema_extra={
|
|
"example": {
|
|
"name": "DE node",
|
|
"address": "192.168.1.1",
|
|
"port": 62050,
|
|
"api_port": 62051,
|
|
"add_as_new_host": True,
|
|
"usage_coefficient": 1
|
|
}
|
|
})
|
|
|
|
|
|
class NodeModify(Node):
|
|
name: Optional[str] = Field(None, nullable=True)
|
|
address: Optional[str] = Field(None, nullable=True)
|
|
port: Optional[int] = Field(None, nullable=True)
|
|
api_port: Optional[int] = Field(None, nullable=True)
|
|
status: Optional[NodeStatus] = Field(None, nullable=True)
|
|
usage_coefficient: Optional[float] = Field(None, nullable=True)
|
|
model_config = ConfigDict(json_schema_extra={
|
|
"example": {
|
|
"name": "DE node",
|
|
"address": "192.168.1.1",
|
|
"port": 62050,
|
|
"api_port": 62051,
|
|
"status": "disabled",
|
|
"usage_coefficient": 1.0
|
|
}
|
|
})
|
|
|
|
|
|
class NodeResponse(Node):
|
|
id: int
|
|
xray_version: Optional[str] = None
|
|
status: NodeStatus
|
|
message: Optional[str] = None
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class NodeUsageResponse(BaseModel):
|
|
node_id: Optional[int] = None
|
|
node_name: str
|
|
uplink: int
|
|
downlink: int
|
|
|
|
|
|
class NodesUsageResponse(BaseModel):
|
|
usages: List[NodeUsageResponse]
|