Spaces:
Runtime error
Runtime error
Update server.js
Browse files
server.js
CHANGED
|
@@ -24,11 +24,19 @@ let sessions = new Map();
|
|
| 24 |
// Load sessions from disk on startup
|
| 25 |
try {
|
| 26 |
if (fs.existsSync(SESSION_FILE)) {
|
| 27 |
-
const
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
-
} catch (e) {
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
function saveSessions() {
|
| 34 |
try {
|
|
@@ -162,6 +170,12 @@ app.get('/auth/login', (req, res) => {
|
|
| 162 |
});
|
| 163 |
|
| 164 |
async function fetchWithRetry(url, options, retries = 2) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
for (let i = 0; i <= retries; i++) {
|
| 166 |
const controller = new AbortController();
|
| 167 |
const timeoutId = setTimeout(() => controller.abort(), 30000); // 30s timeout per attempt
|
|
@@ -169,7 +183,10 @@ async function fetchWithRetry(url, options, retries = 2) {
|
|
| 169 |
try {
|
| 170 |
let targetUrl = url;
|
| 171 |
if (url.includes('discord.com/api')) {
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
| 173 |
}
|
| 174 |
|
| 175 |
const res = await fetch(targetUrl, {
|
|
|
|
| 24 |
// Load sessions from disk on startup
|
| 25 |
try {
|
| 26 |
if (fs.existsSync(SESSION_FILE)) {
|
| 27 |
+
const content = fs.readFileSync(SESSION_FILE, 'utf8').trim();
|
| 28 |
+
if (content) {
|
| 29 |
+
const raw = JSON.parse(content);
|
| 30 |
+
if (raw && typeof raw === 'object') {
|
| 31 |
+
sessions = new Map(Object.entries(raw));
|
| 32 |
+
console.log(`[*] Dashboard: Loaded ${sessions.size} persistent session(s).`);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
}
|
| 36 |
+
} catch (e) {
|
| 37 |
+
console.error(`[*] Dashboard: Failed to load sessions: ${e.message}`);
|
| 38 |
+
}
|
| 39 |
+
console.log("[*] Dashboard: Session system initialized.");
|
| 40 |
|
| 41 |
function saveSessions() {
|
| 42 |
try {
|
|
|
|
| 170 |
});
|
| 171 |
|
| 172 |
async function fetchWithRetry(url, options, retries = 2) {
|
| 173 |
+
const endpoints = [
|
| 174 |
+
'discord.com',
|
| 175 |
+
'canary.discord.com',
|
| 176 |
+
'ptb.discord.com'
|
| 177 |
+
];
|
| 178 |
+
|
| 179 |
for (let i = 0; i <= retries; i++) {
|
| 180 |
const controller = new AbortController();
|
| 181 |
const timeoutId = setTimeout(() => controller.abort(), 30000); // 30s timeout per attempt
|
|
|
|
| 183 |
try {
|
| 184 |
let targetUrl = url;
|
| 185 |
if (url.includes('discord.com/api')) {
|
| 186 |
+
// Rotate hostname to bypass IP blocks
|
| 187 |
+
const endpoint = endpoints[i % endpoints.length];
|
| 188 |
+
targetUrl = url.replace('discord.com', endpoint);
|
| 189 |
+
console.log(`[Dashboard] Attempting connection via ${endpoint}...`);
|
| 190 |
}
|
| 191 |
|
| 192 |
const res = await fetch(targetUrl, {
|