File size: 3,796 Bytes
dc7aadc 8bf27ec cb25c80 dc7aadc 7dd5c4c b7604ef 7dd5c4c e1a7fd3 dc7aadc 90e4651 dc7aadc 6af284c 88b8ef4 e1a7fd3 88b8ef4 e1a7fd3 3a9ffa9 e1a7fd3 88b8ef4 8babfe5 66a7c30 d312f25 88b8ef4 a554442 d312f25 66a7c30 d312f25 d753ef3 4043d79 376597e d753ef3 419fa76 4043d79 d753ef3 4043d79 17f2e27 d753ef3 17f2e27 4ebce36 d753ef3 17f2e27 4ebce36 7dd5c4c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
const express = require('express')
const app = express()
const port = 7860
const axios = require('axios')
const { connectToMongoDB } = require('./database');
const startup = async () => {
try {
console.log("Starting application...");
await connectToMongoDB();
console.log("MongoDB connected successfully.");
} catch (error) {
console.error("Error during startup:", error.message);
process.exit(1);
}
};
const startServer = async () => {
await startup();
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
};
const IPAddressAndUpdate = async (ip) => {
try {
const db = await connectToMongoDB();
const collection = db.collection("FastJsAPI");
const filter = { ip: ip};
const update = { $set: { ip: ip } };
await collection.updateOne(filter, update, { upsert: true });
console.log("Updated IP Address");
} catch (error) {
console.error("Error:", error.message);
}
};
app.get('/', (req, res) => {
res.redirect('https://t.me/RendyProjects');
});
app.use(async (req, res, next) => {
const xForwardedFor = req.headers['x-forwarded-for'];
const xRealIP = req.headers['x-real-ip'];
const cfConnectingIP = req.headers['cf-connecting-ip'];
let realIP = req.ip;
// const BlockedIp = ["103.187.116.9"];
if (xForwardedFor) {
realIP = xForwardedFor.split(',')[0].trim();
}
else if (xRealIP){
realIP = xRealIP;
}
else if (cfConnectingIP) {
realIP = cfConnectingIP;
}
req.realIP = realIP;
/*
if (BlockedIp.includes(realIP)) {
console.log(`Blocked request from IP address: ${realIP}`);
res.status(403).send("access is blocked");
}
*/
await IPAddressAndUpdate(realIP);
console.log(`Real IP address is: ${realIP}, header: ${xForwardedFor ? "x-forwarded-for" : xRealIP ? "x-real-ip" : cfConnectingIP ? "cf-connecting-ip" : "req.ip"} `);
next();
});
app.get('/api/test', async (req, res) => {
try {
// console.log("Test", req)
res.send("Hello world")
} catch (error) {
res.status(401).json({error: error.message})
}
})
const payload = (prompt) => ({
model: "gpt-4o",
prompt: prompt,
top_p: 1,
logprobs: null,
stop: null
});
const OpenaiRes = async (prompt) => {
try {
const EncodeUrl = "aHR0cHM6Ly9vcGVuYWktZ3B0LnJlbWl4cHJvamVjdC5vcmcv"
let url;
try {
url = atob(EncodeUrl);
} catch (e) {
console.error("Could not decode the string! " + e);
}
const headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Accept-Language": "en",
"Connection": "keep-alive",
"Origin": "https://remix.ethereum.org",
"Referer": "https://remix.ethereum.org/",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "cross-site",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134"
};
const response = await axios.post(url, payload(prompt), { headers, timeout: 50000 });
if (response.status === 200) {
return response.data.choices[0].message.content + "\n\nPowered By xtdevs";
}
// console.log("Response:", response)
} catch (error) {
console.error("Error:", error.message);
return null;
}
};
app.get('/api/gpt-old', async (req, res) => {
try {
const query = req.query.query;
const results = await OpenaiRes(query);
res.json({ results });
} catch (error) {
res.status(401).json({ error: error.message });
}
});
startServer(); |