Files
life-echo/api/app/core/config.py
Sully 105b50a277 merge dark mode and google OAuth (#35)
* feat(api): implement Google OAuth login and user management

- Added Google OpenID Connect login functionality, allowing users to authenticate using their Google accounts.
- Created new endpoints for Google login, including user registration and linking existing accounts.
- Introduced Google token verification logic and error handling for authentication failures.
- Updated environment configuration to include Google OAuth client IDs and verification settings.
- Enhanced user model to support OpenID and linked Google accounts.

This feature improves user experience by enabling seamless sign-in with Google, while maintaining security and integrity of user data.

* fix(auth): wire staging Google token verifier

* chore(deps): update expo to version 55.0.6 and adjust @expo/env dependency in pnpm-lock.yaml

* chore(deps): update Babel dependencies to version 7.29.7 in package-lock.json

* feat(auth): enhance phone login for China users

- Updated phone login functionality to support only mainland China (+86) mobile numbers.
- Added user prompts and descriptions for phone login, including confirmation and cancellation options.
- Adjusted translations for both English and Chinese to reflect the new phone login requirements.
- Updated Google OAuth client IDs in configuration files for production and staging environments.

* chore(deps): add peer flag to use-sync-external-store in package-lock.json

* chore(deps): add @emnapi/core and @emnapi/runtime to package-lock.json

* fix(app-expo): align Android native dependencies

* fix(app-expo): normalize lockfile for npm 10

* fix(config): update environment variable handling to use static access

- Introduced a static mapping for public environment variables to ensure proper access during the release bundle.
- Updated the `requirePublicEnv` and `optionalPublicEnv` functions to reference the new `PUBLIC_ENV` object instead of directly accessing `process.env`.
- Added comments to clarify the necessity of static access for certain environment variables.

* feat(app-expo): dark mode, FAQ i18n, eval ASR, and theme cleanup (#34)

* feat(app-expo): dark mode, FAQ i18n, version CI, and theme cleanup

Implement light/dark scene colors across chat, reading, and headers; remove
default/brand theme picker and ThemeVariablesProvider. Localize FAQ in-app,
fix dark-mode text visibility, and remove the unused /api/faqs endpoint.
Align About/version with Expo config and inject APP_VERSION in CI builds.

Also includes phone E164 auth/SMS updates, eval ASR page, and related API work.

* revert: remove phone E.164 changes from dark-mode branch

These auth/SMS internationalization updates were accidentally bundled into
the dark-mode commit; restore 11-digit CN phone flow and drop related API,
migration, and Expo UI work from this branch.

* fix: address PR review issues for dark mode and eval ASR

Use light foreground colors for sepia reading in dark mode, fix chat send
button contrast, stream-limit eval ASR uploads, restore LiveTester phone
validation, and remove unused AudioSegmenter code.

* fix(app-expo): improve chat send button contrast in light and dark mode

Add dedicated send button colors (accent fill in dark, primary fill in
light), use RNText to avoid NativeWind overrides, and restore dark labels
in light mode for readable composer actions.

---------

Co-authored-by: Kevin <kevin@brighteng.org>

---------

Co-authored-by: penghanyuan <penghanyuan@gmail.com>
Co-authored-by: Kevin <kevin@brighteng.org>
2026-06-09 11:14:36 +08:00

141 lines
4.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
统一配置:密钥与连接串经 .env / Settings其余非密钥项见 config/*.tomlAppConfig
本地开发时由 api/development.sh 在启动前将 .env.development 同步为 .env。
"""
from __future__ import annotations
from pydantic import AliasChoices, Field, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from app.core.app_config_models import DeployConfig
from app.core.redis_urls import resolve_redis_urls
_DEV_SECRET_KEY = "dev-only-secret-key-do-not-use-in-production"
_DEPLOY_FIELD_NAMES = frozenset(DeployConfig.model_fields.keys())
class Settings(BaseSettings):
"""Secrets and bootstrap only — non-secret deploy/product config lives in TOML."""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
extra="ignore",
)
database_url: str = "postgresql://postgres:postgres@localhost:48291/life_echo"
redis_url: str = "redis://localhost:48307/0"
redis_password: str = ""
celery_redis_url: str = ""
app_environment: str = Field(
default="development",
validation_alias=AliasChoices("APP_ENV", "APP_ENVIRONMENT"),
)
secret_key: str = _DEV_SECRET_KEY
deepseek_api_key: str = ""
zhipu_api_key: str = ""
tencent_secret_id: str = ""
tencent_secret_key: str = ""
tencent_app_id: str = ""
wechat_pay_api_v3_key: str = ""
wechat_pay_private_key: str = ""
wechat_pay_platform_public_key: str = ""
alipay_private_key: str = ""
alipay_public_key: str = ""
liblib_access_key: str = ""
liblib_secret_key: str = ""
internal_eval_api_key: str = ""
google_token_verifier_secret: str = ""
@model_validator(mode="after")
def _validate_secret_key(self) -> "Settings":
env = (self.app_environment or "").strip().lower()
if env in ("production", "staging") and (
not self.secret_key or self.secret_key == _DEV_SECRET_KEY
):
raise ValueError(
"SECRET_KEY must be set to a strong random value in production/staging"
)
return self
@property
def is_production(self) -> bool:
return (self.app_environment or "").strip().lower() == "production"
@property
def enable_test_subscription(self) -> bool:
return not self.is_production
@property
def enable_test_plan(self) -> bool:
return not self.is_production
@property
def redis_url_resolved(self) -> str:
business, _ = resolve_redis_urls(
self.redis_url,
redis_password=self.redis_password or None,
celery_redis_url_override=None,
)
return business
@property
def celery_redis_url_resolved(self) -> str:
override = (self.celery_redis_url or "").strip() or None
_, celery = resolve_redis_urls(
self.redis_url,
redis_password=self.redis_password or None,
celery_redis_url_override=override,
)
return celery
class SettingsFacade:
"""Backward-compatible facade: secrets from Settings, deploy flags from TOML."""
__slots__ = ("_secrets",)
def __init__(self, secrets: Settings) -> None:
object.__setattr__(self, "_secrets", secrets)
@property
def _deploy(self) -> DeployConfig:
from app.core.app_config import get_app_config
return get_app_config().deploy
def __getattr__(self, name: str):
secrets = object.__getattribute__(self, "_secrets")
if hasattr(secrets, name):
return getattr(secrets, name)
if name in _DEPLOY_FIELD_NAMES:
return getattr(self._deploy, name)
raise AttributeError(f"Settings has no attribute {name!r}")
def __setattr__(self, name: str, value) -> None:
if name == "_secrets":
object.__setattr__(self, name, value)
return
secrets = object.__getattribute__(self, "_secrets")
if hasattr(type(secrets), name) and name not in _DEPLOY_FIELD_NAMES:
setattr(secrets, name, value)
return
if name in _DEPLOY_FIELD_NAMES:
setattr(self._deploy, name, value)
return
setattr(secrets, name, value)
settings = SettingsFacade(Settings())