|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AccountManager {
|
|
|
constructor(cookies) {
|
|
|
this.cookies = this.initCookies(cookies)
|
|
|
this.unavailableCookies = new Set()
|
|
|
this.currentIndex = 0
|
|
|
this.unlimitedIndex = 0
|
|
|
}
|
|
|
|
|
|
markAsUnavailable(cookie) {
|
|
|
this.unavailableCookies.add(cookie)
|
|
|
}
|
|
|
|
|
|
getNextAvailableCookie() {
|
|
|
if (this.cookies.length === 0) {
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
|
|
|
if (this.unavailableCookies.size >= this.cookies.length) {
|
|
|
return this.cookies[0]
|
|
|
}
|
|
|
|
|
|
|
|
|
for (let i = 0; i < this.cookies.length; i++) {
|
|
|
|
|
|
this.currentIndex = (this.currentIndex + 1) % this.cookies.length
|
|
|
const cookie = this.cookies[this.currentIndex]
|
|
|
|
|
|
|
|
|
if (!this.unavailableCookies.has(cookie)) {
|
|
|
return cookie
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return this.cookies[0]
|
|
|
}
|
|
|
|
|
|
getAnyCookie() {
|
|
|
if (this.cookies.length === 0) {
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
this.unlimitedIndex = (this.unlimitedIndex + 1) % this.cookies.length
|
|
|
return this.cookies[this.unlimitedIndex]
|
|
|
}
|
|
|
|
|
|
initCookies(cookies) {
|
|
|
return cookies.split(',').map(cookie => cookie.trim()).filter(cookie => cookie)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
const COOKIES = process.env.COOKIES || ""
|
|
|
const accountManager = new AccountManager(COOKIES)
|
|
|
|
|
|
module.exports = accountManager |