qa1145 commited on
Commit
cce8e49
·
verified ·
1 Parent(s): f5fbb61

Upload 20 files

Browse files
astrbot/core/config/default.py CHANGED
@@ -70,7 +70,7 @@ DEFAULT_CONFIG = {
70
  "type": "openai_chat_completion",
71
  "provider_type": "chat_completion",
72
  "enable": True,
73
- "key": ["1"],
74
  "api_base": "https://qa1145-openrouter-free-api.hf.space/v1",
75
  "timeout": 120,
76
  "proxy": "",
 
70
  "type": "openai_chat_completion",
71
  "provider_type": "chat_completion",
72
  "enable": True,
73
+ "key": [1],
74
  "api_base": "https://qa1145-openrouter-free-api.hf.space/v1",
75
  "timeout": 120,
76
  "proxy": "",
astrbot/core/db/sqlite.py CHANGED
@@ -1,4 +1,5 @@
1
  import asyncio
 
2
  import threading
3
  import typing as T
4
  from collections.abc import Awaitable, Callable
@@ -55,12 +56,37 @@ class SQLiteDatabase(BaseDatabase):
55
  await conn.execute(text("PRAGMA temp_store=MEMORY"))
56
  await conn.execute(text("PRAGMA mmap_size=134217728"))
57
  await conn.execute(text("PRAGMA optimize"))
58
- # 确保 personas 表有 folder_id、sort_order、skills 列(前向兼容)
59
  await self._ensure_persona_folder_columns(conn)
60
  await self._ensure_persona_skills_column(conn)
61
  await self._ensure_persona_custom_error_message_column(conn)
62
  await conn.commit()
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  async def _ensure_persona_folder_columns(self, conn) -> None:
65
  """确保 personas 表有 folder_id 和 sort_order 列。
66
 
 
1
  import asyncio
2
+ import hashlib
3
  import threading
4
  import typing as T
5
  from collections.abc import Awaitable, Callable
 
56
  await conn.execute(text("PRAGMA temp_store=MEMORY"))
57
  await conn.execute(text("PRAGMA mmap_size=134217728"))
58
  await conn.execute(text("PRAGMA optimize"))
 
59
  await self._ensure_persona_folder_columns(conn)
60
  await self._ensure_persona_skills_column(conn)
61
  await self._ensure_persona_custom_error_message_column(conn)
62
  await conn.commit()
63
 
64
+ await self._create_default_api_key()
65
+
66
+ async def _create_default_api_key(self) -> None:
67
+ """Create a default developer API key if none exists."""
68
+ keys = await self.list_api_keys()
69
+ if keys:
70
+ return
71
+
72
+ raw_key = "abk_astrbot"
73
+ key_hash = hashlib.pbkdf2_hmac(
74
+ "sha256",
75
+ raw_key.encode("utf-8"),
76
+ b"astrbot_api_key",
77
+ 100_000,
78
+ ).hex()
79
+ key_prefix = raw_key[:12]
80
+
81
+ await self.create_api_key(
82
+ name="Default Developer Key",
83
+ key_hash=key_hash,
84
+ key_prefix=key_prefix,
85
+ scopes=["chat", "config", "file", "im"],
86
+ created_by="system",
87
+ expires_at=None,
88
+ )
89
+
90
  async def _ensure_persona_folder_columns(self, conn) -> None:
91
  """确保 personas 表有 folder_id 和 sort_order 列。
92