Merge branch 'master' of https://git.yunzer.cn/yunzerwebsite/CursorTokenLogin
This commit is contained in:
commit
85dea22024
@ -101,29 +101,52 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnChange">
|
<layout class="QHBoxLayout" name="horizontalLayout_change">
|
||||||
<property name="minimumSize">
|
<item>
|
||||||
<size>
|
<widget class="QPushButton" name="btnChange">
|
||||||
<width>0</width>
|
<property name="minimumSize">
|
||||||
<height>50</height>
|
<size>
|
||||||
</size>
|
<width>0</width>
|
||||||
</property>
|
<height>50</height>
|
||||||
<property name="font">
|
</size>
|
||||||
<font>
|
</property>
|
||||||
<pointsize>12</pointsize>
|
<property name="font">
|
||||||
<weight>75</weight>
|
<font>
|
||||||
<bold>true</bold>
|
<pointsize>12</pointsize>
|
||||||
</font>
|
<weight>75</weight>
|
||||||
</property>
|
<bold>true</bold>
|
||||||
<property name="styleSheet">
|
</font>
|
||||||
<string notr="true">QPushButton { background-color: #0078D4; color:
|
</property>
|
||||||
white; border-radius: 5px; } QPushButton:hover { background-color:
|
<property name="styleSheet">
|
||||||
#106EBE; } QPushButton:pressed { background-color: #005A9E; }</string>
|
<string notr="true">QPushButton { background-color: #0078D4; color:
|
||||||
</property>
|
white; border-radius: 5px; } QPushButton:hover { background-color:
|
||||||
<property name="text">
|
#106EBE; } QPushButton:pressed { background-color: #005A9E; }</string>
|
||||||
<string>🚀 开始换号</string>
|
</property>
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>🚀 开始换号</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnQueryUsage">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>90</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>90</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>📊 查询额度(暂时无用)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
@ -140,6 +163,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnEmergencyRepair">
|
||||||
|
<property name="text">
|
||||||
|
<string>🔧 应急检修,用户勿点</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimumHeight">
|
||||||
|
<number>30</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnDonate">
|
<widget class="QPushButton" name="btnDonate">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|||||||
102
main.py
102
main.py
@ -14,7 +14,7 @@ from contextlib import contextmanager
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
__VERSION__ = "0.0.2"
|
__VERSION__ = "0.0.3"
|
||||||
|
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
@ -32,7 +32,7 @@ from PySide6.QtWidgets import (
|
|||||||
QScrollArea,
|
QScrollArea,
|
||||||
QSplashScreen,
|
QSplashScreen,
|
||||||
)
|
)
|
||||||
from PySide6.QtCore import QThread, Signal, Qt, QTimer
|
from PySide6.QtCore import QThread, Signal, Qt, QTimer, QMetaObject, Q_ARG, Slot
|
||||||
from PySide6.QtUiTools import QUiLoader
|
from PySide6.QtUiTools import QUiLoader
|
||||||
from PySide6.QtGui import QFont, QPixmap, QColor, QPainter, QPalette, QIcon
|
from PySide6.QtGui import QFont, QPixmap, QColor, QPainter, QPalette, QIcon
|
||||||
|
|
||||||
@ -196,13 +196,13 @@ def update_vsdb_token(config_dir, new_token, new_email, log_callback):
|
|||||||
"UPDATE ItemTable SET value = ? WHERE key = ?",
|
"UPDATE ItemTable SET value = ? WHERE key = ?",
|
||||||
(value, key)
|
(value, key)
|
||||||
)
|
)
|
||||||
log_callback(f"✓ 更新了 {key}")
|
# log_callback(f"✓ 更新了 {key}")
|
||||||
else:
|
else:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"INSERT INTO ItemTable (key, value) VALUES (?, ?)",
|
"INSERT INTO ItemTable (key, value) VALUES (?, ?)",
|
||||||
(key, value)
|
(key, value)
|
||||||
)
|
)
|
||||||
log_callback(f"✓ 插入了 {key}")
|
# log_callback(f"✓ 插入了 {key}")
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
@ -568,6 +568,12 @@ class ChangeTokenThread(QThread):
|
|||||||
self.finished_signal.emit(False, "未找到 storage.json 文件")
|
self.finished_signal.emit(False, "未找到 storage.json 文件")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# 检查并修复只读属性
|
||||||
|
if not os.access(storage_file, os.W_OK):
|
||||||
|
self.log_signal.emit("🔓 检测到文件只读,正在解除只读属性...")
|
||||||
|
import stat
|
||||||
|
storage_file.chmod(storage_file.stat().st_mode | stat.S_IWRITE)
|
||||||
|
|
||||||
# 读取原文件
|
# 读取原文件
|
||||||
self.log_signal.emit("📖 读取配置文件...")
|
self.log_signal.emit("📖 读取配置文件...")
|
||||||
with open(storage_file, "r", encoding="utf-8") as f:
|
with open(storage_file, "r", encoding="utf-8") as f:
|
||||||
@ -780,6 +786,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.btnClearLog = self.findChild(QPushButton, "btnClearLog")
|
self.btnClearLog = self.findChild(QPushButton, "btnClearLog")
|
||||||
self.btnDonate = self.findChild(QPushButton, "btnDonate")
|
self.btnDonate = self.findChild(QPushButton, "btnDonate")
|
||||||
self.btnCheckUpdate = self.findChild(QPushButton, "btnCheckUpdate")
|
self.btnCheckUpdate = self.findChild(QPushButton, "btnCheckUpdate")
|
||||||
|
self.btnEmergencyRepair = self.findChild(QPushButton, "btnEmergencyRepair")
|
||||||
|
self.btnQueryUsage = self.findChild(QPushButton, "btnQueryUsage")
|
||||||
|
|
||||||
# 调试信息
|
# 调试信息
|
||||||
print(f"txtToken: {self.txtToken}")
|
print(f"txtToken: {self.txtToken}")
|
||||||
@ -806,6 +814,10 @@ class MainWindow(QMainWindow):
|
|||||||
self.btnDonate.clicked.connect(self.on_donate_clicked)
|
self.btnDonate.clicked.connect(self.on_donate_clicked)
|
||||||
if self.btnCheckUpdate:
|
if self.btnCheckUpdate:
|
||||||
self.btnCheckUpdate.clicked.connect(self.on_check_update_clicked)
|
self.btnCheckUpdate.clicked.connect(self.on_check_update_clicked)
|
||||||
|
if self.btnEmergencyRepair:
|
||||||
|
self.btnEmergencyRepair.clicked.connect(self.on_emergency_repair_clicked)
|
||||||
|
if self.btnQueryUsage:
|
||||||
|
self.btnQueryUsage.clicked.connect(self.on_query_usage_clicked)
|
||||||
|
|
||||||
# 设置版本号显示在状态栏右侧
|
# 设置版本号显示在状态栏右侧
|
||||||
self.statusBar().addPermanentWidget(QLabel(f"Version: {__VERSION__}"))
|
self.statusBar().addPermanentWidget(QLabel(f"Version: {__VERSION__}"))
|
||||||
@ -1056,7 +1068,87 @@ class MainWindow(QMainWindow):
|
|||||||
dialog = DonateDialog(self)
|
dialog = DonateDialog(self)
|
||||||
dialog.exec()
|
dialog.exec()
|
||||||
|
|
||||||
def on_change_finished(self, success, message):
|
def on_emergency_repair_clicked(self):
|
||||||
|
"""应急检修:下载工具到桌面"""
|
||||||
|
import urllib.request
|
||||||
|
import threading
|
||||||
|
|
||||||
|
url = "http://7colud.yunzer.cn/software/db%20browser%20for%20sqlite.zip"
|
||||||
|
desktop = Path.home() / "Desktop"
|
||||||
|
save_path = desktop / "db browser for sqlite.zip"
|
||||||
|
|
||||||
|
def download():
|
||||||
|
try:
|
||||||
|
self.log("🔧 正在下载检修工具...")
|
||||||
|
urllib.request.urlretrieve(url, str(save_path))
|
||||||
|
self.log(f"✅ 下载完成,已保存到桌面:{save_path.name}")
|
||||||
|
except Exception as e:
|
||||||
|
self.log(f"❌ 下载失败: {e}")
|
||||||
|
|
||||||
|
threading.Thread(target=download, daemon=True).start()
|
||||||
|
|
||||||
|
def on_query_usage_clicked(self):
|
||||||
|
"""查询当前token的额度使用情况"""
|
||||||
|
import threading
|
||||||
|
|
||||||
|
token = self.txtToken.toPlainText().strip() if self.txtToken else ""
|
||||||
|
if not token:
|
||||||
|
QMessageBox.warning(self, "提示", "请先在输入框中填入Token")
|
||||||
|
return
|
||||||
|
|
||||||
|
def query():
|
||||||
|
try:
|
||||||
|
clean_token = token.strip().replace('"', '').replace("SessionToken=", "")
|
||||||
|
resp = requests.get(
|
||||||
|
"https://cursor.com/api/usage",
|
||||||
|
headers={
|
||||||
|
"Cookie": f"SessionToken={clean_token}",
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0",
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
timeout=10,
|
||||||
|
)
|
||||||
|
if resp.status_code == 401:
|
||||||
|
msg = "查询失败:Token 已失效 (401 Unauthorized)。请检查账号是否已退出或被封。"
|
||||||
|
else:
|
||||||
|
resp.raise_for_status()
|
||||||
|
data = resp.json()
|
||||||
|
|
||||||
|
lines = []
|
||||||
|
premium = data.get("premiumUsage", {})
|
||||||
|
if premium:
|
||||||
|
used = premium.get("numRequestsTotal", 0)
|
||||||
|
limit = premium.get("maxRequestUsage", "无限制")
|
||||||
|
lines.append(f"高级模型 (GPT-4/Claude): 已用 {used} / {limit}")
|
||||||
|
|
||||||
|
for model_key, model_data in data.items():
|
||||||
|
if isinstance(model_data, dict) and "numRequestsTotal" in model_data:
|
||||||
|
used = model_data.get("numRequestsTotal", 0)
|
||||||
|
limit = model_data.get("maxRequestUsage")
|
||||||
|
limit_str = str(limit) if limit is not None else "无限制"
|
||||||
|
lines.append(f"{model_key}: 已用 {used} / {limit_str}")
|
||||||
|
|
||||||
|
msg = "\n".join(lines) if lines else "暂无额度数据,请检查账号状态。"
|
||||||
|
|
||||||
|
QMetaObject.invokeMethod(
|
||||||
|
self, "_show_usage_result",
|
||||||
|
Qt.ConnectionType.QueuedConnection,
|
||||||
|
Q_ARG(str, msg)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
QMetaObject.invokeMethod(
|
||||||
|
self, "_show_usage_result",
|
||||||
|
Qt.ConnectionType.QueuedConnection,
|
||||||
|
Q_ARG(str, f"网络请求错误:{str(e)}")
|
||||||
|
)
|
||||||
|
|
||||||
|
threading.Thread(target=query, daemon=True).start()
|
||||||
|
|
||||||
|
@Slot(str)
|
||||||
|
def _show_usage_result(self, msg):
|
||||||
|
QMessageBox.information(self, "额度查询结果", msg)
|
||||||
|
|
||||||
|
|
||||||
if self.btnChange:
|
if self.btnChange:
|
||||||
self.btnChange.setEnabled(True)
|
self.btnChange.setEnabled(True)
|
||||||
self.btnChange.setText("🚀 开始换号")
|
self.btnChange.setText("🚀 开始换号")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user