diff --git a/projects/common/src/types/player/impl/scoresaber-player.ts b/projects/common/src/types/player/impl/scoresaber-player.ts index 56c07b0..4b6d4f4 100644 --- a/projects/common/src/types/player/impl/scoresaber-player.ts +++ b/projects/common/src/types/player/impl/scoresaber-player.ts @@ -3,7 +3,6 @@ import ky from "ky"; import { PlayerHistory } from "../player-history"; import ScoreSaberPlayerToken from "../../token/scoresaber/score-saber-player-token"; import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../../utils/time-utils"; -import { getPlayerIdCookie } from "website/src/common/website-utils"; /** * A ScoreSaber player. @@ -71,10 +70,12 @@ export default interface ScoreSaberPlayer extends Player { * * @param token the player token * @param apiUrl the api url for SSR + * @param playerIdCookie the player id cookie (doesn't need to be set) */ export async function getScoreSaberPlayerFromToken( token: ScoreSaberPlayerToken, - apiUrl: string + apiUrl: string, + playerIdCookie?: string ): Promise { const bio: ScoreSaberBio = { lines: token.bio?.split("\n") || [], @@ -96,7 +97,7 @@ export async function getScoreSaberPlayerFromToken( const { statistics: history } = await ky .get<{ statistics: { [key: string]: PlayerHistory }; - }>(`${apiUrl}/player/history/${token.id}${getPlayerIdCookie() == token.id ? "?createIfMissing=true" : ""}`) + }>(`${apiUrl}/player/history/${token.id}${playerIdCookie == token.id ? "?createIfMissing=true" : ""}`) .json(); if (history === undefined || Object.entries(history).length === 0) { console.log("Player has no history, using fallback"); diff --git a/projects/website/src/app/(pages)/player/[...slug]/page.tsx b/projects/website/src/app/(pages)/player/[...slug]/page.tsx index b9d9ba4..0513d36 100644 --- a/projects/website/src/app/(pages)/player/[...slug]/page.tsx +++ b/projects/website/src/app/(pages)/player/[...slug]/page.tsx @@ -11,6 +11,7 @@ import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; import ScoreSaberPlayerScoresPageToken from "@ssr/common/types/token/scoresaber/score-saber-player-scores-page-token"; import { getScoreSaberPlayerFromToken } from "@ssr/common/types/player/impl/scoresaber-player"; import { config } from "../../../../../config"; +import { getPlayerIdCookie } from "@/common/website-utils"; const UNKNOWN_PLAYER = { title: "ScoreSaber Reloaded - Unknown Player", @@ -41,7 +42,7 @@ const getPlayerData = cache(async ({ params }: Props, fetchScores: boolean = tru const search = (slug[3] as string) || ""; // The search query const playerToken = await scoresaberService.lookupPlayer(id); - const player = playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi)); + const player = playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi, getPlayerIdCookie())); let scores: ScoreSaberPlayerScoresPageToken | undefined; if (fetchScores) { scores = await scoresaberService.lookupPlayerScores({ diff --git a/projects/website/src/components/player/player-data.tsx b/projects/website/src/components/player/player-data.tsx index 9b6a0eb..7e4fb51 100644 --- a/projects/website/src/components/player/player-data.tsx +++ b/projects/website/src/components/player/player-data.tsx @@ -15,6 +15,7 @@ import ScoreSaberPlayerScoresPageToken from "@ssr/common/types/token/scoresaber/ import { ScoreSort } from "@ssr/common/types/score/score-sort"; import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; import { config } from "../../../config"; +import { getPlayerIdCookie } from "@/common/website-utils"; type Props = { initialPlayerData: ScoreSaberPlayer; @@ -43,7 +44,7 @@ export default function PlayerData({ if (playerResponse == undefined) { return undefined; } - return await getScoreSaberPlayerFromToken(playerResponse, config.siteApi); + return await getScoreSaberPlayerFromToken(playerResponse, config.siteApi, getPlayerIdCookie()); }, staleTime: 1000 * 60 * 5, // Cache data for 5 minutes });