forked from seth/ipv4.army
Add logging for client IP in postAnalytics and update Lanyard styles to use RGB format
This commit is contained in:
parent
dcd6bfc3d7
commit
bf32c3fd35
3 changed files with 27 additions and 21 deletions
1
config.yml
Normal file
1
config.yml
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -47,6 +47,13 @@ const postAnalytics = async (
|
|||
req: Request | Bun.BunRequest,
|
||||
server: Bun.Server,
|
||||
) => {
|
||||
console.log(String(
|
||||
req.headers.get("CF-Connecting-IP") ||
|
||||
req.headers.get("X-Real-IP") ||
|
||||
req.headers.get("X-Forwarded-For")?.split(",")[0] ||
|
||||
(typeof server.requestIP(req) === "string"
|
||||
? server.requestIP(req)
|
||||
: server.requestIP(req)?.address || "")));
|
||||
return await fetch("https://plausible.creations.works/api/event", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -54,11 +61,11 @@ const postAnalytics = async (
|
|||
"User-Agent": req.headers.get("user-agent") || "",
|
||||
"X-Forwarded-For": String(
|
||||
req.headers.get("CF-Connecting-IP") ||
|
||||
req.headers.get("X-Real-IP") ||
|
||||
req.headers.get("X-Forwarded-For")?.split(",")[0] ||
|
||||
(typeof server.requestIP(req) === "string"
|
||||
? server.requestIP(req)
|
||||
: server.requestIP(req)?.address || ""),
|
||||
req.headers.get("X-Real-IP") ||
|
||||
req.headers.get("X-Forwarded-For")?.split(",")[0] ||
|
||||
(typeof server.requestIP(req) === "string"
|
||||
? server.requestIP(req)
|
||||
: server.requestIP(req)?.address || ""),
|
||||
),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
|
|
|
@ -3,17 +3,17 @@ import { createRef } from "tsx-dom";
|
|||
import socket from "../../Socket";
|
||||
|
||||
const statusTypes = {
|
||||
online: "rgb(0, 150, 0)",
|
||||
idle: "rgb(150, 150, 0)",
|
||||
dnd: "rgb(150, 0, 0)",
|
||||
offline: "rgb(150, 150, 150)",
|
||||
online: "0, 150, 0",
|
||||
idle: "150, 150, 0",
|
||||
dnd: "150, 0, 0",
|
||||
offline: "150, 150, 150",
|
||||
};
|
||||
|
||||
const gradientTypes = {
|
||||
online: "rgba(0, 150, 0, 0.1)",
|
||||
idle: "rgba(150, 150, 0, 0.1)",
|
||||
dnd: "rgba(150, 0, 0, 0.1)",
|
||||
offline: "rgba(150, 150, 150, 0.1)",
|
||||
online: "0, 150, 0",
|
||||
idle: "150, 150, 0",
|
||||
dnd: "150, 0, 0",
|
||||
offline: "150, 150, 150",
|
||||
};
|
||||
|
||||
const activityTypes: Record<number, string> = {
|
||||
|
@ -31,21 +31,19 @@ export default () => {
|
|||
socket.addEventListener("lanyard", (event: Event) => {
|
||||
const lanyard = (event as CustomEvent<LanyardData>).detail;
|
||||
|
||||
document.body.style = `--status-color: ${statusTypes[lanyard.discord_status]}; --gradient-color: ${gradientTypes[lanyard.discord_status]};`;
|
||||
document.body.style = `--status-color: rgb(${statusTypes[lanyard.discord_status]}); --gradient-color: rgba(${gradientTypes[lanyard.discord_status]}, 0.1);`;
|
||||
|
||||
if (container.current) {
|
||||
container.current.className = "shj-lang-json";
|
||||
container.current.textContent = JSON.stringify(
|
||||
{
|
||||
status: lanyard.discord_status,
|
||||
activities: lanyard.activities.map((act) => {
|
||||
activities: [... new Set(lanyard.activities.map((act) => {
|
||||
const type = activityTypes[act.type];
|
||||
const parts = [type];
|
||||
if (act.name !== type) parts.push(act.name);
|
||||
if (act.details) parts.push(act.details);
|
||||
if (act.state) parts.push(act.state);
|
||||
const parts = [`${type} ${act.name}`];
|
||||
if (act.details && act.details !== act.name) parts.push(act.details);
|
||||
if (act.state && act.state !== act.name) parts.push(act.state);
|
||||
return parts;
|
||||
}),
|
||||
}))],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
|
|
Loading…
Add table
Reference in a new issue