Update index.js
Browse files
index.js
CHANGED
|
@@ -1,111 +1,120 @@
|
|
| 1 |
-
const
|
| 2 |
-
const
|
| 3 |
-
const
|
| 4 |
-
const fs = require('fs-extra');
|
| 5 |
-
const FormData = require('form-data');
|
| 6 |
-
const path = require('path');
|
| 7 |
-
const { v4: uuidv4 } = require('uuid');
|
| 8 |
|
| 9 |
-
const app = express();
|
| 10 |
const PORT = 7860;
|
| 11 |
-
const DATA_FILE = './data/files.json';
|
| 12 |
-
const MAX_CATBOX_SIZE = 200 * 1024 * 1024; // 200 MB
|
| 13 |
|
| 14 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
//
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
});
|
| 25 |
-
|
| 26 |
-
// 📤 Upload to Catbox or Litterbox
|
| 27 |
-
async function uploadToCatboxOrLitterbox(filepath, originalname) {
|
| 28 |
-
const fileSize = (await fs.stat(filepath)).size;
|
| 29 |
-
const formData = new FormData();
|
| 30 |
-
const fileStream = fs.createReadStream(filepath);
|
| 31 |
-
|
| 32 |
-
if (fileSize <= MAX_CATBOX_SIZE) {
|
| 33 |
-
formData.append('reqtype', 'fileupload');
|
| 34 |
-
formData.append('fileToUpload', fileStream, originalname);
|
| 35 |
-
const res = await axios.post('https://catbox.moe/user/api.php', formData, {
|
| 36 |
-
headers: formData.getHeaders()
|
| 37 |
-
});
|
| 38 |
-
return { url: res.data, type: 'catbox' };
|
| 39 |
-
} else {
|
| 40 |
-
formData.append('reqtype', 'fileupload');
|
| 41 |
-
formData.append('time', '72h');
|
| 42 |
-
formData.append('fileToUpload', fileStream, originalname);
|
| 43 |
-
const res = await axios.post('https://litterbox.catbox.moe/resources/internals/api.php', formData, {
|
| 44 |
-
headers: formData.getHeaders()
|
| 45 |
-
});
|
| 46 |
-
return { url: res.data, type: 'litterbox' };
|
| 47 |
-
}
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
// 📤 Upload Route
|
| 51 |
-
app.post('/upload', upload.single('file'), async (req, res) => {
|
| 52 |
-
const file = req.file;
|
| 53 |
-
const id = uuidv4();
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
filename: file.originalname,
|
| 61 |
-
localPath: file.path,
|
| 62 |
-
externalUrl: url,
|
| 63 |
-
source: type,
|
| 64 |
-
expiresAt: type === 'litterbox' ? Date.now() + 1000 * 60 * 60 * 24 * 3 : null
|
| 65 |
-
};
|
| 66 |
-
|
| 67 |
-
fs.writeFileSync(DATA_FILE, JSON.stringify(db, null, 2));
|
| 68 |
-
res.json({
|
| 69 |
-
id,
|
| 70 |
-
viewLink: `https://nexusv1-uploadx.hf.space/view/${id}`,
|
| 71 |
-
externalUrl: url,
|
| 72 |
-
source: type
|
| 73 |
-
});
|
| 74 |
-
} catch (e) {
|
| 75 |
-
res.status(500).json({ error: 'Upload failed', details: e.message });
|
| 76 |
-
}
|
| 77 |
});
|
| 78 |
|
| 79 |
-
//
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
res.download(file.localPath, file.filename);
|
| 89 |
});
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
const file = db[id];
|
| 95 |
-
if (file.source === 'litterbox' && file.expiresAt && (file.expiresAt - Date.now() < 1000 * 60 * 60 * 6)) {
|
| 96 |
-
try {
|
| 97 |
-
console.log(`♻️ Reuploading ${file.filename} (${id})`);
|
| 98 |
-
const { url, type } = await uploadToCatboxOrLitterbox(file.localPath, file.filename);
|
| 99 |
-
db[id].externalUrl = url;
|
| 100 |
-
db[id].source = type;
|
| 101 |
-
db[id].expiresAt = type === 'litterbox' ? Date.now() + 1000 * 60 * 60 * 24 * 3 : null;
|
| 102 |
-
fs.writeFileSync(DATA_FILE, JSON.stringify(db, null, 2));
|
| 103 |
-
console.log(`✅ Reuploaded: ${url}`);
|
| 104 |
-
} catch (err) {
|
| 105 |
-
console.error(`❌ Failed to reupload ${file.filename}:`, err.message);
|
| 106 |
-
}
|
| 107 |
-
}
|
| 108 |
-
}
|
| 109 |
-
}, 1000 * 60 * 30); // every 30 mins
|
| 110 |
-
|
| 111 |
-
app.listen(PORT, () => console.log(`🟢 Server running on http://localhost:${PORT}`));
|
|
|
|
| 1 |
+
const http = require('http');
|
| 2 |
+
const net = require('net');
|
| 3 |
+
const url = require('url');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
| 5 |
const PORT = 7860;
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
const server = http.createServer((req, res) => {
|
| 8 |
+
if (req.method === 'GET' && req.url === '/') {
|
| 9 |
+
// Serve status page
|
| 10 |
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
| 11 |
+
res.end(`
|
| 12 |
+
<!DOCTYPE html>
|
| 13 |
+
<html lang="en">
|
| 14 |
+
<head>
|
| 15 |
+
<meta charset="UTF-8" />
|
| 16 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
| 17 |
+
<title>Reiker Proxy Status</title>
|
| 18 |
+
<style>
|
| 19 |
+
body {
|
| 20 |
+
background-color: #0e0e2e;
|
| 21 |
+
color: #fff;
|
| 22 |
+
font-family: Arial, sans-serif;
|
| 23 |
+
display: flex;
|
| 24 |
+
flex-direction: column;
|
| 25 |
+
align-items: center;
|
| 26 |
+
justify-content: center;
|
| 27 |
+
min-height: 100vh;
|
| 28 |
+
margin: 0;
|
| 29 |
+
}
|
| 30 |
+
h1 {
|
| 31 |
+
color: #a259ff;
|
| 32 |
+
font-size: 2.5rem;
|
| 33 |
+
margin-bottom: 0.5rem;
|
| 34 |
+
}
|
| 35 |
+
.card {
|
| 36 |
+
background: #1f1f3d;
|
| 37 |
+
border-radius: 10px;
|
| 38 |
+
padding: 30px;
|
| 39 |
+
box-shadow: 0 0 20px rgba(162, 89, 255, 0.2);
|
| 40 |
+
max-width: 400px;
|
| 41 |
+
width: 90%;
|
| 42 |
+
text-align: center;
|
| 43 |
+
}
|
| 44 |
+
.status {
|
| 45 |
+
margin: 15px 0;
|
| 46 |
+
font-size: 1.2rem;
|
| 47 |
+
}
|
| 48 |
+
.status span {
|
| 49 |
+
font-weight: bold;
|
| 50 |
+
color: #a259ff;
|
| 51 |
+
}
|
| 52 |
+
.footer {
|
| 53 |
+
margin-top: 20px;
|
| 54 |
+
font-size: 0.9rem;
|
| 55 |
+
color: #aaa;
|
| 56 |
+
}
|
| 57 |
+
a {
|
| 58 |
+
color: #a259ff;
|
| 59 |
+
text-decoration: none;
|
| 60 |
+
}
|
| 61 |
+
a:hover {
|
| 62 |
+
text-decoration: underline;
|
| 63 |
+
}
|
| 64 |
+
</style>
|
| 65 |
+
</head>
|
| 66 |
+
<body>
|
| 67 |
+
<div class="card">
|
| 68 |
+
<h1>Reiker Proxies</h1>
|
| 69 |
+
<div class="status">🟢 <span>Status:</span> Online</div>
|
| 70 |
+
<div class="status">🔌 <span>Port:</span> ${PORT}</div>
|
| 71 |
+
<div class="status">📶 <span>Ping:</span> 1ms</div>
|
| 72 |
+
<div class="status">🧠 <span>Mode:</span> HTTP/HTTPS Proxy</div>
|
| 73 |
+
<div class="footer">Contact on Telegram: <a href="https://t.me/ReikerX" target="_blank">@ReikerX</a></div>
|
| 74 |
+
</div>
|
| 75 |
+
</body>
|
| 76 |
+
</html>
|
| 77 |
+
`);
|
| 78 |
+
return;
|
| 79 |
+
}
|
| 80 |
|
| 81 |
+
// Normal proxy behavior
|
| 82 |
+
const parsed = url.parse(req.url);
|
| 83 |
+
const options = {
|
| 84 |
+
hostname: parsed.hostname,
|
| 85 |
+
port: parsed.port || 80,
|
| 86 |
+
path: parsed.path,
|
| 87 |
+
method: req.method,
|
| 88 |
+
headers: req.headers
|
| 89 |
+
};
|
| 90 |
|
| 91 |
+
const proxyReq = http.request(options, (proxyRes) => {
|
| 92 |
+
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
| 93 |
+
proxyRes.pipe(res);
|
| 94 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
req.pipe(proxyReq);
|
| 97 |
+
proxyReq.on('error', (err) => {
|
| 98 |
+
res.writeHead(500);
|
| 99 |
+
res.end('Error: ' + err.message);
|
| 100 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
});
|
| 102 |
|
| 103 |
+
// HTTPS CONNECT tunneling
|
| 104 |
+
server.on('connect', (req, clientSocket, head) => {
|
| 105 |
+
const { port, hostname } = new URL(`http://${req.url}`);
|
| 106 |
+
const serverSocket = net.connect(port, hostname, () => {
|
| 107 |
+
clientSocket.write('HTTP/1.1 200 Connection Established\r\n\r\n');
|
| 108 |
+
serverSocket.write(head);
|
| 109 |
+
serverSocket.pipe(clientSocket);
|
| 110 |
+
clientSocket.pipe(serverSocket);
|
| 111 |
+
});
|
| 112 |
|
| 113 |
+
serverSocket.on('error', () => {
|
| 114 |
+
clientSocket.end('HTTP/1.1 500 Connection Error\r\n');
|
| 115 |
+
});
|
|
|
|
|
|
|
| 116 |
});
|
| 117 |
|
| 118 |
+
server.listen(PORT, () => {
|
| 119 |
+
console.log(`✅ Reiker Proxy running on port ${PORT}`);
|
| 120 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|