forked from xiaozhou26/deeplx-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b12123e
commit 1aa1445
Showing
588 changed files
with
73,814 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// cookieManager.js | ||
|
||
require('dotenv').config(); // Ensure .env is loaded | ||
|
||
let cookies = process.env.DEEPL_COOKIES ? process.env.DEEPL_COOKIES.split(',') : []; | ||
let invalidCookies = []; | ||
let currentCookieIndex = 0; | ||
|
||
// Validate cookies format | ||
function validateCookies() { | ||
cookies = cookies.filter(cookie => /^[0-9a-fA-F-]{8}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{4}-[0-9a-fA-F-]{12}$/.test(cookie)); | ||
if (cookies.length === 0) { | ||
console.error("No valid cookies provided. Please check your DEEPL_COOKIES environment variable."); | ||
console.error("Cookies found:", process.env.DEEPL_COOKIES); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function getNextCookie() { | ||
let attempts = 0; | ||
while (attempts < cookies.length) { | ||
const cookie = cookies[currentCookieIndex]; | ||
if (!invalidCookies.includes(cookie)) { | ||
currentCookieIndex = (currentCookieIndex + 1) % cookies.length; | ||
return `dl_session=${cookie}`; | ||
} | ||
currentCookieIndex = (currentCookieIndex + 1) % cookies.length; | ||
attempts++; | ||
} | ||
return null; | ||
} | ||
|
||
function markCookieInvalid(cookie) { | ||
const cookieValue = cookie.replace('dl_session=', ''); | ||
if (!invalidCookies.includes(cookieValue)) { | ||
invalidCookies.push(cookieValue); | ||
} | ||
} | ||
|
||
// Initialize and validate cookies on startup | ||
validateCookies(); | ||
|
||
module.exports = { | ||
getNextCookie, | ||
markCookieInvalid | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.