feat(api,userbot,frontend): rename session device from the web ui
This commit is contained in:
@@ -9,6 +9,7 @@ from pyrogram.errors import FloodWait, RPCError
|
||||
from pyrogram.types import User
|
||||
|
||||
from api.login import LoginError, login_manager
|
||||
from userbot import DEVICE_MODEL_LIMIT
|
||||
from utils.read import accounts
|
||||
from utils.read.models import AccountView
|
||||
|
||||
@@ -35,6 +36,10 @@ class PasswordRequest(BaseModel):
|
||||
password: str
|
||||
|
||||
|
||||
class DeviceModelRequest(BaseModel):
|
||||
device_model: str
|
||||
|
||||
|
||||
class LoginState(BaseModel):
|
||||
login_id: str
|
||||
stage: Literal["code", "qr", "password", "done"]
|
||||
@@ -121,6 +126,23 @@ async def cancel_login(login_id: str) -> None:
|
||||
await login_manager.cancel(login_id)
|
||||
|
||||
|
||||
@router.patch("/accounts/{account_id}/device")
|
||||
async def rename_device(
|
||||
account_id: int, body: DeviceModelRequest, pool: FromDishka[asyncpg.Pool]
|
||||
) -> AccountView:
|
||||
device_model = " ".join(body.device_model.split())
|
||||
if not device_model or len(device_model) > DEVICE_MODEL_LIMIT:
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
f"Имя устройства: от 1 до {DEVICE_MODEL_LIMIT} символов",
|
||||
)
|
||||
account = await accounts.set_device_model(pool, account_id, device_model)
|
||||
if account is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, "Аккаунт не найден")
|
||||
await accounts.notify_accounts_changed(pool)
|
||||
return account
|
||||
|
||||
|
||||
@router.delete("/accounts/{account_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def logout_account(account_id: int, pool: FromDishka[asyncpg.Pool]) -> None:
|
||||
if await accounts.deactivate_account(pool, account_id) is None:
|
||||
|
||||
Reference in New Issue
Block a user