Skip to content

Commit 03ceb83

Browse files
committed
Update.
1 parent 42c6cb7 commit 03ceb83

File tree

4 files changed

+88
-74
lines changed

4 files changed

+88
-74
lines changed

cmd/dashboard/controller/member_api.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,31 @@ func (ma *memberAPI) deleteToken(c *gin.Context) {
210210
log.Printf("获取所有API令牌失败: %v", getAllErr)
211211
err = getAllErr
212212
} else {
213-
// 删除所有匹配的Token记录
213+
// 删除所有匹配的Token记录(包括重复记录)
214214
deletedCount := 0
215+
var deleteErrors []error
216+
215217
for _, t := range allTokens {
216-
if t.Token == token {
218+
if t != nil && t.Token == token {
217219
if deleteErr := apiTokenOps.DeleteApiToken(t.ID); deleteErr != nil {
218220
log.Printf("删除API令牌记录失败 (ID: %d): %v", t.ID, deleteErr)
221+
deleteErrors = append(deleteErrors, deleteErr)
219222
} else {
220223
deletedCount++
221224
log.Printf("BadgerDB: 成功删除API令牌记录 %s (ID: %d, Note: %s)", token, t.ID, t.Note)
222225
}
223226
}
224227
}
228+
225229
if deletedCount > 1 {
226230
log.Printf("BadgerDB: 发现并删除了 %d 个重复的API令牌记录: %s", deletedCount, token)
227231
}
232+
228233
if deletedCount == 0 {
229234
err = fmt.Errorf("未找到要删除的API令牌记录")
235+
} else if len(deleteErrors) > 0 {
236+
// 如果有部分删除失败,记录警告但不影响整体结果
237+
log.Printf("警告: %d 个API令牌记录删除失败,但已成功删除 %d 个记录", len(deleteErrors), deletedCount)
230238
}
231239
}
232240
}

model/host.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ func (h *Host) Initialize() {
120120
h.GPU = []string{}
121121
}
122122
// 确保其他字段有合理的默认值
123-
if h.OS == "" {
124-
h.OS = "Unknown"
125-
}
126-
if h.Platform == "" {
127-
h.Platform = "Unknown"
128-
}
129-
if h.Arch == "" {
130-
h.Arch = "Unknown"
131-
}
123+
// if h.OS == "" {
124+
// h.OS = "Unknown"
125+
// }
126+
// if h.Platform == "" {
127+
// h.Platform = "Unknown"
128+
// }
129+
// if h.Arch == "" {
130+
// h.Arch = "Unknown"
131+
// }
132132
}
133133

134134
func (h *Host) PB() *pb.Host {

resource/static/main.js

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,67 +1222,7 @@ function debugOfflineServersConfig() {
12221222
}
12231223
}
12241224

1225-
// 初始化WebSocket连接
1226-
function initWebSocket() {
1227-
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
1228-
const wsUrl = `${protocol}//${window.location.host}/ws`;
1229-
1230-
const ws = new WebSocket(wsUrl);
1231-
1232-
ws.onopen = function() {
1233-
try {
1234-
ws.send(JSON.stringify({ type: 'ping' }));
1235-
} catch (e) {
1236-
}
1237-
};
1238-
1239-
ws.onmessage = function(event) {
1240-
try {
1241-
const data = JSON.parse(event.data);
1242-
1243-
// 处理服务器状态更新
1244-
if (data.servers && Array.isArray(data.servers)) {
1245-
if (window.statusCards) {
1246-
window.statusCards.updateServerLiveStatus(data);
1247-
}
1248-
}
1249-
1250-
// 处理流量数据更新 - 流量数据可能单独发送或与服务器状态一起发送
1251-
if (data.trafficData && Array.isArray(data.trafficData)) {
1252-
window.serverTrafficRawData = data.trafficData;
1253-
if (window.trafficManager) {
1254-
window.trafficManager.processTrafficData(data.trafficData);
1255-
} else {
1256-
window.extractTrafficData();
1257-
}
1258-
}
1259-
} catch (e) {
1260-
}
1261-
};
1262-
1263-
ws.onerror = function(error) {
1264-
};
1265-
1266-
ws.onclose = function(event) {
1267-
setTimeout(initWebSocket, 5000);
1268-
};
1269-
1270-
return ws;
1271-
}
1272-
1273-
// 在页面加载完成后初始化WebSocket
1274-
$(document).ready(function() {
1275-
window.ws = initWebSocket();
1276-
1277-
// 添加页面可见性变化监听
1278-
document.addEventListener('visibilitychange', function() {
1279-
if (document.visibilityState === 'visible') {
1280-
if (!window.ws || window.ws.readyState !== WebSocket.OPEN) {
1281-
window.ws = initWebSocket();
1282-
}
1283-
}
1284-
});
1285-
});
1225+
// WebSocket相关代码已移动到home.html中,仅在首页使用
12861226

12871227
// 保留WebSocket的流量数据处理
12881228
window.extractTrafficData = function() {

resource/template/theme-default/home.html

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,74 @@
965965
// 使Vue实例全局可用
966966
window.statusCards = statusCards;
967967

968+
// 初始化WebSocket连接
969+
function initWebSocket() {
970+
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
971+
const wsUrl = `${protocol}//${window.location.host}/ws`;
972+
973+
const ws = new WebSocket(wsUrl);
974+
975+
ws.onopen = function() {
976+
try {
977+
ws.send(JSON.stringify({ type: 'ping' }));
978+
} catch (e) {
979+
console.warn('WebSocket ping failed:', e);
980+
}
981+
};
982+
983+
ws.onmessage = function(event) {
984+
try {
985+
const data = JSON.parse(event.data);
986+
987+
// 处理服务器状态更新
988+
if (data.servers && Array.isArray(data.servers)) {
989+
if (window.statusCards) {
990+
window.statusCards.updateServerLiveStatus(data);
991+
}
992+
}
993+
994+
// 处理流量数据更新 - 流量数据可能单独发送或与服务器状态一起发送
995+
if (data.trafficData && Array.isArray(data.trafficData)) {
996+
window.serverTrafficRawData = data.trafficData;
997+
if (window.trafficManager) {
998+
window.trafficManager.processTrafficData(data.trafficData);
999+
} else {
1000+
window.extractTrafficData();
1001+
}
1002+
}
1003+
} catch (e) {
1004+
console.warn('WebSocket message parsing failed:', e);
1005+
}
1006+
};
1007+
1008+
ws.onerror = function(error) {
1009+
console.warn('WebSocket error:', error);
1010+
};
1011+
1012+
ws.onclose = function(event) {
1013+
console.log('WebSocket closed, reconnecting in 5 seconds...');
1014+
setTimeout(initWebSocket, 5000);
1015+
};
1016+
1017+
return ws;
1018+
}
1019+
9681020
$(document).ready(function() {
969-
$('.ui.accordion').accordion({
1021+
// 初始化WebSocket连接(仅在首页)
1022+
if (window.location.pathname === '/' || window.location.pathname === '/home') {
1023+
window.ws = initWebSocket();
1024+
1025+
// 添加页面可见性变化监听
1026+
document.addEventListener('visibilitychange', function() {
1027+
if (document.visibilityState === 'visible') {
1028+
if (!window.ws || window.ws.readyState !== WebSocket.OPEN) {
1029+
window.ws = initWebSocket();
1030+
}
1031+
}
1032+
});
1033+
}
1034+
1035+
$('.ui.accordion').accordion({
9701036
exclusive: false,
9711037
silent: true,
9721038
performance: true,
@@ -976,7 +1042,7 @@
9761042
duration: 200,
9771043
easing: 'easeOutQuad'
9781044
});
979-
1045+
9801046
$(document).off('touchstart.accordion touchmove.accordion');
9811047
$(document).on('touchstart.accordion', '.ui.accordion .title', function(e) {
9821048
// 被动处理,不阻止默认行为

0 commit comments

Comments
 (0)