改用API驗證

This commit is contained in:
beabigegg
2025-10-02 17:13:24 +08:00
parent 0a89c19fc9
commit adecdf0cce
48 changed files with 6136 additions and 1239 deletions

View File

@@ -87,6 +87,12 @@ class Config:
# Dify API 配置(從 api.txt 載入)
DIFY_API_BASE_URL = ''
DIFY_API_KEY = ''
# 分離的 Dify API 配置
DIFY_TRANSLATION_BASE_URL = ''
DIFY_TRANSLATION_API_KEY = ''
DIFY_OCR_BASE_URL = ''
DIFY_OCR_API_KEY = ''
# 日誌配置
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO')
@@ -103,11 +109,31 @@ class Config:
try:
with open(api_file, 'r', encoding='utf-8') as f:
for line in f:
if line.startswith('base_url:'):
line = line.strip()
if not line or line.startswith('#'):
continue
# 翻译API配置
if line.startswith('translation_base_url:'):
cls.DIFY_TRANSLATION_BASE_URL = line.split(':', 1)[1].strip()
elif line.startswith('translation_api:'):
cls.DIFY_TRANSLATION_API_KEY = line.split(':', 1)[1].strip()
# OCR API配置
elif line.startswith('ocr_base_url:'):
cls.DIFY_OCR_BASE_URL = line.split(':', 1)[1].strip()
elif line.startswith('ocr_api:'):
cls.DIFY_OCR_API_KEY = line.split(':', 1)[1].strip()
# 兼容旧格式
elif line.startswith('base_url:'):
cls.DIFY_API_BASE_URL = line.split(':', 1)[1].strip()
cls.DIFY_TRANSLATION_BASE_URL = line.split(':', 1)[1].strip()
elif line.startswith('api:'):
cls.DIFY_API_KEY = line.split(':', 1)[1].strip()
except Exception:
cls.DIFY_TRANSLATION_API_KEY = line.split(':', 1)[1].strip()
except Exception as e:
print(f"Error loading Dify config: {e}")
pass
@classmethod