mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-12 02:19:59 +08:00
将日志系统从 app/logger/ 移至 app/log/ 目录 将路由配置从 routers.py 重命名为 routes.py 将硬编码配置值移至 constants.py 中的默认常量 统一代码格式和导入排序 优化函数参数对齐方式
41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
"""
|
|
应用程序初始化模块
|
|
"""
|
|
from pathlib import Path
|
|
from typing import List
|
|
|
|
from app.log.logger import get_initialization_logger
|
|
|
|
logger = get_initialization_logger()
|
|
|
|
|
|
def ensure_directories_exist(directories: List[str]) -> None:
|
|
"""
|
|
确保指定的目录存在,如果不存在则创建
|
|
|
|
Args:
|
|
directories: 要确保存在的目录列表
|
|
"""
|
|
for directory in directories:
|
|
try:
|
|
Path(directory).mkdir(parents=True, exist_ok=True)
|
|
logger.info(f"Ensured directory exists: {directory}")
|
|
except Exception as e:
|
|
logger.error(f"Failed to create directory {directory}: {str(e)}")
|
|
|
|
|
|
def initialize_app() -> None:
|
|
"""
|
|
初始化应用程序,确保所需的目录和文件都存在
|
|
"""
|
|
# 确保必要的目录存在
|
|
required_directories = [
|
|
"app/static/css",
|
|
"app/static/js",
|
|
"app/static/icons",
|
|
"app/templates",
|
|
]
|
|
|
|
ensure_directories_exist(required_directories)
|
|
logger.info("Application initialization completed")
|