Refactor backend configuration management and update environment settings

- Replace the `config.py` module with a new `settings.py` to streamline environment variable management, focusing on database, CORS, and TURN settings.
- Update references throughout the backend codebase to use the new `settings` module instead of the deprecated `config`.
- Modify the `.env.example` file to reflect the new configuration approach, indicating that model provider credentials should be maintained separately.
- Enhance the `AssistantConfig` model to clarify the source of runtime connection information, ensuring it is injected from model resources rather than relying on defaults from the environment.
- Introduce new user scripts for audio and video management in the Tampermonkey environment, enhancing WebRTC capabilities.
This commit is contained in:
Xin Wang
2026-07-09 21:40:29 +08:00
parent 195579c5b7
commit 35d24acf40
19 changed files with 106 additions and 139 deletions

View File

@@ -7,28 +7,28 @@ import hashlib
import hmac
import time
import config
import settings
STUN_URL = "stun:stun.l.google.com:19302"
def _turn_credentials() -> tuple[str, str] | None:
"""Return (username, credential) for TURN, or None when TURN is not configured."""
if not config.TURN_URLS:
if not settings.TURN_URLS:
return None
if config.TURN_SECRET:
expiry = int(time.time()) + config.TURN_CREDENTIAL_TTL
if settings.TURN_SECRET:
expiry = int(time.time()) + settings.TURN_CREDENTIAL_TTL
username = f"{expiry}:ai-video"
credential = base64.b64encode(
hmac.new(
config.TURN_SECRET.encode("utf-8"),
settings.TURN_SECRET.encode("utf-8"),
username.encode("utf-8"),
hashlib.sha1,
).digest()
).decode("utf-8")
return username, credential
if config.TURN_USERNAME and config.TURN_PASSWORD:
return config.TURN_USERNAME, config.TURN_PASSWORD
if settings.TURN_USERNAME and settings.TURN_PASSWORD:
return settings.TURN_USERNAME, settings.TURN_PASSWORD
return None
@@ -39,7 +39,7 @@ def client_ice_servers() -> list[dict]:
if not creds:
return servers
username, credential = creds
for url in config.TURN_URLS:
for url in settings.TURN_URLS:
servers.append({"urls": url, "username": username, "credential": credential})
return servers
@@ -53,7 +53,7 @@ def aiortc_ice_servers() -> list:
if not creds:
return servers
username, credential = creds
for url in config.TURN_URLS:
for url in settings.TURN_URLS:
servers.append(
RTCIceServer(urls=url, username=username, credential=credential)
)