2022-11-03 01:56:19 +08:00
|
|
|
from pydantic import (
|
|
|
|
StrictBool,
|
|
|
|
StrictInt,
|
|
|
|
StrictStr,
|
|
|
|
constr,
|
|
|
|
validator,
|
|
|
|
)
|
2022-02-04 06:21:27 +08:00
|
|
|
|
|
|
|
from yt_shared.schemas.base import RealBaseModel
|
|
|
|
|
2022-06-11 04:35:48 +08:00
|
|
|
_LANG_CODE_LEN = 2
|
2022-10-14 03:55:18 +08:00
|
|
|
_LANG_CODE_REGEX = rf'^[a-z]{{{_LANG_CODE_LEN}}}$'
|
2022-06-11 04:35:48 +08:00
|
|
|
|
2022-02-04 06:21:27 +08:00
|
|
|
|
2022-11-03 01:56:19 +08:00
|
|
|
class BaseUserSchema(RealBaseModel):
|
|
|
|
id: StrictInt
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_base_user(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class UserUploadSchema(RealBaseModel):
|
|
|
|
upload_vide_file: StrictBool
|
|
|
|
upload_video_max_file_size: StrictInt
|
|
|
|
forward_to_group: StrictBool
|
|
|
|
forward_group_id: StrictInt | None
|
|
|
|
silent: StrictBool
|
|
|
|
|
|
|
|
|
|
|
|
class UserSchema(BaseUserSchema):
|
|
|
|
upload: UserUploadSchema
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_base_user(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def change_type(values: list[int]) -> list[BaseUserSchema]:
|
|
|
|
return [BaseUserSchema(id=id_) for id_ in values]
|
|
|
|
|
|
|
|
|
|
|
|
class ApiSchema(RealBaseModel):
|
|
|
|
upload_vide_file: StrictBool
|
|
|
|
upload_video_max_file_size: StrictInt
|
|
|
|
upload_to_chat_ids: list[BaseUserSchema]
|
|
|
|
silent: StrictBool
|
|
|
|
|
|
|
|
_transform_chat_ids = validator('upload_to_chat_ids', pre=True)(change_type)
|
|
|
|
|
|
|
|
|
2022-02-04 06:21:27 +08:00
|
|
|
class TelegramSchema(RealBaseModel):
|
2022-06-11 04:35:48 +08:00
|
|
|
api_id: StrictInt
|
|
|
|
api_hash: StrictStr
|
2022-02-04 06:21:27 +08:00
|
|
|
token: StrictStr
|
2022-06-11 04:35:48 +08:00
|
|
|
lang_code: constr(regex=_LANG_CODE_REGEX, to_lower=True)
|
2022-11-03 01:56:19 +08:00
|
|
|
allowed_users: list[UserSchema]
|
|
|
|
api: ApiSchema
|
2022-02-04 06:21:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ConfigSchema(RealBaseModel):
|
|
|
|
telegram: TelegramSchema
|
2022-11-03 01:56:19 +08:00
|
|
|
ytdlp_version_check_interval: StrictInt
|