From a65ee6fe673f3b49dc7192745fafed9ee78c25da Mon Sep 17 00:00:00 2001 From: seth Date: Sun, 4 May 2025 20:55:40 -0400 Subject: [PATCH] linting --- biome.json | 44 +++++++ bun.lock | 2 +- index.ts | 164 +++++++++++++----------- package.json | 44 ++++--- src/back/Sockets/Hyperate.ts | 153 +++++++++++----------- src/back/Sockets/Lanyard.ts | 109 ++++++++-------- src/back/index.ts | 132 ++++++++++--------- src/front/App.css | 66 +++++----- src/front/App.tsx | 34 +++-- src/front/Socket.ts | 78 +++++------ src/front/components/Hyperate/index.tsx | 24 ++-- src/front/components/Lanyard/index.tsx | 99 +++++++------- src/front/index.css | 24 ++-- src/front/index.tsx | 4 +- tsconfig.json | 53 ++++---- 15 files changed, 564 insertions(+), 466 deletions(-) create mode 100644 biome.json diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..46ee8c9 --- /dev/null +++ b/biome.json @@ -0,0 +1,44 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignoreUnknown": true, + "ignore": [] + }, + "formatter": { + "enabled": true, + "indentStyle": "tab", + "lineEnding": "lf" + }, + "organizeImports": { + "enabled": true + }, + "css": { + "formatter": { + "indentStyle": "tab", + "lineEnding": "lf" + } + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "correctness": { + "noUnusedImports": "error" + } + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double", + "indentStyle": "tab", + "lineEnding": "lf", + "jsxQuoteStyle": "double", + "semicolons": "always" + } + } +} diff --git a/bun.lock b/bun.lock index 8ececa6..7d6e32e 100644 --- a/bun.lock +++ b/bun.lock @@ -9,7 +9,7 @@ "tsx-dom": "latest", }, "devDependencies": { - "@biomejs/biome": "1.9.4", + "@biomejs/biome": "^1.9.4", "@types/bun": "latest", }, "peerDependencies": { diff --git a/index.ts b/index.ts index aba1cb2..e4b48b7 100644 --- a/index.ts +++ b/index.ts @@ -1,107 +1,119 @@ -import { build, serve, gzipSync, file, gc } from "bun"; +import { file, gc, serve } from "bun"; -import Backend from "./src/back" +import Backend from "./src/back"; import pkg from "./package.json"; - let heartrate = 0; let lanyard = {}; -require("node:fs/promises").rm("./dist", { recursive: true, force: true }).catch(() => { - // ignore -}); +require("node:fs/promises") + .rm("./dist", { recursive: true, force: true }) + .catch(() => { + // ignore + }); if (!Backend.development) { - await Backend.build() + await Backend.build(); } const server = serve({ - routes: { - "/": async (req: Bun.BunRequest, server: Bun.Server) => { - await Backend.postAnalytics(req, server); + routes: { + "/": async (req: Bun.BunRequest, server: Bun.Server) => { + await Backend.postAnalytics(req, server); - if (Backend.development) { - await Backend.build() - } + if (Backend.development) { + await Backend.build(); + } - return await Backend.Responses.file(file("./dist/index.html")); - }, + return await Backend.Responses.file(file("./dist/index.html")); + }, - "/assets/:file": async (req: Bun.BunRequest<"/assets/:file">) => { - return await Backend.Responses.file(file(`./dist/${req.params.file}`)); - }, + "/assets/:file": async (req: Bun.BunRequest<"/assets/:file">) => { + return await Backend.Responses.file(file(`./dist/${req.params.file}`)); + }, - "/public/:file": async (req: Bun.BunRequest<"/public/:file">) => { - return await Backend.Responses.file(file(`./public/${req.params.file}`)); - }, + "/public/:file": async (req: Bun.BunRequest<"/public/:file">) => { + return await Backend.Responses.file(file(`./public/${req.params.file}`)); + }, - "/api/server": () => { - const string = JSON.stringify(process) - const data = JSON.parse(string) + "/api/server": () => { + const string = JSON.stringify(process); + const data = JSON.parse(string); - // clear possibly data that could be sensitive - data.env = {} + // clear possibly data that could be sensitive + data.env = {}; - data.availableMemory = process.availableMemory() - data.constrainedMemory = process.constrainedMemory() - data.cpuUsage = process.cpuUsage() - data.memoryUsage = process.memoryUsage() - data.uptime = process.uptime() - data.package = pkg + data.availableMemory = process.availableMemory(); + data.constrainedMemory = process.constrainedMemory(); + data.cpuUsage = process.cpuUsage(); + data.memoryUsage = process.memoryUsage(); + data.uptime = process.uptime(); + data.package = pkg; - return Backend.Responses.json({ data }); - }, - "/api/health": () => { - return Backend.Responses.ok(); - }, - "/api/ws": async (req, server) => { - if (server.upgrade(req)) { - return; - } + return Backend.Responses.json({ data }); + }, + "/api/health": () => { + return Backend.Responses.ok(); + }, + "/api/ws": async (req, server) => { + if (server.upgrade(req)) { + return; + } - await Backend.postAnalytics(req, server); - return Response.redirect("/"); - }, - "/api/gc": async () => { - gc(true) + await Backend.postAnalytics(req, server); + return Response.redirect("/"); + }, + "/api/gc": async () => { + gc(true); - return Backend.Responses.ok(); - }, - "/api/headers": async (req) => { - return Backend.Responses.json({ ...req.headers.toJSON() }); - } - }, + return Backend.Responses.ok(); + }, + "/api/headers": async (req) => { + return Backend.Responses.json({ ...req.headers.toJSON() }); + }, + }, - fetch: async (request, server) => { - await Backend.postAnalytics(request, server); + fetch: async (request, server) => { + await Backend.postAnalytics(request, server); - return Response.redirect("/"); - }, + return Response.redirect("/"); + }, - websocket: { - idleTimeout: 1, - open: async (ws) => { - ws.subscribe("lanyard"); - ws.send(JSON.stringify({ type: "lanyard", data: lanyard }), true); + websocket: { + idleTimeout: 1, + open: async (ws) => { + ws.subscribe("lanyard"); + ws.send(JSON.stringify({ type: "lanyard", data: lanyard }), true); - ws.subscribe("hyperate"); - ws.send(JSON.stringify({ type: "hyperate", data: { hr: heartrate } }), true); - }, - message: async (ws, message) => { - ws.send(JSON.stringify({ type: "echo", data: message }), true) - } - }, - development: Backend.development, - port: 2056 + ws.subscribe("hyperate"); + ws.send( + JSON.stringify({ type: "hyperate", data: { hr: heartrate } }), + true, + ); + }, + message: async (ws, message) => { + ws.send(JSON.stringify({ type: "echo", data: message }), true); + }, + }, + development: Backend.development, + port: 2056, }); new Backend.Sockets.Hyperate((data) => { - heartrate = data; - server.publish("hyperate", JSON.stringify({ type: "hyperate", data: { hr: heartrate } }), true); -}) + heartrate = data; + server.publish( + "hyperate", + JSON.stringify({ type: "hyperate", data: { hr: heartrate } }), + true, + ); +}); new Backend.Sockets.Lanyard((data) => { - lanyard = data; - server.publish("lanyard", JSON.stringify({ type: "lanyard", data: lanyard }), true); -}); \ No newline at end of file + lanyard = data; + server.publish( + "lanyard", + JSON.stringify({ type: "lanyard", data: lanyard }), + true, + ); +}); diff --git a/package.json b/package.json index a1b2ce3..8cc2293 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,24 @@ { - "name": "ipv4.army", - "module": "index.ts", - "scripts": { - "dev": "NODE_ENV=development bun run --hot . --watch", - "start": "bun run ." - }, - "devDependencies": { - "@biomejs/biome": "1.9.4", - "@types/bun": "latest" - }, - "peerDependencies": { - "typescript": "^5.8.3" - }, - "private": true, - "type": "module", - "dependencies": { - "@speed-highlight/core": "latest", - "reconnecting-websocket": "latest", - "tsx-dom": "latest" - } -} \ No newline at end of file + "name": "ipv4.army", + "module": "index.ts", + "scripts": { + "dev": "NODE_ENV=development bun run --hot . --watch", + "start": "bun run .", + "lint": "bunx biome ci . --verbose", + "lint:fix": "bunx biome check --fix" + }, + "devDependencies": { + "@biomejs/biome": "^1.9.4", + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.8.3" + }, + "private": true, + "type": "module", + "dependencies": { + "@speed-highlight/core": "latest", + "reconnecting-websocket": "latest", + "tsx-dom": "latest" + } +} diff --git a/src/back/Sockets/Hyperate.ts b/src/back/Sockets/Hyperate.ts index 0badb0c..d4154a2 100644 --- a/src/back/Sockets/Hyperate.ts +++ b/src/back/Sockets/Hyperate.ts @@ -1,88 +1,89 @@ -import ReconnectingWebSocket from 'reconnecting-websocket'; +import ReconnectingWebSocket from "reconnecting-websocket"; export default class { - private _socket: ReconnectingWebSocket; - private _keepAlive: NodeJS.Timeout | null; - private _interval: NodeJS.Timeout | null; - private _callback: (data: number) => void; + private _socket: ReconnectingWebSocket; + private _keepAlive: NodeJS.Timeout | null; + private _interval: NodeJS.Timeout | null; + private _callback: (data: number) => void; - constructor(callback: (data: number) => void) { - this._socket = new ReconnectingWebSocket("wss://app.hyperate.io/socket/websocket?token=wv39nM6iyrNJulvpmMQrimYPIXy2dVrYRjkuHpbRapKT2VSh65ngDGHdCdCtmEN9") - this._keepAlive = null; - this._interval = null; - this._callback = callback; + constructor(callback: (data: number) => void) { + this._socket = new ReconnectingWebSocket( + "wss://app.hyperate.io/socket/websocket?token=wv39nM6iyrNJulvpmMQrimYPIXy2dVrYRjkuHpbRapKT2VSh65ngDGHdCdCtmEN9", + ); + this._keepAlive = null; + this._interval = null; + this._callback = callback; - this._socket.binaryType = "arraybuffer"; + this._socket.binaryType = "arraybuffer"; - this._socket.onopen = () => { - console.log("Hyperate socket opened") + this._socket.onopen = () => { + console.log("Hyperate socket opened"); - this._socket.send( - JSON.stringify({ - topic: "hr:84aa0f", - event: "phx_join", - payload: {}, - ref: 0, - }), - ); + this._socket.send( + JSON.stringify({ + topic: "hr:84aa0f", + event: "phx_join", + payload: {}, + ref: 0, + }), + ); - this._keepAlive = setInterval(() => { - this._socket.send( - JSON.stringify({ - topic: "phoenix", - event: "heartbeat", - payload: {}, - ref: 0, - }), - ); - }, 10000); - } + this._keepAlive = setInterval(() => { + this._socket.send( + JSON.stringify({ + topic: "phoenix", + event: "heartbeat", + payload: {}, + ref: 0, + }), + ); + }, 10000); + }; - this._socket.onmessage = ({ data }: MessageEvent) => { - data = JSON.parse(data); + this._socket.onmessage = ({ data }: MessageEvent) => { + data = JSON.parse(data); - switch (data.event) { - case "hr_update": { - this._callback(data.payload.hr); - this.heartbeat(); - break; - } - } - } + switch (data.event) { + case "hr_update": { + this._callback(data.payload.hr); + this.heartbeat(); + break; + } + } + }; - this._socket.onerror = () => { - console.error("Hyperate socket error"); - if (this._keepAlive) { - clearInterval(this._keepAlive); - this._keepAlive = null; - } - if (this._interval) { - clearInterval(this._interval); - this._interval = null; - } - } + this._socket.onerror = () => { + console.error("Hyperate socket error"); + if (this._keepAlive) { + clearInterval(this._keepAlive); + this._keepAlive = null; + } + if (this._interval) { + clearInterval(this._interval); + this._interval = null; + } + }; - this._socket.onclose = () => { - console.log("Hyperate socket closed"); - if (this._keepAlive) { - clearInterval(this._keepAlive); - this._keepAlive = null; - } - if (this._interval) { - clearInterval(this._interval); - this._interval = null; - } - } + this._socket.onclose = () => { + console.log("Hyperate socket closed"); + if (this._keepAlive) { + clearInterval(this._keepAlive); + this._keepAlive = null; + } + if (this._interval) { + clearInterval(this._interval); + this._interval = null; + } + }; + } - } - - private heartbeat() { - if (this._interval) { - clearTimeout(this._interval); - this._interval = null; - } - this._interval = setTimeout(() => { - this._callback(0); - }, 6000); - } -} \ No newline at end of file + private heartbeat() { + if (this._interval) { + clearTimeout(this._interval); + this._interval = null; + } + this._interval = setTimeout(() => { + this._callback(0); + }, 6000); + } +} diff --git a/src/back/Sockets/Lanyard.ts b/src/back/Sockets/Lanyard.ts index d4999fa..04f9b9d 100644 --- a/src/back/Sockets/Lanyard.ts +++ b/src/back/Sockets/Lanyard.ts @@ -1,61 +1,66 @@ -import ReconnectingWebSocket from 'reconnecting-websocket'; +import ReconnectingWebSocket from "reconnecting-websocket"; export default class { - private _socket: ReconnectingWebSocket; - private _keepAlive: NodeJS.Timeout | null; - private _callback: (data: { [key: string]: string }) => void; + private _socket: ReconnectingWebSocket; + private _keepAlive: NodeJS.Timeout | null; + private _callback: (data: { [key: string]: string }) => void; - constructor(callback: (data: { [key: string]: string }) => void) { - this._socket = new ReconnectingWebSocket("wss://lanyard.creations.works/socket") - this._keepAlive = null; - this._callback = callback; + constructor(callback: (data: { [key: string]: string }) => void) { + this._socket = new ReconnectingWebSocket( + "wss://lanyard.creations.works/socket", + ); + this._keepAlive = null; + this._callback = callback; - this._socket.binaryType = "arraybuffer"; + this._socket.binaryType = "arraybuffer"; - this._socket.onopen = () => { - console.log("Lanyard socket opened") - } + this._socket.onopen = () => { + console.log("Lanyard socket opened"); + }; - this._socket.onmessage = ({ data }: MessageEvent) => { - data = JSON.parse(data); + this._socket.onmessage = ({ data }: MessageEvent) => { + data = JSON.parse(data); - switch (data.op) { - case 0: { - this._callback(data.d) - break; - } - case 1: { - this._socket.send(JSON.stringify({ - op: 2, - d: { - subscribe_to_id: "1273447359417942128" - } - })) - this._keepAlive = setInterval(() => { - this._socket.send(JSON.stringify({ - op: 3 - })) - }, data.d.heartbeat_interval) - break; - } - } - } + switch (data.op) { + case 0: { + this._callback(data.d); + break; + } + case 1: { + this._socket.send( + JSON.stringify({ + op: 2, + d: { + subscribe_to_id: "1273447359417942128", + }, + }), + ); + this._keepAlive = setInterval(() => { + this._socket.send( + JSON.stringify({ + op: 3, + }), + ); + }, data.d.heartbeat_interval); + break; + } + } + }; - this._socket.onerror = () => { - console.error("Lanyard socket error"); - if (this._keepAlive) { - clearInterval(this._keepAlive); - this._keepAlive = null; - } - } + this._socket.onerror = () => { + console.error("Lanyard socket error"); + if (this._keepAlive) { + clearInterval(this._keepAlive); + this._keepAlive = null; + } + }; - this._socket.onclose = () => { - console.log("Lanyard socket closed"); - if (this._keepAlive) { - clearInterval(this._keepAlive); - this._keepAlive = null; - } - } - - } -} \ No newline at end of file + this._socket.onclose = () => { + console.log("Lanyard socket closed"); + if (this._keepAlive) { + clearInterval(this._keepAlive); + this._keepAlive = null; + } + }; + } +} diff --git a/src/back/index.ts b/src/back/index.ts index 7ac97e1..f010df2 100644 --- a/src/back/index.ts +++ b/src/back/index.ts @@ -4,71 +4,79 @@ import Lanyard from "./Sockets/Lanyard"; const development = process.env.NODE_ENV === "development"; const build = async () => { - return await Bun.build({ - entrypoints: ['./src/front/index.html'], - outdir: './dist', - minify: !development, - sourcemap: (development ? "inline" : "none"), - splitting: true, - publicPath: "/assets/", - }) -} + return await Bun.build({ + entrypoints: ["./src/front/index.html"], + outdir: "./dist", + minify: !development, + sourcemap: development ? "inline" : "none", + splitting: true, + publicPath: "/assets/", + }); +}; const respOptions = { - headers: { - "Content-Type": "application/json", - "Cache-Control": "no-cache", - "Content-Encoding": "gzip", - } -} -const okResp = new Response(Bun.gzipSync(JSON.stringify({ data: "ok" })), respOptions) + headers: { + "Content-Type": "application/json", + "Cache-Control": "no-cache", + "Content-Encoding": "gzip", + }, +}; +const okResp = new Response( + Bun.gzipSync(JSON.stringify({ data: "ok" })), + respOptions, +); const Responses = { - ok: () => { - return okResp.clone(); - }, - json: (data: { [key: string]: string }) => { - return new Response(Bun.gzipSync(JSON.stringify(data)), respOptions); - }, - file: async (file: Bun.BunFile) => { - return new Response(Bun.gzipSync(await file.arrayBuffer()), { - headers: { - "Content-Type": file.type, - "Cache-Control": "public, max-age=31536000", - "Content-Encoding": "gzip", - } - }); - } -} + ok: () => { + return okResp.clone(); + }, + json: (data: { [key: string]: string }) => { + return new Response(Bun.gzipSync(JSON.stringify(data)), respOptions); + }, + file: async (file: Bun.BunFile) => { + return new Response(Bun.gzipSync(await file.arrayBuffer()), { + headers: { + "Content-Type": file.type, + "Cache-Control": "public, max-age=31536000", + "Content-Encoding": "gzip", + }, + }); + }, +}; -const postAnalytics = async (req: Request | Bun.BunRequest, server: Bun.Server) => { - return await fetch("https://plausible.creations.works/api/event", { - method: "POST", - headers: { - "Content-Type": "application/json", - "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 || "")) - ), - }, - body: JSON.stringify({ - domain: "ipv4.army", - name: "pageview", - url: req.url, - referrer: req.headers.get("referer") || "", - }) - }) -} +const postAnalytics = async ( + req: Request | Bun.BunRequest, + server: Bun.Server, +) => { + return await fetch("https://plausible.creations.works/api/event", { + method: "POST", + headers: { + "Content-Type": "application/json", + "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 || ""), + ), + }, + body: JSON.stringify({ + domain: "ipv4.army", + name: "pageview", + url: req.url, + referrer: req.headers.get("referer") || "", + }), + }); +}; export default { - Sockets: { - Hyperate, - Lanyard - }, - Responses, - build, - development, - postAnalytics, -}; \ No newline at end of file + Sockets: { + Hyperate, + Lanyard, + }, + Responses, + build, + development, + postAnalytics, +}; diff --git a/src/front/App.css b/src/front/App.css index 86b4f77..8e39d36 100644 --- a/src/front/App.css +++ b/src/front/App.css @@ -1,59 +1,61 @@ .scanlines { - overflow: hidden; + overflow: hidden; } .scanlines:before, .scanlines:after { - display: inherit; - pointer-events: none; - content: ""; - position: absolute; + display: inherit; + pointer-events: none; + content: ""; + position: absolute; } .scanlines:before { - width: 100%; - height: 2px; - z-index: 2147483649; - background: rgba(0, 0, 0, 0.3); - opacity: 0.75; - animation: scanline 6s linear infinite; + width: 100%; + height: 2px; + z-index: 2147483649; + background: rgba(0, 0, 0, 0.3); + opacity: 0.75; + animation: scanline 6s linear infinite; } .scanlines:after { - top: 0; - right: 0; - bottom: 0; - left: 0; - z-index: 2147483648; - background: linear-gradient(to bottom, - transparent 50%, - rgba(0, 0, 0, 0.3) 51%); - background-size: 100% 6px; - animation: scanlines 2s steps(30) infinite; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 2147483648; + background: linear-gradient( + to bottom, + transparent 50%, + rgba(0, 0, 0, 0.3) 51% + ); + background-size: 100% 6px; + animation: scanlines 2s steps(30) infinite; } /* ANIMATE UNIQUE SCANLINE */ @keyframes scanline { - 0% { - transform: translate3d(0, 200000%, 0); - } + 0% { + transform: translate3d(0, 200000%, 0); + } } @keyframes scanlines { - 0% { - background-position: 0 50%; - } + 0% { + background-position: 0 50%; + } } span.shj-syn-str:nth-child(2) { - color: var(--status-color, rgba(150, 150, 150, 0.1)); + color: var(--status-color, rgba(150, 150, 150, 0.1)); } .shj-numbers { - padding: 0px; + padding: 0px; } .shj-lang-json { - padding: 0px; - background-color: transparent; -} \ No newline at end of file + padding: 0px; + background-color: transparent; +} diff --git a/src/front/App.tsx b/src/front/App.tsx index 06e9041..40dd719 100644 --- a/src/front/App.tsx +++ b/src/front/App.tsx @@ -1,15 +1,27 @@ -import Lanyard from './components/Lanyard'; -import Hyperate from './components/Hyperate'; +import Hyperate from "./components/Hyperate"; +import Lanyard from "./components/Lanyard"; export default () => { - return
-

seth> cat ./about.txt

-

A Dedicated Backend Developer,
with a passion for high-fidelity audio,
gaming, and web development.

+ return ( +
+

seth> cat ./about.txt

+

+ A Dedicated Backend Developer, +
+ with a passion for high-fidelity audio, +
+ gaming, and web development. +

-

seth> curl /tmp/discord-ipc

-

+

seth> curl /tmp/discord-ipc

+

+ +

-

seth> cat /tmp/heartrate

-

-
-} \ No newline at end of file +

seth> cat /tmp/heartrate

+

+ +

+
+ ); +}; diff --git a/src/front/Socket.ts b/src/front/Socket.ts index 22a39a9..3c271bf 100644 --- a/src/front/Socket.ts +++ b/src/front/Socket.ts @@ -1,50 +1,50 @@ const { protocol, host } = window.location; class Socket extends EventTarget { - private _socket: WebSocket; + private _socket: WebSocket; - constructor(url: string) { - super(); + constructor(url: string) { + super(); - this._socket = new WebSocket(url); - this._socket.onmessage = (event) => { - const { type, data } = JSON.parse(event.data); + this._socket = new WebSocket(url); + this._socket.onmessage = (event) => { + const { type, data } = JSON.parse(event.data); - switch (type) { - case "lanyard": { - this.emitLanyard(data); - break; - } - case "hyperate": { - this.emitHyperate(data.hr); - break; - } - case "echo": { - console.log("Echo: ", data); - break; - } - default: { - console.error("Unknown message type: ", type, data); - break; - } - } - }; + switch (type) { + case "lanyard": { + this.emitLanyard(data); + break; + } + case "hyperate": { + this.emitHyperate(data.hr); + break; + } + case "echo": { + console.log("Echo: ", data); + break; + } + default: { + console.error("Unknown message type: ", type, data); + break; + } + } + }; - this._socket.onclose = () => { - location.reload(); - }; + this._socket.onclose = () => { + location.reload(); + }; - setInterval(() => { - this._socket.send("ping"); - }, 30 * 1000); - } + setInterval(() => { + this._socket.send("ping"); + }, 30 * 1000); + } - emitLanyard(lanyard: object) { - this.dispatchEvent(new CustomEvent('lanyard', { detail: lanyard })); - } - emitHyperate(heartRate: number) { - this.dispatchEvent(new CustomEvent('hyperate', { detail: heartRate })); - } + emitLanyard(lanyard: object) { + this.dispatchEvent(new CustomEvent("lanyard", { detail: lanyard })); + } + emitHyperate(heartRate: number) { + this.dispatchEvent(new CustomEvent("hyperate", { detail: heartRate })); + } } -export default new Socket(`${protocol.replace("http", "ws")}//${host}/api/ws`); \ No newline at end of file +export default new Socket(`${protocol.replace("http", "ws")}//${host}/api/ws`); diff --git a/src/front/components/Hyperate/index.tsx b/src/front/components/Hyperate/index.tsx index 8ca5997..e5c1074 100644 --- a/src/front/components/Hyperate/index.tsx +++ b/src/front/components/Hyperate/index.tsx @@ -3,15 +3,17 @@ import { createRef } from "tsx-dom"; import socket from "../../Socket"; export default () => { - const paragraph = createRef(); + const paragraph = createRef(); - socket.addEventListener('hyperate', (event: Event) => { - const heartRate = (event as CustomEvent).detail; - if (paragraph.current) { - paragraph.current.innerText = `${heartRate} BPM`; - } - }); - return
-

0 BPM

-
; -} \ No newline at end of file + socket.addEventListener("hyperate", (event: Event) => { + const heartRate = (event as CustomEvent).detail; + if (paragraph.current) { + paragraph.current.innerText = `${heartRate} BPM`; + } + }); + return ( +
+

0 BPM

+
+ ); +}; diff --git a/src/front/components/Lanyard/index.tsx b/src/front/components/Lanyard/index.tsx index 29396c6..aee6527 100644 --- a/src/front/components/Lanyard/index.tsx +++ b/src/front/components/Lanyard/index.tsx @@ -1,59 +1,68 @@ -import { createRef } from "tsx-dom"; import { highlightAll } from "@speed-highlight/core"; +import { createRef } from "tsx-dom"; import socket from "../../Socket"; const statusTypes: { [key: string]: string } = { - online: "rgb(0, 150, 0)", - idle: "rgb(150, 150, 0)", - dnd: "rgb(150, 0, 0)", - offline: "rgb(150, 150, 150)", -} + online: "rgb(0, 150, 0)", + idle: "rgb(150, 150, 0)", + dnd: "rgb(150, 0, 0)", + offline: "rgb(150, 150, 150)", +}; const gradientTypes: { [key: string]: string } = { - 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: "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)", +}; const activityTypes: { [key: number]: string } = { - 0: "Playing", - 1: "Streaming", - 2: "Listening to", - 3: "Watching", - 4: "Custom Status", - 5: "Competing in", -} + 0: "Playing", + 1: "Streaming", + 2: "Listening to", + 3: "Watching", + 4: "Custom Status", + 5: "Competing in", +}; const stringify = (data: { [key: string]: string }) => { - return JSON.stringify(data, null, 2) -} + return JSON.stringify(data, null, 2); +}; export default () => { - const code = createRef(); + const code = createRef(); - socket.addEventListener('lanyard', (event: Event) => { - const lanyard = (event as CustomEvent).detail; - document.body.style = `--status-color: ${statusTypes[lanyard.discord_status]}; --gradient-color: ${gradientTypes[lanyard.discord_status]};`; - if (code.current) { - code.current.innerHTML = stringify({ - status: lanyard.discord_status, - activities: lanyard.activities.map((act: { - type: number, name: string, details: string, state: string - }) => { - return [ - ... new Set([ - activityTypes[act.type], - act.name, - act.details, - act.state - ]) - ].filter(n => n) - }), - }); - } - highlightAll(); - }); + socket.addEventListener("lanyard", (event: Event) => { + const lanyard = (event as CustomEvent).detail; + document.body.style = `--status-color: ${statusTypes[lanyard.discord_status]}; --gradient-color: ${gradientTypes[lanyard.discord_status]};`; + if (code.current) { + code.current.innerHTML = stringify({ + status: lanyard.discord_status, + activities: lanyard.activities.map( + (act: { + type: number; + name: string; + details: string; + state: string; + }) => { + return [ + ...new Set([ + activityTypes[act.type], + act.name, + act.details, + act.state, + ]), + ].filter((n) => n); + }, + ), + }); + } + highlightAll(); + }); - return
{"{}"}
-} \ No newline at end of file + return ( +
+ {"{}"} +
+ ); +}; diff --git a/src/front/index.css b/src/front/index.css index f1285a9..1b5386d 100644 --- a/src/front/index.css +++ b/src/front/index.css @@ -5,16 +5,20 @@ html, head, body { - margin: 0; - padding: 0; - font: 2vh monospace; - height: 100vh; - width: 100vw; + margin: 0; + padding: 0; + font: 2vh monospace; + height: 100vh; + width: 100vw; } body { - color: #DEDEDE; - text-shadow: 0 0 5px #C8C8C8; - background: radial-gradient(at bottom right, var(--gradient-color, rgba(150, 150, 150, 0.1)) 0%, rgba(0, 0, 0, 1) 100%); - display: flex; -} \ No newline at end of file + color: #dedede; + text-shadow: 0 0 5px #c8c8c8; + background: radial-gradient( + at bottom right, + var(--gradient-color, rgba(150, 150, 150, 0.1)) 0%, + rgba(0, 0, 0, 1) 100% + ); + display: flex; +} diff --git a/src/front/index.tsx b/src/front/index.tsx index eedc7db..93f1320 100644 --- a/src/front/index.tsx +++ b/src/front/index.tsx @@ -1,8 +1,8 @@ import "tsx-dom"; -import App from './App'; +import App from "./App"; document.body.appendChild(); // You're garbage, let me collect you. -fetch("/api/gc") \ No newline at end of file +fetch("/api/gc"); diff --git a/tsconfig.json b/tsconfig.json index 29eee99..ab77b3d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,29 +1,26 @@ { - "compilerOptions": { - // Environment setup & latest features - "lib": [ - "ESNext", - "DOM", - ], - "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", - "jsxImportSource": "tsx-dom", - "allowJs": true, - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - // Best practices - "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedIndexedAccess": true, - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false - } -} \ No newline at end of file + "compilerOptions": { + // Environment setup & latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "jsxImportSource": "tsx-dom", + "allowJs": true, + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +}