Skip to content

Commit ba6a369

Browse files
author
Your Name
committed
feat: 将 key.txt 移至 auth_profiles 目录 (修复 #216)
1 parent a0978cc commit ba6a369

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

api_utils/auth_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Set
33

44
API_KEYS: Set[str] = set()
5-
KEY_FILE_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "key.txt")
5+
KEY_FILE_PATH = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "auth_profiles", "key.txt")
66

77
def load_api_keys():
88
"""Loads API keys from the key file into the API_KEYS set."""

api_utils/routes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ async def add_api_key(request: ApiKeyRequest, logger: logging.Logger = Depends(g
327327
raise HTTPException(status_code=400, detail="该API密钥已存在。")
328328

329329
try:
330-
key_file_path = os.path.join(os.path.dirname(__file__), "..", "key.txt")
330+
# --- MODIFIED LINE ---
331+
# Use the centralized path from auth_utils
332+
key_file_path = auth_utils.KEY_FILE_PATH
331333
with open(key_file_path, 'a+', encoding='utf-8') as f:
332334
f.seek(0)
333335
if f.read(): f.write("\n")
@@ -366,7 +368,9 @@ async def delete_api_key(request: ApiKeyRequest, logger: logging.Logger = Depend
366368
raise HTTPException(status_code=404, detail="API密钥不存在。")
367369

368370
try:
369-
key_file_path = os.path.join(os.path.dirname(__file__), "..", "key.txt")
371+
# --- MODIFIED LINE ---
372+
# Use the centralized path from auth_utils
373+
key_file_path = auth_utils.KEY_FILE_PATH
370374
with open(key_file_path, 'r', encoding='utf-8') as f:
371375
lines = f.readlines()
372376

0 commit comments

Comments
 (0)