src
app
components
schemas/scoresaber
utils/scoresaber
32
src/app/api/beatsaver/mapdata/route.ts
Normal file
32
src/app/api/beatsaver/mapdata/route.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { BeatsaverMap } from "@/schemas/beatsaver/BeatsaverMap";
|
||||
import { BeatsaverAPI } from "@/utils/beatsaver/api";
|
||||
|
||||
const mapCache = new Map<string, BeatsaverMap>();
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const mapHashes = searchParams.get("hashes")?.split(",") ?? undefined;
|
||||
if (!mapHashes) {
|
||||
return new Response("mapHashes parameter is required", { status: 400 });
|
||||
}
|
||||
const idOnly = searchParams.get("idonly") === "true";
|
||||
|
||||
const maps: Record<string, BeatsaverMap | { id: string }> = {};
|
||||
for (const mapHash of mapHashes) {
|
||||
if (mapCache.has(mapHash)) {
|
||||
maps[mapHash] = mapCache.get(mapHash)!;
|
||||
} else {
|
||||
const map = await BeatsaverAPI.fetchMapByHash(mapHash);
|
||||
if (map) {
|
||||
maps[mapHash] = map;
|
||||
}
|
||||
if (map && idOnly) {
|
||||
maps[mapHash] = { id: map.id };
|
||||
}
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(maps), {
|
||||
headers: { "content-type": "application/json;charset=UTF-8" },
|
||||
});
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import clsx from "clsx";
|
||||
import { Metadata, Viewport } from "next";
|
||||
import { Inter } from "next/font/google";
|
||||
import Script from "next/script";
|
||||
|
||||
import "react-toastify/dist/ReactToastify.css";
|
||||
import "./globals.css";
|
||||
|
||||
|
@ -69,7 +69,12 @@ export async function generateMetadata({
|
||||
*/
|
||||
async function getData(id: string, page: number, sort: string) {
|
||||
const playerData = await ScoreSaberAPI.fetchPlayerData(id);
|
||||
const playerScores = await ScoreSaberAPI.fetchScores(id, page, sort, 10);
|
||||
const playerScores = await ScoreSaberAPI.fetchScoresWithBeatsaverData(
|
||||
id,
|
||||
page,
|
||||
sort,
|
||||
10,
|
||||
);
|
||||
return {
|
||||
playerData: playerData,
|
||||
playerScores: playerScores,
|
||||
|
Reference in New Issue
Block a user