test something
This commit is contained in:
parent
42a1b60b0c
commit
4e09c44150
@ -53,32 +53,39 @@ module.exports = function (app, config, renderTemplate) {
|
||||
f.body.pipe(res);
|
||||
});
|
||||
|
||||
|
||||
app.get("/api/geo", async (req, res) => {
|
||||
try {
|
||||
let ip =
|
||||
req.headers["x-forwarded-for"]?.split(",")[0].trim() ||
|
||||
req.socket.remoteAddress;
|
||||
|
||||
if (ip && ip.startsWith("::ffff:")) ip = ip.slice(7);
|
||||
if (!ip || ip.startsWith("192.") || ip.startsWith("10.") || ip === "::1") {
|
||||
return res.json({ countryCode: "ZZ" });
|
||||
if (ip && ip.startsWith("::ffff:")) {
|
||||
ip = ip.slice(7);
|
||||
}
|
||||
|
||||
if (!ip) {
|
||||
return res.status(400).json({ error: "No IP found" });
|
||||
}
|
||||
|
||||
const response = await fetch(`https://ip2c.org/${ip}`);
|
||||
const text = await response.text();
|
||||
const parts = text.trim().split(";");
|
||||
|
||||
const countryCode = parts[1] || "ZZ";
|
||||
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.json({ countryCode });
|
||||
} catch {
|
||||
res.json({ countryCode: "ZZ" });
|
||||
} catch (err) {
|
||||
res.setHeader("Content-Type", "application/json");
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.status(500).json({ countryCode: "ZZ", error: true, details: String(err) });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
app.get("/ggpht/:v", async function (req, res) {
|
||||
var url = `https://yt3.ggpht.com/${req.params.v}`;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user