Spaces:
Running
Running
Upload server.js
Browse files
server.js
CHANGED
|
@@ -59,34 +59,35 @@ function readBody(req) {
|
|
| 59 |
});
|
| 60 |
}
|
| 61 |
|
| 62 |
-
function fetchRaw(
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 90 |
}
|
| 91 |
|
| 92 |
// ββ Cinemar parser ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 59 |
});
|
| 60 |
}
|
| 61 |
|
| 62 |
+
async function fetchRaw(url, headers = {}) {
|
| 63 |
+
let retries = 2;
|
| 64 |
+
while (retries > 0) {
|
| 65 |
+
try {
|
| 66 |
+
return await new Promise((resolve, reject) => {
|
| 67 |
+
const pu = new URL(url);
|
| 68 |
+
const mod = pu.protocol === 'https:' ? https : http;
|
| 69 |
+
const req = mod.get(url, {
|
| 70 |
+
headers: {
|
| 71 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
|
| 72 |
+
'connection': 'close',
|
| 73 |
+
...headers
|
| 74 |
+
},
|
| 75 |
+
timeout: 10000
|
| 76 |
+
}, (res) => {
|
| 77 |
+
let data = '';
|
| 78 |
+
res.on('data', (chunk) => data += chunk);
|
| 79 |
+
res.on('end', () => resolve(data));
|
| 80 |
+
});
|
| 81 |
+
req.on('error', reject);
|
| 82 |
+
req.on('timeout', () => { req.destroy(); reject(new Error('timeout')); });
|
| 83 |
+
});
|
| 84 |
+
} catch (e) {
|
| 85 |
+
console.log(`[fetchRaw] error for ${url}: ${e.message}, retries left: ${retries - 1}`);
|
| 86 |
+
retries--;
|
| 87 |
+
if (retries === 0) throw e;
|
| 88 |
+
await new Promise(r => setTimeout(r, 1000));
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
}
|
| 92 |
|
| 93 |
// ββ Cinemar parser ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|