fix: Fix leaderboard freeze and AJAX submission issues - Fixed fetchData async/await to use proper Promise pattern - Added basedir prefix to API URLs - Fixed submitToLeaderboard to use XMLHttpRequest with CSRF token
This commit is contained in:
@@ -43,9 +43,8 @@ class LeaderboardUI {
|
|||||||
this.songSelect.leaderboardActive = false
|
this.songSelect.leaderboardActive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchData(songId, difficulty) {
|
fetchData(songId, difficulty) {
|
||||||
try {
|
loader.ajax(gameConfig.basedir + `api/leaderboard/get?song_id=${songId}&difficulty=${difficulty}`).then(response => {
|
||||||
const response = await loader.ajax(`api/leaderboard/get?song_id=${songId}&difficulty=${difficulty}`)
|
|
||||||
const data = JSON.parse(response)
|
const data = JSON.parse(response)
|
||||||
if (data.status === 'ok') {
|
if (data.status === 'ok') {
|
||||||
this.leaderboardData = data.leaderboard
|
this.leaderboardData = data.leaderboard
|
||||||
@@ -57,10 +56,10 @@ class LeaderboardUI {
|
|||||||
const viewHeight = this.height - this.headerHeight - this.padding * 2
|
const viewHeight = this.height - this.headerHeight - this.padding * 2
|
||||||
this.maxScroll = Math.max(0, totalHeight - viewHeight)
|
this.maxScroll = Math.max(0, totalHeight - viewHeight)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
}).catch(e => {
|
||||||
console.error(e)
|
console.error("Leaderboard fetch error:", e)
|
||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(ctx, winW, winH, pixelRatio) {
|
draw(ctx, winW, winH, pixelRatio) {
|
||||||
|
|||||||
@@ -995,20 +995,31 @@ class Scoresheet {
|
|||||||
hash: song.hash
|
hash: song.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
loader.ajax("api/leaderboard/submit", request => {
|
loader.getCsrfToken().then(token => {
|
||||||
request.open("POST", "api/leaderboard/submit")
|
var request = new XMLHttpRequest()
|
||||||
request.setRequestHeader("Content-Type", "application/json")
|
request.open("POST", gameConfig.basedir + "api/leaderboard/submit")
|
||||||
request.send(JSON.stringify(body))
|
pageEvents.load(request).then(() => {
|
||||||
}).then(response => {
|
if (request.status === 200) {
|
||||||
var data = JSON.parse(response)
|
try {
|
||||||
|
var data = JSON.parse(request.response)
|
||||||
if (data.status === "ok" && data.new_record && data.rank) {
|
if (data.status === "ok" && data.new_record && data.rank) {
|
||||||
this.leaderboardResult = {
|
this.leaderboardResult = {
|
||||||
rank: data.rank
|
rank: data.rank
|
||||||
}
|
}
|
||||||
assets.sounds["se_results_crown"].play()
|
assets.sounds["se_results_crown"].play()
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Leaderboard response parse error:", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
console.error("Leaderboard submit failed", e)
|
console.error("Leaderboard submit failed:", e)
|
||||||
|
})
|
||||||
|
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8")
|
||||||
|
request.setRequestHeader("X-CSRFToken", token)
|
||||||
|
request.send(JSON.stringify(body))
|
||||||
|
}).catch(e => {
|
||||||
|
console.error("Failed to get CSRF token:", e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user