Fix: Support both numeric and hash song IDs for leaderboard
This commit is contained in:
@@ -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 || []
|
||||
|
||||
@@ -958,11 +958,12 @@ class Scoresheet {
|
||||
}
|
||||
|
||||
submitToLeaderboard(songId, difficulty, scoreObj) {
|
||||
// Only submit if user is logged in and song has valid numeric ID
|
||||
if (!account.loggedIn || !songId || isNaN(parseInt(songId))) {
|
||||
// Only submit if user is logged in and song has an ID
|
||||
if (!account.loggedIn || !songId) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var self = this
|
||||
loader.getCsrfToken().then(token => {
|
||||
var request = new XMLHttpRequest()
|
||||
@@ -984,7 +985,7 @@ class Scoresheet {
|
||||
}
|
||||
|
||||
request.send(JSON.stringify({
|
||||
song_id: parseInt(songId),
|
||||
song_id: songId,
|
||||
difficulty: difficulty,
|
||||
score: scoreObj
|
||||
}))
|
||||
|
||||
@@ -3336,12 +3336,11 @@ class SongSelect {
|
||||
}
|
||||
toLeaderboard() {
|
||||
var songId = this.songs[this.selectedSong].id
|
||||
// Only allow leaderboard for server songs with numeric IDs
|
||||
if (!songId || typeof songId !== 'number' || isNaN(songId)) {
|
||||
// Show alert for custom/local songs
|
||||
alert("排行榜仅支持服务器歌曲\nLeaderboard only available for server songs")
|
||||
// Allow leaderboard for any song with an ID (numeric or hash)
|
||||
if (!songId) {
|
||||
return
|
||||
}
|
||||
|
||||
// Default to first available difficulty if not in a valid difficulty selection
|
||||
var selectedDiff = this.selectedDiff - this.diffOptions.length
|
||||
if (selectedDiff < 0) {
|
||||
|
||||
Reference in New Issue
Block a user