add additional data in top scores response
Some checks failed
Deploy Backend / docker (ubuntu-latest) (push) Failing after 31s

This commit is contained in:
Lee 2024-10-29 18:44:21 +00:00
parent f232468fc1
commit 8011ed7b5a

@ -340,13 +340,15 @@ export class ScoreService {
const scores: PlayerScore<ScoreSaberScore, ScoreSaberLeaderboard>[] = []; const scores: PlayerScore<ScoreSaberScore, ScoreSaberLeaderboard>[] = [];
for (const { score: scoreData } of foundScores) { for (const { score: scoreData } of foundScores) {
const score = new ScoreSaberScoreModel(scoreData).toObject() as ScoreSaberScore; const score = new ScoreSaberScoreModel(scoreData).toObject() as ScoreSaberScore;
const leaderboard = await LeaderboardService.getLeaderboard<ScoreSaberLeaderboard>( const leaderboardResponse = await LeaderboardService.getLeaderboard<ScoreSaberLeaderboard>(
"scoresaber", "scoresaber",
score.leaderboardId + "" score.leaderboardId + ""
); );
if (!leaderboard) { if (!leaderboardResponse) {
continue; continue;
} }
const { leaderboard, beatsaver } = leaderboardResponse;
try { try {
const player = await PlayerService.getPlayer(score.playerId); const player = await PlayerService.getPlayer(score.playerId);
if (player !== undefined) { if (player !== undefined) {
@ -361,10 +363,20 @@ export class ScoreService {
}; };
} }
const additionalData = await ScoreService.getAdditionalScoreData(
score.playerId,
leaderboard.songHash,
`${leaderboard.difficulty.difficulty}-${leaderboard.difficulty.characteristic}`,
score.score
);
if (additionalData) {
score.additionalData = additionalData;
}
scores.push({ scores.push({
score: score, score: score,
leaderboard: leaderboard.leaderboard, leaderboard: leaderboard,
beatSaver: leaderboard.beatsaver, beatSaver: beatsaver,
}); });
} }
console.log(`Got ${scores.length} scores in ${Date.now() - before}ms (timeframe: ${timeframe}, limit: ${amount})`); console.log(`Got ${scores.length} scores in ${Date.now() - before}ms (timeframe: ${timeframe}, limit: ${amount})`);