feat: 优化设置布局并支持管理端地址切换 (#130)
This commit is contained in:
@@ -11,6 +11,7 @@ from .settings_repository import SettingsRepository
|
||||
|
||||
CLIENT_ID_KEY = "admin.client_id"
|
||||
CLIENT_NAME_KEY = "admin.client_name"
|
||||
ADMIN_BASE_URL_KEY = "admin.base_url"
|
||||
|
||||
|
||||
def generate_client_device_id() -> str:
|
||||
@@ -56,8 +57,12 @@ class CurrentClientService:
|
||||
)
|
||||
return CurrentClientSettings(client_id, client_name)
|
||||
|
||||
def save(self, client_name: str) -> CurrentClientSettings:
|
||||
"""保存名称;设备号不存在时生成,存在时保持不变。"""
|
||||
def save(
|
||||
self,
|
||||
client_name: str,
|
||||
admin_base_url: Optional[str] = None,
|
||||
) -> CurrentClientSettings:
|
||||
"""原子保存身份;传入管理端地址时一并保存。"""
|
||||
|
||||
normalized_name = self._clean_text(client_name)
|
||||
if len(normalized_name) > 50:
|
||||
@@ -70,12 +75,13 @@ class CurrentClientService:
|
||||
if not client_id:
|
||||
raise ValueError("生成的设备号不能为空")
|
||||
|
||||
self._repository.set_many(
|
||||
{
|
||||
CLIENT_ID_KEY: client_id,
|
||||
CLIENT_NAME_KEY: normalized_name,
|
||||
}
|
||||
)
|
||||
values = {
|
||||
CLIENT_ID_KEY: client_id,
|
||||
CLIENT_NAME_KEY: normalized_name,
|
||||
}
|
||||
if admin_base_url is not None:
|
||||
values[ADMIN_BASE_URL_KEY] = self._clean_text(admin_base_url)
|
||||
self._repository.set_many(values)
|
||||
return CurrentClientSettings(client_id, normalized_name)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user