Update Lanyard socket URL, enhance IP logging in postAnalytics, and refactor App component structure
Some checks failed
Code quality checks / biome (push) Failing after 7s
Some checks failed
Code quality checks / biome (push) Failing after 7s
This commit is contained in:
parent
281e34bbd9
commit
a8d8f7014a
7 changed files with 49 additions and 183 deletions
|
@ -7,7 +7,7 @@ export default class {
|
||||||
|
|
||||||
constructor(callback: (data: LanyardData) => void) {
|
constructor(callback: (data: LanyardData) => void) {
|
||||||
this._socket = new ReconnectingWebSocket(
|
this._socket = new ReconnectingWebSocket(
|
||||||
"wss://lanyard.creations.works/socket",
|
"wss://lanyard.atums.world/socket",
|
||||||
);
|
);
|
||||||
this._keepAlive = null;
|
this._keepAlive = null;
|
||||||
this._callback = callback;
|
this._callback = callback;
|
||||||
|
@ -55,7 +55,7 @@ export default class {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this._socket.onclose = () => {
|
this._socket.onclose = (e) => {
|
||||||
console.log("Lanyard socket closed");
|
console.log("Lanyard socket closed");
|
||||||
if (this._keepAlive) {
|
if (this._keepAlive) {
|
||||||
clearInterval(this._keepAlive);
|
clearInterval(this._keepAlive);
|
||||||
|
|
|
@ -10,7 +10,7 @@ const build = async () => {
|
||||||
minify: !development,
|
minify: !development,
|
||||||
sourcemap: development ? "inline" : "none",
|
sourcemap: development ? "inline" : "none",
|
||||||
splitting: true,
|
splitting: true,
|
||||||
publicPath: "/assets/",
|
publicPath: "/assets/"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,18 +47,28 @@ const postAnalytics = async (
|
||||||
req: Request | Bun.BunRequest,
|
req: Request | Bun.BunRequest,
|
||||||
server: Bun.Server,
|
server: Bun.Server,
|
||||||
) => {
|
) => {
|
||||||
|
const cfIp = req.headers.get("CF-Connecting-IP");
|
||||||
|
const realIp = req.headers.get("X-Real-IP");
|
||||||
|
const forwardedIp = req.headers.get("X-Forwarded-For");
|
||||||
|
const serverIp = server.requestIP(req)?.address;
|
||||||
|
|
||||||
|
console.log({
|
||||||
|
cfIp,
|
||||||
|
realIp,
|
||||||
|
forwardedIp,
|
||||||
|
serverIp,
|
||||||
|
});
|
||||||
|
|
||||||
return await fetch("https://plausible.creations.works/api/event", {
|
return await fetch("https://plausible.creations.works/api/event", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"User-Agent": req.headers.get("user-agent") || "",
|
"User-Agent": req.headers.get("user-agent") || "",
|
||||||
"X-Forwarded-For": String(
|
"X-Forwarded-For": String(
|
||||||
req.headers.get("CF-Connecting-IP") ||
|
cfIp ||
|
||||||
req.headers.get("X-Real-IP") ||
|
realIp ||
|
||||||
req.headers.get("X-Forwarded-For")?.split(",")[0] ||
|
forwardedIp?.split(",")[0] ||
|
||||||
(typeof server.requestIP(req) === "string"
|
serverIp,
|
||||||
? server.requestIP(req)
|
|
||||||
: server.requestIP(req)?.address || ""),
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
@ -1,145 +1,27 @@
|
||||||
import Hyperate from "./components/Hyperate";
|
import Hyperate from "./components/Hyperate";
|
||||||
import Lanyard from "./components/Lanyard";
|
import Lanyard from "./components/Lanyard";
|
||||||
|
|
||||||
let latestLanyard: LanyardData | null = null;
|
|
||||||
|
|
||||||
window.addEventListener("lanyard-update", (e) => {
|
|
||||||
latestLanyard = (e as CustomEvent<LanyardData>).detail;
|
|
||||||
});
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
const container = document.createElement("div");
|
return (
|
||||||
container.className = "app terminal";
|
<div class="app terminal">
|
||||||
|
<p>[seth@ipv4 ~]$ cat ./about.txt</p>
|
||||||
|
<p>
|
||||||
|
A Dedicated Backend Developer,
|
||||||
|
<br />
|
||||||
|
with a passion for high-fidelity audio,
|
||||||
|
<br />
|
||||||
|
gaming, and web development.
|
||||||
|
</p>
|
||||||
|
|
||||||
const renderElement = (content: string | Node) => {
|
<p>[seth@ipv4 ~]$ cat /tmp/discord-ipc</p>
|
||||||
const p = document.createElement("p");
|
<p>
|
||||||
if (typeof content === "string") {
|
<Lanyard />
|
||||||
p.textContent = content;
|
</p>
|
||||||
} else {
|
|
||||||
p.appendChild(content);
|
<p>[seth@ipv4 ~]$ cat /tmp/heartrate</p>
|
||||||
}
|
<p>
|
||||||
return p;
|
<Hyperate />
|
||||||
};
|
</p>
|
||||||
|
</div>
|
||||||
const prompt = "[seth@ipv4 ~]$";
|
);
|
||||||
|
|
||||||
const staticLines: (string | (() => Node))[] = [
|
|
||||||
`${prompt} cat ./about.txt`,
|
|
||||||
() =>
|
|
||||||
document
|
|
||||||
.createRange()
|
|
||||||
.createContextualFragment(
|
|
||||||
"A Dedicated Backend Developer,<br />with a passion for high-fidelity audio,<br />gaming, and web development.",
|
|
||||||
),
|
|
||||||
`${prompt} cat /tmp/discord-ipc`,
|
|
||||||
() => Lanyard(),
|
|
||||||
`${prompt} cat /tmp/heartrate`,
|
|
||||||
() => Hyperate(),
|
|
||||||
];
|
|
||||||
|
|
||||||
const renderStatic = () => {
|
|
||||||
for (const line of staticLines) {
|
|
||||||
const content = typeof line === "function" ? line() : line;
|
|
||||||
container.appendChild(renderElement(content));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
renderStatic();
|
|
||||||
|
|
||||||
const lanyardInstance = Lanyard();
|
|
||||||
const files: Record<string, () => Node> = {
|
|
||||||
"./about.txt": () =>
|
|
||||||
document
|
|
||||||
.createRange()
|
|
||||||
.createContextualFragment(
|
|
||||||
"A Dedicated Backend Developer,<br />with a passion for high-fidelity audio,<br />gaming, and web development.",
|
|
||||||
),
|
|
||||||
"/tmp/discord-ipc": () => lanyardInstance,
|
|
||||||
"/tmp/heartrate": () => Hyperate(),
|
|
||||||
};
|
|
||||||
|
|
||||||
const history: string[] = [];
|
|
||||||
let historyIndex = -1;
|
|
||||||
|
|
||||||
const inputBox = document.createElement("input");
|
|
||||||
inputBox.className = "terminal-input";
|
|
||||||
inputBox.autofocus = true;
|
|
||||||
|
|
||||||
const inputLine = document.createElement("div");
|
|
||||||
inputLine.className = "terminal-line";
|
|
||||||
|
|
||||||
const promptSpan = document.createElement("span");
|
|
||||||
promptSpan.textContent = `${prompt} `;
|
|
||||||
|
|
||||||
inputLine.appendChild(promptSpan);
|
|
||||||
inputLine.appendChild(inputBox);
|
|
||||||
container.appendChild(inputLine);
|
|
||||||
|
|
||||||
const appendLine = (line: string | Node) => {
|
|
||||||
container.insertBefore(renderElement(line), inputLine);
|
|
||||||
};
|
|
||||||
|
|
||||||
inputBox.addEventListener("keydown", (e) => {
|
|
||||||
if (e.key === "Enter") {
|
|
||||||
const cmd = inputBox.value.trim();
|
|
||||||
if (!cmd) return;
|
|
||||||
|
|
||||||
history.push(cmd);
|
|
||||||
historyIndex = history.length;
|
|
||||||
|
|
||||||
appendLine(`${prompt} ${cmd}`);
|
|
||||||
|
|
||||||
let out: string | Node;
|
|
||||||
|
|
||||||
if (cmd.startsWith("cat ")) {
|
|
||||||
const file = cmd.slice(4).trim();
|
|
||||||
out = files[file]?.() ?? `cat: ${file}: No such file`;
|
|
||||||
} else if (cmd === "ls") {
|
|
||||||
out = Object.keys(files)
|
|
||||||
.filter((f) => f.startsWith("./"))
|
|
||||||
.map((f) => f.slice(2))
|
|
||||||
.join("\n");
|
|
||||||
} else if (cmd.startsWith("ls ")) {
|
|
||||||
const dir = cmd.slice(3).trim();
|
|
||||||
if (dir === "/tmp") {
|
|
||||||
out = Object.keys(files)
|
|
||||||
.filter((f) => f.startsWith("/tmp/"))
|
|
||||||
.map((f) => f.slice("/tmp/".length))
|
|
||||||
.join("\n");
|
|
||||||
} else {
|
|
||||||
out = `ls: cannot access '${dir}': No such file or directory`;
|
|
||||||
}
|
|
||||||
} else if (cmd === "help") {
|
|
||||||
out = [
|
|
||||||
"Available commands:",
|
|
||||||
" cat [file] View contents of a file",
|
|
||||||
" ls List files in current directory",
|
|
||||||
" ls /tmp List files in /tmp directory",
|
|
||||||
" help Show this message",
|
|
||||||
].join("\n");
|
|
||||||
} else {
|
|
||||||
out = `bash: ${cmd}: command not found`;
|
|
||||||
}
|
|
||||||
|
|
||||||
appendLine(out);
|
|
||||||
inputBox.value = "";
|
|
||||||
} else if (e.key === "ArrowUp") {
|
|
||||||
if (historyIndex > 0) {
|
|
||||||
historyIndex--;
|
|
||||||
inputBox.value = history[historyIndex] || "";
|
|
||||||
}
|
|
||||||
e.preventDefault();
|
|
||||||
} else if (e.key === "ArrowDown") {
|
|
||||||
if (historyIndex < history.length - 1) {
|
|
||||||
historyIndex++;
|
|
||||||
inputBox.value = history[historyIndex] || "";
|
|
||||||
} else {
|
|
||||||
historyIndex = history.length;
|
|
||||||
inputBox.value = "";
|
|
||||||
}
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return container;
|
|
||||||
};
|
};
|
|
@ -41,9 +41,6 @@ class Socket extends EventTarget {
|
||||||
|
|
||||||
emitLanyard(lanyard: LanyardData) {
|
emitLanyard(lanyard: LanyardData) {
|
||||||
this.dispatchEvent(new CustomEvent("lanyard", { detail: lanyard }));
|
this.dispatchEvent(new CustomEvent("lanyard", { detail: lanyard }));
|
||||||
window.dispatchEvent(
|
|
||||||
new CustomEvent("lanyard-update", { detail: lanyard }),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
emitHyperate(heartRate: number) {
|
emitHyperate(heartRate: number) {
|
||||||
this.dispatchEvent(new CustomEvent("hyperate", { detail: heartRate }));
|
this.dispatchEvent(new CustomEvent("hyperate", { detail: heartRate }));
|
||||||
|
|
|
@ -14,11 +14,9 @@ body {
|
||||||
body {
|
body {
|
||||||
color: #dedede;
|
color: #dedede;
|
||||||
text-shadow: 0 0 5px #c8c8c8;
|
text-shadow: 0 0 5px #c8c8c8;
|
||||||
background: radial-gradient(
|
background: radial-gradient(at bottom right,
|
||||||
at bottom right,
|
|
||||||
var(--gradient-color, rgba(150, 150, 150, 0.1)) 0%,
|
var(--gradient-color, rgba(150, 150, 150, 0.1)) 0%,
|
||||||
rgba(0, 0, 0, 1) 100%
|
rgba(0, 0, 0, 1) 100%);
|
||||||
);
|
|
||||||
display: flex;
|
display: flex;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
|
@ -40,27 +38,5 @@ p {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
gap: 0.4em;
|
gap: 0.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.terminal-input {
|
|
||||||
background: transparent;
|
|
||||||
border: none;
|
|
||||||
color: inherit;
|
|
||||||
font: inherit;
|
|
||||||
outline: none;
|
|
||||||
display: inline-block;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-line {
|
|
||||||
display: flex;
|
|
||||||
align-items: baseline;
|
|
||||||
flex-direction: row;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-line > span {
|
|
||||||
white-space: pre;
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,8 +30,9 @@ const server = serve({
|
||||||
"/assets/:file": async (req) =>
|
"/assets/:file": async (req) =>
|
||||||
Backend.Responses.file(file(`./dist/${req.params.file}`)),
|
Backend.Responses.file(file(`./dist/${req.params.file}`)),
|
||||||
|
|
||||||
"/public/:file": async (req) =>
|
"/robots.txt": async () => Backend.Responses.file(file("./public/robots.txt")),
|
||||||
Backend.Responses.file(file(`./public/${req.params.file}`)),
|
"/favicon.svg": async () =>
|
||||||
|
Backend.Responses.file(file("./public/favicon.svg")),
|
||||||
|
|
||||||
"/api/server": () => {
|
"/api/server": () => {
|
||||||
const safeProcess = JSON.parse(JSON.stringify(process));
|
const safeProcess = JSON.parse(JSON.stringify(process));
|
||||||
|
|
Loading…
Add table
Reference in a new issue