Fix: Support both numeric and hash song IDs for leaderboard

This commit is contained in:
2026-01-17 19:56:41 +08:00
parent 3f7ff13ef7
commit 9935d70e31
5 changed files with 20 additions and 15 deletions

View File

@@ -77,17 +77,18 @@ class Leaderboard {
}
async fetchLeaderboard() {
// Validate songId is a valid number
if (!this.songId || isNaN(parseInt(this.songId))) {
console.error("Invalid song ID for leaderboard:", this.songId)
// Validate songId exists
if (!this.songId) {
console.error("Missing song ID for leaderboard")
this.leaderboardData = []
return
}
try {
var response = await loader.ajax(
`${gameConfig.basedir || "/"}api/leaderboard/get?song_id=${parseInt(this.songId)}&difficulty=${this.difficulty}`
`${gameConfig.basedir || "/"}api/leaderboard/get?song_id=${encodeURIComponent(this.songId)}&difficulty=${this.difficulty}`
)
var data = JSON.parse(response)
if (data.status === "ok") {
this.leaderboardData = data.leaderboard || []