Compare commits

..

7 Commits

Author SHA1 Message Date
dvelo
c4b1e41b82 fix: i need new friends 2025-05-05 20:58:29 -05:00
dvelo
ba7737d383 fix: make servers show up even with no filters 2025-05-05 20:47:39 -05:00
dvelo
119b79d985 fix: move off of edge runtime 2025-05-05 20:20:01 -05:00
dvelo
275f236365 Revert "fix: remove medium to make endpoint smaller"
This reverts commit 7497ca7df1a58d101d451804789f722710519529.
2025-05-05 20:19:09 -05:00
dvelo
7e806cd335 Revert "fix: don't load banner locally"
This reverts commit b35f04020d318b67908fe1723a66be0b2b6e8716.
2025-05-05 20:19:01 -05:00
dvelo
17dbc9e751 Revert "fix: ig no banners?"
This reverts commit 76ebc9405624265888d16578c56f3b3cff228f30.
2025-05-05 20:18:59 -05:00
dvelo
1a05e42996 Revert "fix: p.2"
This reverts commit 53f7cdb171ea2fab272108c3ee6b7e67d4b479ae.
2025-05-05 20:18:57 -05:00
6 changed files with 77 additions and 15 deletions

Binary file not shown.

@ -4,10 +4,13 @@ export async function loadFonts() {
new URL("./Inter-Regular.ttf", import.meta.url)
).then((res) => res.arrayBuffer());
const interMediumFontP = fetch(
new URL("./Inter-Medium.ttf", import.meta.url)
).then((res) => res.arrayBuffer());
const interBoldFontP = fetch(
new URL("./Inter-Bold.ttf", import.meta.url)
).then((res) => res.arrayBuffer());
return Promise.all([interRegularFontP, interBoldFontP]);
return Promise.all([interRegularFontP, interMediumFontP, interBoldFontP]);
}

@ -1,5 +1,5 @@
import { ImageResponse } from "@vercel/og";
import { NextRequest } from "next/server";
import type { NextRequest } from "next/server";
import { MongoClient } from "mongodb";
import fs from "node:fs";
import path from "node:path";
@ -26,6 +26,7 @@ async function loadLocalFonts() {
return [
fs.readFileSync(path.join(fontPath, "Inter-Regular.ttf")),
fs.readFileSync(path.join(fontPath, "Inter-Medium.ttf")),
fs.readFileSync(path.join(fontPath, "Inter-Bold.ttf")),
];
}
@ -35,11 +36,19 @@ export async function GET(
{ params }: { params: Promise<{ id: string }> }
) {
try {
// Load banner image from filesystem
const bannerPath = path.join(
process.cwd(),
"public",
"branding",
"bg-banner.png"
);
const bannerImageData = fs.readFileSync(bannerPath);
const id = (await params).id;
// Load fonts
const [interRegular, interBold] = await loadLocalFonts();
const [interRegular, interMedium, interBold] = await loadLocalFonts();
// Verify server exists
const serverResponse = await fetch(`https://api.minehut.com/server/${id}`);
@ -60,7 +69,7 @@ export async function GET(
textAlign: "center",
justifyContent: "center",
alignItems: "center",
backgroundColor: "white",
backgroundImage: `url(data:image/png;base64,${bannerImageData.toString("base64")})`,
backgroundSize: "cover",
backgroundPosition: "center",
fontFamily: "Inter",
@ -248,7 +257,7 @@ export async function GET(
position: "relative",
overflow: "hidden",
fontFamily: "Inter",
backgroundColor: "white",
backgroundImage: `url(data:image/png;base64,${bannerImageData.toString("base64")})`,
backgroundSize: "cover",
backgroundPosition: "center",
}}
@ -540,6 +549,12 @@ export async function GET(
style: "normal",
weight: 700,
},
{
name: "Inter",
data: interMedium,
style: "normal",
weight: 500,
},
],
}
);
@ -555,6 +570,21 @@ export async function GET(
console.error("Failed to load fonts for error page:", e);
}
// Try to load the banner image
let bannerImageData: Buffer | null = null;
try {
const bannerPath = path.join(
process.cwd(),
"public",
"branding",
"dark-banner.png"
);
bannerImageData = fs.readFileSync(bannerPath);
} catch (e) {
// If banner image fails to load, use a solid color background
console.error("Failed to load banner image for error page:", e);
}
return new ImageResponse(
(
<div
@ -562,6 +592,7 @@ export async function GET(
display: "flex",
fontSize: 60,
color: "white",
background: bannerImageData ? undefined : "#121212",
width: "100%",
height: "100%",
padding: "50px 50px",
@ -569,7 +600,11 @@ export async function GET(
justifyContent: "center",
alignItems: "center",
fontFamily: "Inter",
backgroundColor: "white"
...(bannerImageData && {
backgroundImage: `url(data:image/png;base64,${bannerImageData.toString("base64")})`,
backgroundSize: "cover",
backgroundPosition: "center",
}),
}}
>
<div

@ -4,7 +4,7 @@ import { NextRequest } from "next/server";
import { miniMessage } from "minimessage-js";
import { loadFonts } from "../../fonts";
export const runtime = "edge";
// export const runtime = "edge";
// Function to parse MiniMessage and create JSX elements with styling
function parseMotdToJsx(text: string) {
@ -128,11 +128,15 @@ export async function GET(
{ params }: { params: Promise<{ id: string }> }
) {
try {
// Load banner image
const bannerImageData = await fetch(
new URL("/branding/bg-banner.png", request.url)
).then((res) => res.arrayBuffer());
const id = (await params).id;
// Load fonts
const [interRegular, interBold] = await loadFonts();
const [interRegular, interMedium, interBold] = await loadFonts();
// Fetch server data
const response = await fetch(`https://api.minehut.com/server/${id}`);
@ -154,6 +158,7 @@ export async function GET(
textAlign: "center",
justifyContent: "center",
alignItems: "center",
backgroundImage: `url(data:image/png;base64,${Buffer.from(bannerImageData).toString("base64")})`,
backgroundSize: "cover",
backgroundPosition: "center",
fontFamily: "Inter",
@ -221,7 +226,7 @@ export async function GET(
position: "relative",
overflow: "hidden",
fontFamily: "Inter",
backgroundColor: "white",
backgroundImage: `url(data:image/png;base64,${Buffer.from(bannerImageData).toString("base64")})`,
backgroundSize: "cover",
backgroundPosition: "center",
}}
@ -412,15 +417,30 @@ export async function GET(
data: interBold,
style: "normal",
weight: 700,
}
},
{
name: "Inter",
data: interMedium,
style: "normal",
weight: 500,
},
],
}
);
} catch (error) {
const [interRegular, interBold] = await loadFonts();
const [interRegular, interMedium, interBold] = await loadFonts();
console.error("Error generating OG image:", error);
// Try to load the banner image again in case it failed earlier
let bannerImageData: ArrayBuffer | undefined;
try {
bannerImageData = await fetch(
new URL("/branding/dark-banner.png", request.url)
).then((res) => res.arrayBuffer());
} catch (e) {
// If banner image fails to load, use a solid color background
console.error("Failed to load banner image for error page:", e);
}
return new ImageResponse(
(
@ -429,7 +449,7 @@ export async function GET(
display: "flex",
fontSize: 60,
color: "white",
background: "#121212",
background: bannerImageData ? undefined : "#121212",
width: "100%",
height: "100%",
padding: "50px 50px",
@ -437,7 +457,11 @@ export async function GET(
justifyContent: "center",
alignItems: "center",
fontFamily: "Inter",
backgroundColor: "white",
...(bannerImageData && {
backgroundImage: `url(data:image/png;base64,${Buffer.from(bannerImageData).toString("base64")})`,
backgroundSize: "cover",
backgroundPosition: "center",
}),
}}
>
<div style={{ display: "flex" }}>

@ -103,7 +103,6 @@ export function ServerList() {
</TooltipTrigger>
<TooltipContent
side="bottom"
className="backdrop-blur bg-transparent text-black dark:text-white "
>
{filterCount} modification(s) enabled
</TooltipContent>

@ -61,6 +61,7 @@ export function useFilters(data: OnlineServer[]) {
const { user, isSignedIn } = useUser();
const updateServers = async (newFilters: EmbeddedFilter[]) => {
if (newFilters.length === 0) setFilteredData(data);
const modificationMap = await Promise.all(data.map((v) =>
Promise.all(newFilters.map(async (c) => c.functionFilter(v))),
));