qa1145 commited on
Commit
1c8cdd0
·
verified ·
1 Parent(s): c896e8b

Upload sqlite.py

Browse files
Files changed (1) hide show
  1. astrbot/core/db/sqlite.py +21 -8
astrbot/core/db/sqlite.py CHANGED
@@ -2,6 +2,7 @@ import asyncio
2
  import hashlib
3
  import threading
4
  import typing as T
 
5
  from collections.abc import Awaitable, Callable
6
  from datetime import datetime, timedelta, timezone
7
 
@@ -79,15 +80,27 @@ class SQLiteDatabase(BaseDatabase):
79
  100_000,
80
  ).hex()
81
  key_prefix = raw_key[:12]
 
 
82
 
83
- await self.create_api_key(
84
- name="Default Developer Key",
85
- key_hash=key_hash,
86
- key_prefix=key_prefix,
87
- scopes=["chat", "config", "file", "im"],
88
- created_by="system",
89
- expires_at=None,
90
- )
 
 
 
 
 
 
 
 
 
 
91
 
92
  async def _ensure_persona_folder_columns(self, conn) -> None:
93
  """确保 personas 表有 folder_id 和 sort_order 列。
 
2
  import hashlib
3
  import threading
4
  import typing as T
5
+ import uuid
6
  from collections.abc import Awaitable, Callable
7
  from datetime import datetime, timedelta, timezone
8
 
 
80
  100_000,
81
  ).hex()
82
  key_prefix = raw_key[:12]
83
+ key_id = str(uuid.uuid4())
84
+ now = datetime.now(timezone.utc).isoformat()
85
 
86
+ async with self.engine.begin() as conn:
87
+ await conn.execute(
88
+ text("""
89
+ INSERT INTO api_keys (key_id, name, key_hash, key_prefix, scopes, created_by, created_at, updated_at)
90
+ VALUES (:key_id, :name, :key_hash, :key_prefix, :scopes, :created_by, :created_at, :updated_at)
91
+ """),
92
+ {
93
+ "key_id": key_id,
94
+ "name": "Default Developer Key",
95
+ "key_hash": key_hash,
96
+ "key_prefix": key_prefix,
97
+ "scopes": '["chat","config","file","im"]',
98
+ "created_by": "system",
99
+ "created_at": now,
100
+ "updated_at": now,
101
+ },
102
+ )
103
+ await conn.commit()
104
 
105
  async def _ensure_persona_folder_columns(self, conn) -> None:
106
  """确保 personas 表有 folder_id 和 sort_order 列。