92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import axios from 'axios'
|
|
import {
|
|
encodeGJP2,
|
|
generateTimeLength,
|
|
jsonResponse,
|
|
splitGd
|
|
} from '../../../lib/util'
|
|
import { Context } from 'elysia'
|
|
|
|
export const handler = async (
|
|
handler: Context,
|
|
type: string,
|
|
classic: boolean
|
|
) => {
|
|
const id = handler.query.id
|
|
|
|
if (!process.env.ACCOUNT_ID || !process.env.ACCOUNT_PASSWORD)
|
|
return jsonResponse({
|
|
success: false,
|
|
message:
|
|
'Failed to authenticate (are you sure account ID and password are in .env?)',
|
|
data: null
|
|
})
|
|
|
|
const request = await axios.post(
|
|
classic
|
|
? 'https://www.boomlings.com/database/getGJLevelScores211.php'
|
|
: 'https://www.boomlings.com/database/getGJLevelScoresPlat.php',
|
|
new URLSearchParams({
|
|
gameVersion: '22',
|
|
binaryVersion: '45',
|
|
accountID: process.env.ACCOUNT_ID ?? '',
|
|
gjp2: await encodeGJP2(process.env.ACCOUNT_PASSWORD ?? ''),
|
|
levelID: id,
|
|
secret: 'Wmfd2893gb7',
|
|
type: type
|
|
}),
|
|
{
|
|
headers: {
|
|
'User-Agent': ' ',
|
|
Cookie: 'gd=1'
|
|
}
|
|
}
|
|
)
|
|
|
|
if (request.data == '-01')
|
|
return jsonResponse({
|
|
success: false,
|
|
message:
|
|
'Failed to authenticate (are you sure account ID and password are in .env?)',
|
|
data: null
|
|
})
|
|
if (request.data.trim() == '')
|
|
return jsonResponse({
|
|
success: false,
|
|
message:
|
|
'Empty response (please check that you are using the right classic/platformer type)',
|
|
data: null
|
|
})
|
|
|
|
const responseText = request.data as string
|
|
const responseSplit = responseText.split('|')
|
|
|
|
return jsonResponse({
|
|
success: true,
|
|
message: null,
|
|
data: responseSplit.map(item => {
|
|
const split = splitGd(item)
|
|
return {
|
|
rank: +split['6'],
|
|
username: split['1'],
|
|
time: +split['3'],
|
|
timeFormatted: generateTimeLength(+split['3']),
|
|
coins: +split['13'],
|
|
playerId: +split['2'],
|
|
accountId: +split['16'],
|
|
date: split['42'] + ' ago',
|
|
icon: {
|
|
form: ['icon', 'ship', 'ball', 'ufo', 'wave', 'robot', 'spider'][
|
|
+split['14']
|
|
],
|
|
icon: +split['9'],
|
|
col1: +split['10'],
|
|
col2: +split['11'],
|
|
colG: +split['51'],
|
|
glow: +split['15'] > 1
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|