feat(base): 优化环境变量配置

This commit is contained in:
xingc
2025-02-22 11:35:19 +08:00
parent e35e97402f
commit 02ddc81c51
6 changed files with 60 additions and 18 deletions

View File

@@ -5,7 +5,7 @@
# @Author : xingc
# @Desc :
import logging
import os
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -15,7 +15,7 @@ class Settings(BaseSettings):
NAME: str = 'card book'
PREFIX: str = NAME.lower().replace(' ', '_')
ENVIRONMENT: str = 'dev'
BASE_DIR: str = os.path.dirname(os.path.abspath(__file__))
BASE_DIR: Path = Path(__file__).resolve().parent
DEBUG: bool = True
# 应用配置
@@ -40,30 +40,30 @@ class Settings(BaseSettings):
REDIS_HOST: str
REDIS_PORT: int = 6379
REDIS_DB: int = 0
REDIS_CACHE_EXPIRATION_SECONDS: int = 60 * 30 * 1
REDIS_CACHE_EXPIRATION_SECONDS: int = 60 * 5 * 1
# 身份认证
ACCESS_SECRET_KEY: str = 'a2f718e8313bf8efcb45ef7364d040c45800f34d10f65776eef0f6584677ecd0'
REFRESH_SECRET_KEY: str = 'bb0cbf245de98c09c42c928326f6e07a44d91bc5a81787b37b4eb33428915fa7'
ALGORITHM: str = 'HS256'
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7
# 文件上传配置
UPLOADED_FILES_DIR: str = os.path.join(BASE_DIR, 'uploads')
UPLOADED_FILES_DIR: Path = BASE_DIR / 'uploads'
UPLOADED_ALLOWED_MIME_TYPES: set = {
"image/jpeg",
"image/png"
}
UPLOADED_MAX_FILE_SIZE: int = 1024 * 1024 * 10 # 10MB
ASSETS_BASE_URL: str = 'http://127.0.0.1:8000'
# 代理
OVERSEAS_PROXY: str = 'http://127.0.0.1:7890'
# 微信
APPID: str = '<KEY>'
APP_SECRET: str = '<KEY>'
APPID: str = ''
APP_SECRET: str = ''
model_config = SettingsConfigDict(env_file=F'.env.{ENVIRONMENT.lower()}', env_file_encoding='utf-8')
model_config = SettingsConfigDict(env_file=f'.env.{ENVIRONMENT}', env_file_encoding='utf-8')
class ProductionSettings(Settings):
@@ -73,7 +73,6 @@ class ProductionSettings(Settings):
# 身份认证
ACCESS_SECRET_KEY: str = '1f790219840ccd10b5d8b33d7f595b7fe0eed262403689f6fa1cab80149b00f2'
REFRESH_SECRET_KEY: str = 'fb57c85dc4e0256024ae809bc3200adc7b7de222b348da6df35d58e27338e3b8'
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 1 # 1days
@@ -95,6 +94,7 @@ class DevelopmentSettings(Settings):
def get_settings():
import os
env = os.environ.get('ENVIRONMENT', 'dev')
if env == 'dev':
return DevelopmentSettings()