move score page fetching to the backend
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
import Leaderboard from "../leaderboard";
|
||||
import LeaderboardDifficulty from "../leaderboard-difficulty";
|
||||
import ScoreSaberLeaderboardToken from "../../types/token/scoresaber/score-saber-leaderboard-token";
|
||||
import { getDifficultyFromScoreSaberDifficulty } from "../../utils/scoresaber-utils";
|
||||
import { parseDate } from "../../utils/time-utils";
|
||||
|
||||
export default interface ScoreSaberLeaderboard extends Leaderboard {
|
||||
/**
|
||||
* The star count for the leaderboard.
|
||||
*/
|
||||
readonly stars: number;
|
||||
|
||||
/**
|
||||
* The total amount of plays.
|
||||
*/
|
||||
readonly plays: number;
|
||||
|
||||
/**
|
||||
* The amount of plays today.
|
||||
*/
|
||||
readonly dailyPlays: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a {@link ScoreSaberLeaderboardToken} into a {@link ScoreSaberLeaderboard}.
|
||||
*
|
||||
* @param token the token to parse
|
||||
*/
|
||||
export function getScoreSaberLeaderboardFromToken(token: ScoreSaberLeaderboardToken): ScoreSaberLeaderboard {
|
||||
const difficulty: LeaderboardDifficulty = {
|
||||
leaderboardId: token.difficulty.leaderboardId,
|
||||
difficulty: getDifficultyFromScoreSaberDifficulty(token.difficulty.difficulty),
|
||||
gameMode: token.difficulty.gameMode,
|
||||
difficultyRaw: token.difficulty.difficultyRaw,
|
||||
};
|
||||
return {
|
||||
id: token.id,
|
||||
songHash: token.songHash,
|
||||
songName: token.songName,
|
||||
songSubName: token.songSubName,
|
||||
songAuthorName: token.songAuthorName,
|
||||
levelAuthorName: token.levelAuthorName,
|
||||
difficulty: difficulty,
|
||||
difficulties:
|
||||
token.difficulties != undefined && token.difficulties.length > 0
|
||||
? token.difficulties.map(difficulty => {
|
||||
return {
|
||||
leaderboardId: difficulty.leaderboardId,
|
||||
difficulty: getDifficultyFromScoreSaberDifficulty(difficulty.difficulty),
|
||||
gameMode: difficulty.gameMode,
|
||||
difficultyRaw: difficulty.difficultyRaw,
|
||||
};
|
||||
})
|
||||
: [difficulty],
|
||||
maxScore: token.maxScore,
|
||||
ranked: token.ranked,
|
||||
songArt: token.coverImage,
|
||||
timestamp: parseDate(token.createdDate),
|
||||
stars: token.stars,
|
||||
plays: token.plays,
|
||||
dailyPlays: token.dailyPlays,
|
||||
};
|
||||
}
|
23
projects/common/src/leaderboard/leaderboard-difficulty.ts
Normal file
23
projects/common/src/leaderboard/leaderboard-difficulty.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Difficulty } from "../score/difficulty";
|
||||
|
||||
export default interface LeaderboardDifficulty {
|
||||
/**
|
||||
* The id of the leaderboard.
|
||||
*/
|
||||
leaderboardId: number;
|
||||
|
||||
/**
|
||||
* The difficulty of the leaderboard.
|
||||
*/
|
||||
difficulty: Difficulty;
|
||||
|
||||
/**
|
||||
* The game mode of the leaderboard.
|
||||
*/
|
||||
gameMode: string;
|
||||
|
||||
/**
|
||||
* The raw difficulty of the leaderboard.
|
||||
*/
|
||||
difficultyRaw: string;
|
||||
}
|
75
projects/common/src/leaderboard/leaderboard.ts
Normal file
75
projects/common/src/leaderboard/leaderboard.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import LeaderboardDifficulty from "./leaderboard-difficulty";
|
||||
|
||||
export default interface Leaderboard {
|
||||
/**
|
||||
* The id of the leaderboard.
|
||||
* @private
|
||||
*/
|
||||
readonly id: number;
|
||||
|
||||
/**
|
||||
* The hash of the song this leaderboard is for.
|
||||
* @private
|
||||
*/
|
||||
readonly songHash: string;
|
||||
|
||||
/**
|
||||
* The name of the song this leaderboard is for.
|
||||
* @private
|
||||
*/
|
||||
readonly songName: string;
|
||||
|
||||
/**
|
||||
* The sub name of the leaderboard.
|
||||
* @private
|
||||
*/
|
||||
readonly songSubName: string;
|
||||
|
||||
/**
|
||||
* The author of the song this leaderboard is for.
|
||||
* @private
|
||||
*/
|
||||
readonly songAuthorName: string;
|
||||
|
||||
/**
|
||||
* The author of the level this leaderboard is for.
|
||||
* @private
|
||||
*/
|
||||
readonly levelAuthorName: string;
|
||||
|
||||
/**
|
||||
* The difficulty of the leaderboard.
|
||||
* @private
|
||||
*/
|
||||
readonly difficulty: LeaderboardDifficulty;
|
||||
|
||||
/**
|
||||
* The difficulties of the leaderboard.
|
||||
* @private
|
||||
*/
|
||||
readonly difficulties: LeaderboardDifficulty[];
|
||||
|
||||
/**
|
||||
* The maximum score of the leaderboard.
|
||||
* @private
|
||||
*/
|
||||
readonly maxScore: number;
|
||||
|
||||
/**
|
||||
* Whether the leaderboard is ranked.
|
||||
* @private
|
||||
*/
|
||||
readonly ranked: boolean;
|
||||
|
||||
/**
|
||||
* The link to the song art.
|
||||
* @private
|
||||
*/
|
||||
readonly songArt: string;
|
||||
|
||||
/**
|
||||
* The date the leaderboard was created.
|
||||
* @private
|
||||
*/
|
||||
readonly timestamp: Date;
|
||||
}
|
Reference in New Issue
Block a user