From 42d133bbbb5be46e817ce40426e96a862e0e82f7 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 17 Oct 2024 02:40:18 +0100 Subject: [PATCH] fix player data not showing when claiming the profile --- .gitea/workflows/!-fix-bun-lock-file.yml | 29 ------------------- .../types/player/impl/scoresaber-player.ts | 9 ++++-- .../src/app/(pages)/player/[...slug]/page.tsx | 3 +- .../website/src/components/api/api-health.tsx | 2 +- .../src/components/player/player-data.tsx | 4 +-- 5 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 .gitea/workflows/!-fix-bun-lock-file.yml diff --git a/.gitea/workflows/!-fix-bun-lock-file.yml b/.gitea/workflows/!-fix-bun-lock-file.yml deleted file mode 100644 index be427d5..0000000 --- a/.gitea/workflows/!-fix-bun-lock-file.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Fix bun lock file (Renovate) - -on: - workflow_dispatch: - push: - branches-ignore: - - master - paths: - - '**/package.json' # Detect changes in any package.json file in any directory - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install bun - uses: oven-sh/setup-bun@v2 - - - name: Install dependencies - run: bun install - - - name: Commit bun lock file - run: | - git config --global user.email "helper@fascinated.cc" - git config --global user.name "Bun Fixer" - git add bun.lockb - git commit -m "Fix bun lock file" - git push \ No newline at end of file diff --git a/projects/common/src/types/player/impl/scoresaber-player.ts b/projects/common/src/types/player/impl/scoresaber-player.ts index fe04345..d6c8d61 100644 --- a/projects/common/src/types/player/impl/scoresaber-player.ts +++ b/projects/common/src/types/player/impl/scoresaber-player.ts @@ -4,6 +4,9 @@ import { PlayerHistory } from "../player-history"; import ScoreSaberPlayerToken from "../../token/scoresaber/score-saber-player-token"; import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../../utils/time-utils"; import { getPageFromRank } from "../../../utils/utils"; +import { getCookieValue } from "website/src/common/cookie-utils"; +import { db } from "website/src/common/database/database"; +import { isServer } from "@tanstack/react-query"; /** * A ScoreSaber player. @@ -76,12 +79,10 @@ 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, - playerIdCookie?: string + apiUrl: string ): Promise { const bio: ScoreSaberBio = { lines: token.bio?.split("\n") || [], @@ -99,6 +100,8 @@ export async function getScoreSaberPlayerFromToken( let isBeingTracked = false; const todayDate = formatDateMinimal(getMidnightAlignedDate(new Date())); let statisticHistory: { [key: string]: PlayerHistory } = {}; + + const playerIdCookie = isServer ? await getCookieValue("playerId") : (await db.getSettings())?.playerId; try { const { statistics: history } = await ky .get<{ diff --git a/projects/website/src/app/(pages)/player/[...slug]/page.tsx b/projects/website/src/app/(pages)/player/[...slug]/page.tsx index 6a47a16..a3dd4a6 100644 --- a/projects/website/src/app/(pages)/player/[...slug]/page.tsx +++ b/projects/website/src/app/(pages)/player/[...slug]/page.tsx @@ -55,8 +55,7 @@ const getPlayerData = async ({ params }: Props, fetchScores: boolean = true): Pr } const playerToken = await scoresaberService.lookupPlayer(id); - const player = - playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi, await getCookieValue("playerId"))); + const player = playerToken && (await getScoreSaberPlayerFromToken(playerToken, config.siteApi)); let scores: ScoreSaberPlayerScoresPageToken | undefined; if (fetchScores) { scores = await scoresaberService.lookupPlayerScores({ diff --git a/projects/website/src/components/api/api-health.tsx b/projects/website/src/components/api/api-health.tsx index 318eec0..c84bc92 100644 --- a/projects/website/src/components/api/api-health.tsx +++ b/projects/website/src/components/api/api-health.tsx @@ -16,7 +16,7 @@ export function ApiHealth() { useQuery({ queryKey: ["api-health"], queryFn: async () => { - const status = (await getApiHealth(config.siteApi)).online; + const status = (await getApiHealth(config.siteApi + "/health")).online; setOnline(status); return status; }, diff --git a/projects/website/src/components/player/player-data.tsx b/projects/website/src/components/player/player-data.tsx index f5cd453..f2b30d5 100644 --- a/projects/website/src/components/player/player-data.tsx +++ b/projects/website/src/components/player/player-data.tsx @@ -17,7 +17,6 @@ import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; import { config } from "../../../config"; import useDatabase from "@/hooks/use-database"; import { useLiveQuery } from "dexie-react-hooks"; -import { getCookieValue } from "@/common/cookie-utils"; const REFRESH_INTERVAL = 1000 * 60 * 5; @@ -50,9 +49,8 @@ export default function PlayerData({ if (playerResponse == undefined) { return undefined; } - return await getScoreSaberPlayerFromToken(playerResponse, config.siteApi, await getCookieValue("playerId")); + return await getScoreSaberPlayerFromToken(playerResponse, config.siteApi); }, - staleTime: REFRESH_INTERVAL, refetchInterval: REFRESH_INTERVAL, refetchIntervalInBackground: false, });