LETS GO BABY
Some checks failed
Deploy Website / deploy (push) Waiting to run
Deploy Backend / deploy (push) Has been cancelled

This commit is contained in:
Lee
2024-10-09 01:17:00 +01:00
parent e0fca1168a
commit e87d73bbdf
69 changed files with 583 additions and 458 deletions

View File

@ -3,12 +3,19 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "tsup src/index.ts --watch",
"build": "tsup src/index.ts"
"dev": "tsc --watch --preserveWatchOutput",
"build": "tsc"
},
"exports": {
"./*": {
"types": "./dist/*.d.ts",
"import": "./dist/*.js",
"require": "./dist/*.js",
"default": "./dist/*.js"
}
},
"devDependencies": {
"@types/node": "^22.7.4",
"tsup": "^8",
"typescript": "^5"
},
"dependencies": {

View File

@ -1,49 +0,0 @@
export * from "src/utils/utils";
export * from "src/utils/time-utils";
/**
* Player stuff
*/
export * from "src/types/player/player-history";
export * from "src/types/player/player-tracked-since";
export * from "src/types/player/player";
export * from "src/types/player/impl/scoresaber-player";
export * from "src/utils/player-utils";
/**
* Score stuff
*/
export * from "src/types/score/score";
export * from "src/types/score/score-sort";
export * from "src/types/score/modifier";
export * from "src/types/score/impl/scoresaber-score";
/**
* Service stuff
*/
export * from "src/service/impl/beatsaver";
export * from "src/service/impl/scoresaber";
/**
* Scoresaber Tokens
*/
export * from "src/types/token/scoresaber/score-saber-badge-token";
export * from "src/types/token/scoresaber/score-saber-difficulty-token";
export * from "src/types/token/scoresaber/score-saber-leaderboard-player-info-token";
export * from "src/types/token/scoresaber/score-saber-leaderboard-scores-page-token";
export * from "src/types/token/scoresaber/score-saber-leaderboard-token";
export * from "src/types/token/scoresaber/score-saber-metadata-token";
export * from "src/types/token/scoresaber/score-saber-player-score-token";
export * from "src/types/token/scoresaber/score-saber-player-scores-page-token";
export * from "src/types/token/scoresaber/score-saber-player-search-token";
export * from "src/types/token/scoresaber/score-saber-player-token";
export * from "src/types/token/scoresaber/score-saber-players-page-token";
export * from "src/types/token/scoresaber/score-saber-score-token";
/**
* Beatsaver Tokens
*/
export * from "src/types/token/beatsaver/beat-saver-account-token";
export * from "src/types/token/beatsaver/beat-saver-map-metadata-token";
export * from "src/types/token/beatsaver/beat-saver-map-stats-token";
export * from "src/types/token/beatsaver/beat-saver-map-token";

View File

@ -1,7 +1,6 @@
import Service from "../service";
import { ScoreSaberPlayerSearchToken } from "../../types/token/scoresaber/score-saber-player-search-token";
import ScoreSaberPlayerToken from "../../types/token/scoresaber/score-saber-player-token";
import ScoreSaberPlayer, { getScoreSaberPlayerFromToken } from "../../types/player/impl/scoresaber-player";
import { ScoreSaberPlayersPageToken } from "../../types/token/scoresaber/score-saber-players-page-token";
import { ScoreSort } from "../../types/score/score-sort";
import ScoreSaberPlayerScoresPageToken from "../../types/token/scoresaber/score-saber-player-scores-page-token";
@ -55,19 +54,9 @@ class ScoreSaberService extends Service {
* Looks up a player by their ID.
*
* @param playerId the ID of the player to look up
* @param apiUrl the url to the API for SSR
* @returns the player that matches the ID, or undefined
*/
async lookupPlayer(
playerId: string,
apiUrl: string
): Promise<
| {
player: ScoreSaberPlayer;
rawPlayer: ScoreSaberPlayerToken;
}
| undefined
> {
async lookupPlayer(playerId: string): Promise<ScoreSaberPlayerToken | undefined> {
const before = performance.now();
this.log(`Looking up player "${playerId}"...`);
const token = await this.fetch<ScoreSaberPlayerToken>(LOOKUP_PLAYER_ENDPOINT.replace(":id", playerId));
@ -75,10 +64,7 @@ class ScoreSaberService extends Service {
return undefined;
}
this.log(`Found player "${playerId}" in ${(performance.now() - before).toFixed(0)}ms`);
return {
player: await getScoreSaberPlayerFromToken(apiUrl, token),
rawPlayer: token,
};
return token;
}
/**

View File

@ -3,6 +3,7 @@ import ky from "ky";
import { PlayerHistory } from "../player-history";
import ScoreSaberPlayerToken from "../../token/scoresaber/score-saber-player-token";
import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../../utils/time-utils";
import { getPlayerIdCookie } from "website/src/common/website-utils";
/**
* A ScoreSaber player.
@ -65,9 +66,15 @@ export default interface ScoreSaberPlayer extends Player {
isBeingTracked?: boolean;
}
/**
* Gets the ScoreSaber Player from an {@link ScoreSaberPlayerToken}.
*
* @param token the player token
* @param apiUrl the api url for SSR
*/
export async function getScoreSaberPlayerFromToken(
apiUrl: string,
token: ScoreSaberPlayerToken
token: ScoreSaberPlayerToken,
apiUrl: string
): Promise<ScoreSaberPlayer> {
const bio: ScoreSaberBio = {
lines: token.bio?.split("\n") || [],
@ -86,10 +93,10 @@ export async function getScoreSaberPlayerFromToken(
const todayDate = formatDateMinimal(getMidnightAlignedDate(new Date()));
let statisticHistory: { [key: string]: PlayerHistory } = {};
try {
const history = await ky
const { statistics: history } = await ky
.get<{
[key: string]: PlayerHistory;
}>(`${apiUrl}/api/player/history?id=${token.id}`)
statistics: { [key: string]: PlayerHistory };
}>(`${apiUrl}/player/history/${token.id}${getPlayerIdCookie() == token.id ? "?createIfMissing=true" : ""}`)
.json();
if (history === undefined || Object.entries(history).length === 0) {
console.log("Player has no history, using fallback");

View File

@ -4,11 +4,6 @@ export interface PlayerTrackedSince {
*/
tracked: boolean;
/**
* The date the player was first tracked
*/
trackedSince?: string;
/**
* The amount of days the player has been tracked
*/

View File

@ -1,21 +1,18 @@
{
"compilerOptions": {
"module": "ES2022",
"moduleResolution": "Bundler",
"target": "ES2022",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"declaration": true,
"moduleResolution": "node",
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
"allowSyntheticDefaultImports": true,
"strict": true,
"baseUrl": "./",
"paths": {
"@ssr/*": ["dist/*"] // This is crucial for resolving the imports correctly
}
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
}

View File

@ -1,10 +0,0 @@
import { defineConfig } from "tsup";
export default defineConfig({
entry: ["src/index.ts"],
splitting: false,
sourcemap: true,
clean: true,
dts: true, // Generates type declarations
format: ["esm"], // Ensures output is in ESM format
});