From 90ab732c47d037516fc60182ae1cf4b89534438f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=81=97=E5=BF=98=E7=9A=84=E8=AE=B0=E5=BF=86?= <32097237+YIWANG-sketch@users.noreply.github.com> Date: Sun, 17 Nov 2024 03:24:00 +0800 Subject: [PATCH] Add files via upload --- sessionManager.mjs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 sessionManager.mjs diff --git a/sessionManager.mjs b/sessionManager.mjs new file mode 100644 index 0000000..b2ff6ac --- /dev/null +++ b/sessionManager.mjs @@ -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; \ No newline at end of file