Add files via upload

This commit is contained in:
被遗忘的记忆
2024-11-17 03:24:00 +08:00
committed by GitHub
parent cf703dccdf
commit 90ab732c47
+30
View File
@@ -0,0 +1,30 @@
class SessionManager {
constructor(provider) {
this.sessions = provider.sessions;
}
// 获取所有可用会话
getAvailableSessions() {
return Object.keys(this.sessions).filter(username => this.sessions[username].valid);
}
// 随机选择会话
getRandomSession() {
const availableSessions = this.getAvailableSessions();
if (availableSessions.length === 0) {
throw new Error('没有可用的会话');
}
const randomIndex = Math.floor(Math.random() * availableSessions.length);
return availableSessions[randomIndex];
}
// 策略
getSessionByStrategy(strategy = 'random') {
if (strategy === 'random') {
return this.getRandomSession();
}
throw new Error(`未实现的策略: ${strategy}`);
}
}
export default SessionManager;