add map stats from beat saver
Some checks failed
Deploy Backend / docker (ubuntu-latest) (push) Successful in 47s
Deploy Website / docker (ubuntu-latest) (push) Failing after 1m34s

This commit is contained in:
Lee
2024-10-23 15:33:25 +01:00
parent 62090b8054
commit 33b931b5f1
47 changed files with 835 additions and 289 deletions

View File

@ -1,5 +1,5 @@
import { beatsaverService } from "@ssr/common/service/impl/beatsaver";
import { BeatSaverMap, BeatSaverMapModel } from "@ssr/common/model/beatsaver/beatsaver-map";
import { BeatSaverMap, BeatSaverMapModel } from "@ssr/common/model/beatsaver/map";
export default class BeatSaverService {
/**
@ -12,28 +12,71 @@ export default class BeatSaverService {
let map = await BeatSaverMapModel.findById(hash);
if (map != undefined) {
const toObject = map.toObject() as BeatSaverMap;
if (toObject.unknownMap) {
if (toObject.notFound) {
return undefined;
}
return toObject;
}
const token = await beatsaverService.lookupMap(hash);
const uploader = token?.uploader;
const metadata = token?.metadata;
map = await BeatSaverMapModel.create(
token
? {
token && uploader && metadata
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
({
_id: hash,
bsr: token.id,
name: token.name,
description: token.description,
author: {
id: token.uploader.id,
id: uploader.id,
name: uploader.name,
avatar: uploader.avatar,
},
}
metadata: {
bpm: metadata.bpm,
duration: metadata.duration,
levelAuthorName: metadata.levelAuthorName,
songAuthorName: metadata.songAuthorName,
songName: metadata.songName,
songSubName: metadata.songSubName,
},
versions: token.versions.map(version => {
return {
hash: version.hash.toUpperCase(),
difficulties: version.diffs.map(diff => {
return {
njs: diff.njs,
offset: diff.offset,
notes: diff.notes,
bombs: diff.bombs,
obstacles: diff.obstacles,
nps: diff.nps,
characteristic: diff.characteristic,
difficulty: diff.difficulty,
events: diff.events,
chroma: diff.chroma,
mappingExtensions: diff.me,
noodleExtensions: diff.ne,
cinema: diff.cinema,
maxScore: diff.maxScore,
label: diff.label,
};
}),
createdAt: new Date(version.createdAt),
};
}),
lastRefreshed: new Date(),
} as BeatSaverMap)
: {
_id: hash,
unknownMap: true,
notFound: true,
}
);
if (map.unknownMap) {
if (map.notFound) {
return undefined;
}
return map.toObject() as BeatSaverMap;

View File

@ -7,7 +7,7 @@ import ScoreSaberLeaderboardToken from "@ssr/common/types/token/scoresaber/score
import { NotFoundError } from "elysia";
import { getScoreSaberLeaderboardFromToken } from "@ssr/common/leaderboard/impl/scoresaber-leaderboard";
import BeatSaverService from "./beatsaver.service";
import { BeatSaverMap } from "@ssr/common/model/beatsaver/beatsaver-map";
import { BeatSaverMap } from "@ssr/common/model/beatsaver/map";
const leaderboardCache = new SSRCache({
ttl: 1000 * 60 * 60 * 24,

View File

@ -13,7 +13,7 @@ import { ScoreSort } from "@ssr/common/score/score-sort";
import { Leaderboards } from "@ssr/common/leaderboard";
import Leaderboard from "@ssr/common/leaderboard/leaderboard";
import LeaderboardService from "./leaderboard.service";
import { BeatSaverMap } from "@ssr/common/model/beatsaver/beatsaver-map";
import { BeatSaverMap } from "@ssr/common/model/beatsaver/map";
import { PlayerScore } from "@ssr/common/score/player-score";
import LeaderboardScoresResponse from "@ssr/common/response/leaderboard-scores-response";
import Score from "@ssr/common/score/score";
@ -188,7 +188,7 @@ export class ScoreService {
};
const difficulty = leaderboard.difficulty;
const difficultyKey = `${difficulty.difficultyName.replace("Plus", "+")}-${difficulty.modeName}`;
const difficultyKey = `${difficulty.difficultyName}-${difficulty.modeName}`;
const rawScoreImprovement = score.scoreImprovement;
const data = {
playerId: playerId,
@ -312,15 +312,15 @@ export class ScoreService {
if (score == undefined) {
continue;
}
const tokenLeaderboard = getScoreSaberLeaderboardFromToken(token.leaderboard);
if (tokenLeaderboard == undefined) {
const leaderboard = getScoreSaberLeaderboardFromToken(token.leaderboard);
if (leaderboard == undefined) {
continue;
}
const additionalData = await this.getAdditionalScoreData(
id,
tokenLeaderboard.songHash,
`${tokenLeaderboard.difficulty.difficulty}-${tokenLeaderboard.difficulty.gameMode}`,
leaderboard.songHash,
`${leaderboard.difficulty.difficulty}-${leaderboard.difficulty.characteristic}`,
score.score
);
if (additionalData !== undefined) {
@ -329,8 +329,8 @@ export class ScoreService {
scores.push({
score: score,
leaderboard: tokenLeaderboard,
beatSaver: await BeatSaverService.getMap(tokenLeaderboard.songHash),
leaderboard: leaderboard,
beatSaver: await BeatSaverService.getMap(leaderboard.songHash),
});
}
break;