mirror of
https://github.com/DeveloLongScript/MHSF.git
synced 2026-05-09 08:05:00 -05:00
Compare commits
7 Commits
53f7cdb171
...
c4b1e41b82
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4b1e41b82 | ||
|
|
ba7737d383 | ||
|
|
119b79d985 | ||
|
|
275f236365 | ||
|
|
7e806cd335 | ||
|
|
17dbc9e751 | ||
|
|
1a05e42996 |
BIN
apps/www/src/app/api/og/fonts/Inter-Medium.ttf
Normal file
BIN
apps/www/src/app/api/og/fonts/Inter-Medium.ttf
Normal file
Binary file not shown.
@ -4,10 +4,13 @@ export async function loadFonts() {
|
|||||||
new URL("./Inter-Regular.ttf", import.meta.url)
|
new URL("./Inter-Regular.ttf", import.meta.url)
|
||||||
).then((res) => res.arrayBuffer());
|
).then((res) => res.arrayBuffer());
|
||||||
|
|
||||||
|
const interMediumFontP = fetch(
|
||||||
|
new URL("./Inter-Medium.ttf", import.meta.url)
|
||||||
|
).then((res) => res.arrayBuffer());
|
||||||
|
|
||||||
const interBoldFontP = fetch(
|
const interBoldFontP = fetch(
|
||||||
new URL("./Inter-Bold.ttf", import.meta.url)
|
new URL("./Inter-Bold.ttf", import.meta.url)
|
||||||
).then((res) => res.arrayBuffer());
|
).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 { ImageResponse } from "@vercel/og";
|
||||||
import { NextRequest } from "next/server";
|
import type { NextRequest } from "next/server";
|
||||||
import { MongoClient } from "mongodb";
|
import { MongoClient } from "mongodb";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
@ -26,6 +26,7 @@ async function loadLocalFonts() {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
fs.readFileSync(path.join(fontPath, "Inter-Regular.ttf")),
|
fs.readFileSync(path.join(fontPath, "Inter-Regular.ttf")),
|
||||||
|
fs.readFileSync(path.join(fontPath, "Inter-Medium.ttf")),
|
||||||
fs.readFileSync(path.join(fontPath, "Inter-Bold.ttf")),
|
fs.readFileSync(path.join(fontPath, "Inter-Bold.ttf")),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -35,11 +36,19 @@ export async function GET(
|
|||||||
{ params }: { params: Promise<{ id: string }> }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
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;
|
const id = (await params).id;
|
||||||
|
|
||||||
// Load fonts
|
// Load fonts
|
||||||
const [interRegular, interBold] = await loadLocalFonts();
|
const [interRegular, interMedium, interBold] = await loadLocalFonts();
|
||||||
|
|
||||||
// Verify server exists
|
// Verify server exists
|
||||||
const serverResponse = await fetch(`https://api.minehut.com/server/${id}`);
|
const serverResponse = await fetch(`https://api.minehut.com/server/${id}`);
|
||||||
@ -60,7 +69,7 @@ export async function GET(
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
backgroundColor: "white",
|
backgroundImage: `url(data:image/png;base64,${bannerImageData.toString("base64")})`,
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
backgroundPosition: "center",
|
backgroundPosition: "center",
|
||||||
fontFamily: "Inter",
|
fontFamily: "Inter",
|
||||||
@ -248,7 +257,7 @@ export async function GET(
|
|||||||
position: "relative",
|
position: "relative",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
fontFamily: "Inter",
|
fontFamily: "Inter",
|
||||||
backgroundColor: "white",
|
backgroundImage: `url(data:image/png;base64,${bannerImageData.toString("base64")})`,
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
backgroundPosition: "center",
|
backgroundPosition: "center",
|
||||||
}}
|
}}
|
||||||
@ -540,6 +549,12 @@ export async function GET(
|
|||||||
style: "normal",
|
style: "normal",
|
||||||
weight: 700,
|
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);
|
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(
|
return new ImageResponse(
|
||||||
(
|
(
|
||||||
<div
|
<div
|
||||||
@ -562,6 +592,7 @@ export async function GET(
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
fontSize: 60,
|
fontSize: 60,
|
||||||
color: "white",
|
color: "white",
|
||||||
|
background: bannerImageData ? undefined : "#121212",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
padding: "50px 50px",
|
padding: "50px 50px",
|
||||||
@ -569,7 +600,11 @@ export async function GET(
|
|||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
fontFamily: "Inter",
|
fontFamily: "Inter",
|
||||||
backgroundColor: "white"
|
...(bannerImageData && {
|
||||||
|
backgroundImage: `url(data:image/png;base64,${bannerImageData.toString("base64")})`,
|
||||||
|
backgroundSize: "cover",
|
||||||
|
backgroundPosition: "center",
|
||||||
|
}),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { NextRequest } from "next/server";
|
|||||||
import { miniMessage } from "minimessage-js";
|
import { miniMessage } from "minimessage-js";
|
||||||
import { loadFonts } from "../../fonts";
|
import { loadFonts } from "../../fonts";
|
||||||
|
|
||||||
export const runtime = "edge";
|
// export const runtime = "edge";
|
||||||
|
|
||||||
// Function to parse MiniMessage and create JSX elements with styling
|
// Function to parse MiniMessage and create JSX elements with styling
|
||||||
function parseMotdToJsx(text: string) {
|
function parseMotdToJsx(text: string) {
|
||||||
@ -128,11 +128,15 @@ export async function GET(
|
|||||||
{ params }: { params: Promise<{ id: string }> }
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
) {
|
) {
|
||||||
try {
|
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;
|
const id = (await params).id;
|
||||||
|
|
||||||
// Load fonts
|
// Load fonts
|
||||||
const [interRegular, interBold] = await loadFonts();
|
const [interRegular, interMedium, interBold] = await loadFonts();
|
||||||
|
|
||||||
// Fetch server data
|
// Fetch server data
|
||||||
const response = await fetch(`https://api.minehut.com/server/${id}`);
|
const response = await fetch(`https://api.minehut.com/server/${id}`);
|
||||||
@ -154,6 +158,7 @@ export async function GET(
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
backgroundImage: `url(data:image/png;base64,${Buffer.from(bannerImageData).toString("base64")})`,
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
backgroundPosition: "center",
|
backgroundPosition: "center",
|
||||||
fontFamily: "Inter",
|
fontFamily: "Inter",
|
||||||
@ -221,7 +226,7 @@ export async function GET(
|
|||||||
position: "relative",
|
position: "relative",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
fontFamily: "Inter",
|
fontFamily: "Inter",
|
||||||
backgroundColor: "white",
|
backgroundImage: `url(data:image/png;base64,${Buffer.from(bannerImageData).toString("base64")})`,
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
backgroundPosition: "center",
|
backgroundPosition: "center",
|
||||||
}}
|
}}
|
||||||
@ -412,15 +417,30 @@ export async function GET(
|
|||||||
data: interBold,
|
data: interBold,
|
||||||
style: "normal",
|
style: "normal",
|
||||||
weight: 700,
|
weight: 700,
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
name: "Inter",
|
||||||
|
data: interMedium,
|
||||||
|
style: "normal",
|
||||||
|
weight: 500,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const [interRegular, interBold] = await loadFonts();
|
const [interRegular, interMedium, interBold] = await loadFonts();
|
||||||
console.error("Error generating OG image:", error);
|
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(
|
return new ImageResponse(
|
||||||
(
|
(
|
||||||
@ -429,7 +449,7 @@ export async function GET(
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
fontSize: 60,
|
fontSize: 60,
|
||||||
color: "white",
|
color: "white",
|
||||||
background: "#121212",
|
background: bannerImageData ? undefined : "#121212",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
padding: "50px 50px",
|
padding: "50px 50px",
|
||||||
@ -437,7 +457,11 @@ export async function GET(
|
|||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
fontFamily: "Inter",
|
fontFamily: "Inter",
|
||||||
backgroundColor: "white",
|
...(bannerImageData && {
|
||||||
|
backgroundImage: `url(data:image/png;base64,${Buffer.from(bannerImageData).toString("base64")})`,
|
||||||
|
backgroundSize: "cover",
|
||||||
|
backgroundPosition: "center",
|
||||||
|
}),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div style={{ display: "flex" }}>
|
<div style={{ display: "flex" }}>
|
||||||
|
|||||||
@ -103,7 +103,6 @@ export function ServerList() {
|
|||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
<TooltipContent
|
<TooltipContent
|
||||||
side="bottom"
|
side="bottom"
|
||||||
className="backdrop-blur bg-transparent text-black dark:text-white "
|
|
||||||
>
|
>
|
||||||
{filterCount} modification(s) enabled
|
{filterCount} modification(s) enabled
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
|
|||||||
@ -61,6 +61,7 @@ export function useFilters(data: OnlineServer[]) {
|
|||||||
const { user, isSignedIn } = useUser();
|
const { user, isSignedIn } = useUser();
|
||||||
|
|
||||||
const updateServers = async (newFilters: EmbeddedFilter[]) => {
|
const updateServers = async (newFilters: EmbeddedFilter[]) => {
|
||||||
|
if (newFilters.length === 0) setFilteredData(data);
|
||||||
const modificationMap = await Promise.all(data.map((v) =>
|
const modificationMap = await Promise.all(data.map((v) =>
|
||||||
Promise.all(newFilters.map(async (c) => c.functionFilter(v))),
|
Promise.all(newFilters.map(async (c) => c.functionFilter(v))),
|
||||||
));
|
));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user