Add admin official account connection UI and persistent session secrets

This commit is contained in:
Pigway
2026-10-04 00:20:43 +08:00
parent 5aa0e9f762
commit b76af5ada3
12 changed files with 400 additions and 12 deletions
+47
View File
@@ -20,6 +20,11 @@ from pigway_frame_flow.core.registry import DeviceRegistry
from pigway_frame_flow.display.service import DisplayService
from pigway_frame_flow.errors import ErrorCode as E
from pigway_frame_flow.errors import FlowError
from pigway_frame_flow.integrations.kokonna_official.connection import (
ConnectionState,
LoginRequest,
SelectRequest,
)
from pigway_frame_flow.models import (
Accepted,
Asset,
@@ -753,6 +758,48 @@ def create_app(settings=None, start_worker=True):
weather_provider=weather.config().provider,
)
def official_connection(device_id):
registry.get(device_id)
return registry.official[device_id]
@app.get(
"/api/v1/devices/{device_id}/official/connection",
response_model=ConnectionState,
tags=["Official"],
dependencies=[Depends(require("admin"))],
)
def connection_state(device_id: str, discover: bool = False):
return official_connection(device_id).state(discover)
@app.post(
"/api/v1/devices/{device_id}/official/connection",
response_model=ConnectionState,
tags=["Official"],
dependencies=[Depends(require("admin"))],
)
def connection_login(device_id: str, body: LoginRequest):
return official_connection(device_id).login(
body.username, body.password.get_secret_value()
)
@app.put(
"/api/v1/devices/{device_id}/official/connection",
response_model=ConnectionState,
tags=["Official"],
dependencies=[Depends(require("admin"))],
)
def connection_select(device_id: str, body: SelectRequest):
return official_connection(device_id).select(body.robot_id)
@app.delete(
"/api/v1/devices/{device_id}/official/connection",
response_model=ConnectionState,
tags=["Official"],
dependencies=[Depends(require("admin"))],
)
def connection_disconnect(device_id: str):
return official_connection(device_id).disconnect()
@app.get(
"/api/v1/devices/{device_id}/widgets",
response_model=__import__(