From 23f37beef35c385acad2c0c56c01761ecaf50d8d Mon Sep 17 00:00:00 2001 From: creations Date: Thu, 17 Apr 2025 18:26:59 -0400 Subject: [PATCH 01/71] update to allow html readme, fx id page for colors --- public/css/index.css | 4 +++- src/helpers/lanyard.ts | 27 ++++++++++++++------------- src/routes/[id].ts | 14 ++++++++++++-- src/views/index.ejs | 2 +- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/public/css/index.css b/public/css/index.css index ac5f70f..11b05ee 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -494,7 +494,9 @@ ul { /* readme :p */ .readme { - max-width: 700px; + max-width: fit-content; + min-width: 700px; + overflow: hidden; width: 100%; background: var(--readme-bg); padding: 1.5rem; diff --git a/src/helpers/lanyard.ts b/src/helpers/lanyard.ts index de78955..c13ba06 100644 --- a/src/helpers/lanyard.ts +++ b/src/helpers/lanyard.ts @@ -49,11 +49,12 @@ export async function getLanyardData(id?: string): Promise { export async function handleReadMe(data: LanyardData): Promise { const userReadMe: string | null = data.kv?.readme; + const validExtension = /\.(md|markdown|txt|html?)$/i; if ( !userReadMe || - !userReadMe.toLowerCase().endsWith("readme.md") || - !userReadMe.startsWith("http") + !userReadMe.startsWith("http") || + !validExtension.test(userReadMe) ) { return null; } @@ -65,15 +66,7 @@ export async function handleReadMe(data: LanyardData): Promise { }, }); - const contentType: string = res.headers.get("content-type") || ""; - if ( - !res.ok || - !( - contentType.includes("text/markdown") || - contentType.includes("text/plain") - ) - ) - return null; + if (!res.ok) return null; if (res.headers.has("content-length")) { const size: number = Number.parseInt( @@ -86,9 +79,17 @@ export async function handleReadMe(data: LanyardData): Promise { const text: string = await res.text(); if (!text || text.length < 10) return null; - const html: string | null = await marked.parse(text); - const safe: string | null = DOMPurify.sanitize(html); + let html: string; + if ( + userReadMe.toLowerCase().endsWith(".html") || + userReadMe.toLowerCase().endsWith(".htm") + ) { + html = text; + } else { + html = await marked.parse(text); + } + const safe: string | null = DOMPurify.sanitize(html); return safe; } catch { return null; diff --git a/src/routes/[id].ts b/src/routes/[id].ts index 16ea3c0..46e3952 100644 --- a/src/routes/[id].ts +++ b/src/routes/[id].ts @@ -1,3 +1,4 @@ +import { getImageColors } from "@/helpers/colors"; import { lanyardConfig } from "@config/environment"; import { renderEjsTemplate } from "@helpers/ejs"; import { getLanyardData, handleReadMe } from "@helpers/lanyard"; @@ -38,6 +39,14 @@ async function handler(request: ExtendedRequest): Promise { status = presence.discord_status; } + let colors: ImageColorResult | null = null; + if (presence.kv.colors === "true") { + const avatar: string = presence.discord_user.avatar + ? `https://cdn.discordapp.com/avatars/${presence.discord_user.id}/${presence.discord_user.avatar}` + : `https://cdn.discordapp.com/embed/avatars/${presence.discord_user.discriminator || 1 % 5}`; + colors = await getImageColors(avatar, true); + } + const ejsTemplateData: EjsTemplateData = { title: presence.discord_user.global_name || presence.discord_user.username, username: @@ -52,8 +61,9 @@ async function handler(request: ExtendedRequest): Promise { }, instance, readme, - allowSnow: presence.kv.snow || false, - allowRain: presence.kv.rain || false, + allowSnow: presence.kv.snow === "true", + allowRain: presence.kv.rain === "true", + colors: colors?.colors ?? {}, }; return await renderEjsTemplate("index", ejsTemplateData); diff --git a/src/views/index.ejs b/src/views/index.ejs index 0db4f4b..e24109a 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -24,7 +24,7 @@ -<%- include('partial/style.ejs') %> +<%- include("partial/style.ejs") %>
From b109f671255b6972442fe07c33f4671842a590db Mon Sep 17 00:00:00 2001 From: creations Date: Thu, 17 Apr 2025 18:57:45 -0400 Subject: [PATCH 02/71] fix ip log issue, make changes to embed --- src/server.ts | 15 ++++++++------- src/views/index.ejs | 9 +++++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/server.ts b/src/server.ts index fc8d4b5..ebdbed0 100644 --- a/src/server.ts +++ b/src/server.ts @@ -225,17 +225,18 @@ class ServerHandler { ); } - const headers: Headers = response.headers; - let ip: string | null = server.requestIP(request)?.address || null; + const headers = request.headers; + let ip = server.requestIP(request)?.address; - if (!ip) { + if (!ip || ip.startsWith("172.") || ip === "127.0.0.1") { ip = - headers.get("CF-Connecting-IP") || - headers.get("X-Real-IP") || - headers.get("X-Forwarded-For") || - null; + headers.get("CF-Connecting-IP")?.trim() || + headers.get("X-Real-IP")?.trim() || + headers.get("X-Forwarded-For")?.split(",")[0].trim() || + "unknown"; } + logger.custom( `[${request.method}]`, `(${response.status})`, diff --git a/src/views/index.ejs b/src/views/index.ejs index e24109a..5e922c7 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -5,9 +5,14 @@ - + <% + const displayName = username.endsWith('s') ? `${username}'` : `${username}'s`; + const profileUrl = `https://discord.com/users/${user.id}`; + %> + + - + <%= title %> From 7816210a2ce5c99e82cdf55572404ee70d4e3240 Mon Sep 17 00:00:00 2001 From: creations Date: Fri, 18 Apr 2025 04:31:25 -0400 Subject: [PATCH 03/71] add clan badges --- public/css/index.css | 47 +++++++++++++++++++++++++++++++++++++++++++- src/views/index.ejs | 10 +++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/public/css/index.css b/public/css/index.css index 11b05ee..1bcd28d 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -45,7 +45,10 @@ body { .avatar-status-wrapper { display: flex; align-items: center; - gap: 1.5rem; + gap: 2rem; + + width: fit-content; + max-width: 700px; } .avatar-wrapper { @@ -116,6 +119,48 @@ body { flex-direction: column; } +.user-info-inner { + display: flex; + flex-direction: row; + align-items: center; + text-align: center; + gap: .5rem; +} + +.user-info-inner h1 { + font-size: 2rem; + margin: 0; +} + +.clan-badge { + width: 50px; + height: 20px; + border-radius: 8px; + background-color: var(--card-bg); + + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + gap: 0.3rem; + padding: 0.2rem 0.3rem; +} + +.clan-badge img { + width: 20px; + height: 20px; + margin: 0; + padding: 0; +} + +.clan-badge span { + font-size: 1rem; + color: var(--text-color); + margin: 0; + + font-weight: 600; +} + h1 { font-size: 2.5rem; margin: 0; diff --git a/src/views/index.ejs b/src/views/index.ejs index 5e922c7..0736af4 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -48,7 +48,15 @@ <% } %>