From 98b06e6d2fafeca83c16e76f6b351df528d58cfb Mon Sep 17 00:00:00 2001 From: cheng zhen Date: Sat, 4 Jan 2025 20:51:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cursor_auth_manager.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cursor_auth_manager.py b/cursor_auth_manager.py index 7049d74..6e34afc 100644 --- a/cursor_auth_manager.py +++ b/cursor_auth_manager.py @@ -25,6 +25,9 @@ class CursorAuthManager: :return: bool 是否成功更新 """ updates = [] + # 登录状态 + updates.append(("cursorAuth/cachedSignUpType", "Auth_0")) + if email is not None: updates.append(("cursorAuth/cachedEmail", email)) if access_token is not None: @@ -42,8 +45,17 @@ class CursorAuthManager: cursor = conn.cursor() for key, value in updates: - query = "UPDATE itemTable SET value = ? WHERE key = ?" - cursor.execute(query, (value, key)) + + # 如果没有更新任何行,说明key不存在,执行插入 + # 检查 accessToken 是否存在 + check_query = f"SELECT COUNT(*) FROM itemTable WHERE key = ?" + cursor.execute(check_query, (key,)) + if cursor.fetchone()[0] == 0: + insert_query = "INSERT INTO itemTable (key, value) VALUES (?, ?)" + cursor.execute(insert_query, (key, value)) + else: + update_query = "UPDATE itemTable SET value = ? WHERE key = ?" + cursor.execute(update_query, (value, key)) if cursor.rowcount > 0: print(f"成功更新 {key.split('/')[-1]}")