add:新增手动重置机器ID #32

This commit is contained in:
ddCat
2025-03-28 10:51:17 +08:00
parent 36101daae3
commit d59064d7b0
4 changed files with 118 additions and 7 deletions

22
api.py
View File

@@ -1036,6 +1036,28 @@ async def use_account_token(id: int):
error(traceback.format_exc())
return {"success": False, "message": f"使用Token失败: {str(e)}"}
# 添加"重置设备id"功能
@app.get("/reset-machine", tags=["System"])
async def reset_machine():
"""重置设备id"""
try:
# 重置Cursor的机器ID
from cursor_shadow_patcher import CursorShadowPatcher
resetter = CursorShadowPatcher()
patch_success = resetter.reset_machine_ids()
if patch_success:
return {
"success": True,
"message": f"成功重置了机器ID",
}
else:
return {"success": False, "message": "重置机器ID失败"}
except Exception as e:
error(f"重置机器ID失败: {str(e)}")
error(traceback.format_exc())
return {"success": False, "message": f"重置机器ID失败: {str(e)}"}
# 添加配置相关模型
class ConfigModel(BaseModel):

View File

@@ -382,6 +382,28 @@
</div>
</div>
</div>
<!-- 在系统配置区域添加重置机器ID按钮 -->
<div class="config-section card mb-3">
<div class="card-header bg-light">
<h5 class="mb-0">系统维护</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6">
<button id="restart-service-btn" class="btn btn-primary w-100">
<i class="fas fa-sync-alt me-2"></i>重启服务
</button>
<p class="text-muted small mt-1">某些配置更改需要重启服务才能生效</p>
</div>
<div class="col-md-6">
<button id="reset-machine-btn" class="btn btn-danger w-100">
<i class="fas fa-microchip me-2"></i>重置机器ID
</button>
<p class="text-muted small mt-1">解决设备绑定或配额限制问题</p>
</div>
</div>
</div>
</div>
<!-- 将按钮容器从text-end改为新的栅格布局 -->
<div class="row mt-4 config-actions" id="config-actions" style="display:none">
<div class="col-6 pe-1">
@@ -401,13 +423,6 @@
</span>
</button>
</div>
<!-- 在系统配置区域底部添加重启按钮 -->
<div class="text-center mt-4">
<button id="restart-service-btn" class="btn btn-danger">
<i class="fas fa-sync-alt me-2"></i>重启服务
</button>
<p class="text-muted small mt-2">某些配置更改需要重启服务才能生效</p>
</div>
</div>
</div>
</div>

View File

@@ -898,3 +898,33 @@ h2, h3, h4, h5 {
border-color: #86b7fe;
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
/* 系统维护按钮样式 - 更新蓝色按钮样式 */
.config-section .btn-danger,
.config-section .btn-primary {
transition: all 0.3s ease;
font-weight: 500;
}
.config-section .btn-primary {
background-color: #0b5ed7;
border-color: #0a58ca;
}
.config-section .btn-danger:hover {
background-color: #dc2626;
box-shadow: 0 4px 8px rgba(220, 38, 38, 0.3);
transform: translateY(-2px);
}
.config-section .btn-primary:hover {
background-color: #0a4fbf;
box-shadow: 0 4px 8px rgba(11, 94, 215, 0.3);
transform: translateY(-2px);
}
/* 系统维护卡片强调 */
.config-section.card {
border-color: #e2e8f0;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

View File

@@ -96,6 +96,17 @@ function bindEventHandlers() {
}
);
});
// 重置机器ID按钮事件
$("#reset-machine-btn").click(function() {
showConfirmDialog(
'重置机器ID',
'确定要重置机器ID吗这将解除当前设备的绑定限制但可能需要重新登录所有账号。',
function() {
resetMachineId();
}
);
});
}
// 全局变量
@@ -1529,4 +1540,37 @@ function formatTimeLeft(seconds) {
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours}小时${minutes}`;
}
}
// 添加重置机器ID函数
function resetMachineId() {
showLoading();
$.ajax({
url: '/reset-machine',
method: 'GET',
success: function(response) {
hideLoading();
if (response.success) {
showAlert('success', '成功重置机器ID。' + (response.message || ''));
// 询问是否需要重启服务以应用更改
setTimeout(function() {
showConfirmDialog(
'重启服务',
'机器ID已重置建议重启服务以确保更改生效。是否立即重启',
function() {
restartService();
}
);
}, 1000);
} else {
showAlert('danger', '重置机器ID失败: ' + (response.message || '未知错误'));
}
},
error: function(xhr) {
hideLoading();
showAlert('danger', '重置机器ID失败: ' + (xhr.responseJSON?.message || xhr.statusText || '未知错误'));
}
});
}