fix player data not showing when claiming the profile
Some checks failed
Deploy Backend / deploy (push) Failing after 1m5s
Deploy Website / deploy (push) Failing after 1m29s

This commit is contained in:
Lee 2024-10-17 02:40:18 +01:00
parent ae4e6912e5
commit 42d133bbbb
5 changed files with 9 additions and 38 deletions

@ -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

@ -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<ScoreSaberPlayer> {
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<{

@ -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({

@ -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;
},

@ -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,
});