fix(api): ms trophy validation (#53978)

pull/53980/head
Tom 2024-03-04 23:50:53 -06:00 committed by GitHub
parent a8ce82facb
commit 87351f39d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 8 deletions

View File

@ -766,26 +766,26 @@ function createMsTrophyChallengeCompleted(app) {
const { userId } = msProfileJson;
const msGameStatusApi = `https://learn.microsoft.com/api/gamestatus/${userId}`;
const msGameStatusApiRes = await fetch(msGameStatusApi);
const msGameStatusJson = await msGameStatusApiRes.json();
const msUserAchievementsApi = `https://learn.microsoft.com/api/achievements/user/${userId}`;
const msUserAchievementsApiRes = await fetch(msUserAchievementsApi);
const msUserAchievementsJson = await msUserAchievementsApiRes.json();
if (!msGameStatusApiRes.ok) {
if (!msUserAchievementsApiRes.ok) {
return res.status(403).json({
type: 'error',
message: 'flash.ms.trophy.err-3'
});
}
if (msGameStatusJson.achievements?.length === 0) {
if (msUserAchievementsJson.achievements?.length === 0) {
return res.status(403).json({
type: 'error',
message: 'flash.ms.trophy.err-6'
});
}
const hasEarnedTrophy = msGameStatusJson.achievements?.some(
a => a.awardUid === msTrophyId
const hasEarnedTrophy = msUserAchievementsJson.achievements?.some(
a => a.typeId === msTrophyId
);
if (!hasEarnedTrophy) {
@ -800,7 +800,7 @@ function createMsTrophyChallengeCompleted(app) {
const completedChallenge = pick(body, ['id']);
completedChallenge.solution = msGameStatusApi;
completedChallenge.solution = msUserAchievementsApi;
completedChallenge.completedDate = Date.now();
try {