From 4be0b072b254c2211db640072c1578c80f8b728e Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 27 Oct 2024 13:30:51 +0000 Subject: [PATCH] fix player embed image not updating (maybe?) --- projects/common/src/{utils => }/curve-point.ts | 0 projects/common/src/service/impl/scoresaber.ts | 2 +- projects/common/src/utils/string.util.ts | 14 ++++++++++++++ .../src/app/(pages)/player/[...slug]/page.tsx | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-) rename projects/common/src/{utils => }/curve-point.ts (100%) create mode 100644 projects/common/src/utils/string.util.ts diff --git a/projects/common/src/utils/curve-point.ts b/projects/common/src/curve-point.ts similarity index 100% rename from projects/common/src/utils/curve-point.ts rename to projects/common/src/curve-point.ts diff --git a/projects/common/src/service/impl/scoresaber.ts b/projects/common/src/service/impl/scoresaber.ts index 0896026..ee2c869 100644 --- a/projects/common/src/service/impl/scoresaber.ts +++ b/projects/common/src/service/impl/scoresaber.ts @@ -7,7 +7,7 @@ import ScoreSaberPlayerScoresPageToken from "../../types/token/scoresaber/score- import ScoreSaberLeaderboardToken from "../../types/token/scoresaber/score-saber-leaderboard-token"; import ScoreSaberLeaderboardScoresPageToken from "../../types/token/scoresaber/score-saber-leaderboard-scores-page-token"; import { clamp, lerp } from "../../utils/math-utils"; -import { CurvePoint } from "../../utils/curve-point"; +import { CurvePoint } from "../../curve-point"; import { SSRCache } from "../../cache"; const API_BASE = "https://scoresaber.com/api"; diff --git a/projects/common/src/utils/string.util.ts b/projects/common/src/utils/string.util.ts new file mode 100644 index 0000000..142b42b --- /dev/null +++ b/projects/common/src/utils/string.util.ts @@ -0,0 +1,14 @@ +/** + * Generates a random string + * + * @param length the length of the string + * @returns the random string + */ +export function randomString(length: number) { + const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + let result = ""; + for (let i = 0; i < length; i++) { + result += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return result; +} diff --git a/projects/website/src/app/(pages)/player/[...slug]/page.tsx b/projects/website/src/app/(pages)/player/[...slug]/page.tsx index 81da0cc..fa34ac4 100644 --- a/projects/website/src/app/(pages)/player/[...slug]/page.tsx +++ b/projects/website/src/app/(pages)/player/[...slug]/page.tsx @@ -14,6 +14,7 @@ import { fetchPlayerScores } from "@ssr/common/utils/score-utils"; import PlayerScoresResponse from "@ssr/common/response/player-scores-response"; import { getScoreSaberPlayerFromToken } from "@ssr/common/token-creators"; import { cache } from "react"; +import { randomString } from "@ssr/common/utils/string.util"; const UNKNOWN_PLAYER = { title: "ScoreSaber Reloaded - Unknown Player", @@ -91,7 +92,7 @@ export async function generateMetadata(props: Props): Promise { description: `Click here to view the scores for ${player.name}!`, images: [ { - url: `${Config.apiUrl}/image/player/${player.id}`, + url: `${Config.apiUrl}/image/player/${player.id}?id=${randomString(8)}`, }, ], },