215 lines
5.2 KiB
TypeScript
215 lines
5.2 KiB
TypeScript
import { Elysia, t } from 'elysia'
|
|
import { jsonResponse } from './lib/util'
|
|
import dotenv from 'dotenv'
|
|
import swagger from '@elysiajs/swagger'
|
|
|
|
import { handler as eventLevelGetHandler } from './routes/event-level/get'
|
|
|
|
import { handler as gauntletsGetHandler } from './routes/gauntlets/get'
|
|
|
|
import { handler as leaderboardsGetHandler } from './routes/leaderboards/get'
|
|
import { handler as leaderboardsLevelGetHandler } from './routes/leaderboards/level/get'
|
|
|
|
import { handler as mapPacksGetHandler } from './routes/map-packs/get'
|
|
|
|
import { handler as commentsAccountGetHandler } from './routes/comments/account/get'
|
|
import { handler as commentsAccountHistoryGetHandler } from './routes/comments/account/history/get'
|
|
import { handler as commentsLevelGetHandler } from './routes/comments/level/get'
|
|
|
|
dotenv.config()
|
|
|
|
const app = new Elysia().use(
|
|
swagger({
|
|
path: '/docs',
|
|
documentation: {
|
|
info: {
|
|
title: 'Lncvrt Games API',
|
|
description:
|
|
'This is the official documentation for the Lncvrt Games API!',
|
|
version: '1.0.0'
|
|
}
|
|
}
|
|
})
|
|
)
|
|
|
|
app.get('/gauntlets', gauntletsGetHandler, {
|
|
detail: {
|
|
description: 'The endpoint for getting all gauntlets',
|
|
tags: ['Levels']
|
|
}
|
|
})
|
|
app.get('/map-packs', mapPacksGetHandler, {
|
|
detail: {
|
|
description: 'The endpoint for getting all map packs',
|
|
tags: ['Levels']
|
|
}
|
|
})
|
|
app.get('/leaderboards/top', () => leaderboardsGetHandler('top'), {
|
|
detail: {
|
|
description: 'The endpoint for getting the top players leaderboard',
|
|
tags: ['Leaderboards']
|
|
}
|
|
})
|
|
app.get('/leaderboards/creators', () => leaderboardsGetHandler('creators'), {
|
|
detail: {
|
|
description: 'The endpoint for getting the top creators leaderboard',
|
|
tags: ['Leaderboards']
|
|
}
|
|
})
|
|
app.get(
|
|
'/leaderboards/level/classic/top',
|
|
handler => leaderboardsLevelGetHandler(handler, '1', true),
|
|
{
|
|
detail: {
|
|
description:
|
|
'The endpoint for getting the classic level top players leaderboard',
|
|
tags: ['Leaderboards', 'Levels']
|
|
},
|
|
query: t.Object({
|
|
id: t.String()
|
|
})
|
|
}
|
|
)
|
|
app.get(
|
|
'/leaderboards/level/platformer/top',
|
|
handler => leaderboardsLevelGetHandler(handler, '2', false),
|
|
{
|
|
detail: {
|
|
description:
|
|
'The endpoint for getting the platformer level top players leaderboard',
|
|
tags: ['Leaderboards', 'Levels']
|
|
},
|
|
query: t.Object({
|
|
id: t.String()
|
|
})
|
|
}
|
|
)
|
|
app.get(
|
|
'/leaderboards/level/classic/week',
|
|
handler => leaderboardsLevelGetHandler(handler, '2', true),
|
|
{
|
|
detail: {
|
|
description:
|
|
'The endpoint for getting the classic level week players leaderboard',
|
|
tags: ['Leaderboards', 'Levels']
|
|
},
|
|
query: t.Object({
|
|
id: t.String()
|
|
})
|
|
}
|
|
)
|
|
app.get(
|
|
'/leaderboards/level/platformer/week',
|
|
handler => leaderboardsLevelGetHandler(handler, '1', false),
|
|
{
|
|
detail: {
|
|
description:
|
|
'The endpoint for getting the classic level week players leaderboard',
|
|
tags: ['Leaderboards', 'Levels']
|
|
},
|
|
query: t.Object({
|
|
id: t.String()
|
|
})
|
|
}
|
|
)
|
|
app.get('/daily-level', () => eventLevelGetHandler('0'), {
|
|
detail: {
|
|
description: 'The endpoint for getting the daily level',
|
|
tags: ['Levels']
|
|
}
|
|
})
|
|
app.get('/weekly-level', () => eventLevelGetHandler('1'), {
|
|
detail: {
|
|
description: 'The endpoint for getting the weekly level',
|
|
tags: ['Levels']
|
|
}
|
|
})
|
|
app.get('/comments/account', handler => commentsAccountGetHandler(handler), {
|
|
detail: {
|
|
description: 'The endpoint for getting account comments',
|
|
tags: ['Accounts', 'Comments']
|
|
},
|
|
query: t.Object({
|
|
id: t.String({ description: 'This is the account ID.' }),
|
|
page: t.Optional(
|
|
t.String({
|
|
description:
|
|
'The page you want to get, starts from `0`. Default is `0`.'
|
|
})
|
|
)
|
|
})
|
|
})
|
|
app.get(
|
|
'/comments/account/history',
|
|
handler => commentsAccountHistoryGetHandler(handler),
|
|
{
|
|
detail: {
|
|
description: 'The endpoint for getting account comment history',
|
|
tags: ['Accounts', 'Comments']
|
|
},
|
|
query: t.Object({
|
|
id: t.String({ description: 'This is the user ID.' }),
|
|
page: t.Optional(
|
|
t.String({
|
|
description:
|
|
'The page you want to get, starts from `0`. Default is `0`.'
|
|
})
|
|
)
|
|
})
|
|
}
|
|
)
|
|
app.get('/comments/level', handler => commentsLevelGetHandler(handler), {
|
|
detail: {
|
|
description: 'The endpoint for getting level comments',
|
|
tags: ['Levels', 'Comments']
|
|
},
|
|
query: t.Object({
|
|
id: t.String({ description: 'This is the level ID.' }),
|
|
page: t.Optional(
|
|
t.String({
|
|
description:
|
|
'The page you want to get, starts from `0`. Default is `0`.'
|
|
})
|
|
),
|
|
mode: t.Union([t.Literal('0'), t.Literal('1')], {
|
|
description: '0 for top, 1 for recent'
|
|
})
|
|
})
|
|
})
|
|
app.get(
|
|
'/',
|
|
() =>
|
|
new Response(null, {
|
|
status: 301,
|
|
headers: { Location: '/docs' }
|
|
}),
|
|
{
|
|
detail: {
|
|
hide: true
|
|
}
|
|
}
|
|
)
|
|
app.all(
|
|
'*',
|
|
() =>
|
|
jsonResponse(
|
|
{
|
|
success: false,
|
|
message:
|
|
'Endpoint not found (are you using the correct request method?)'
|
|
},
|
|
404
|
|
),
|
|
{
|
|
detail: {
|
|
hide: true
|
|
}
|
|
}
|
|
)
|
|
|
|
app.listen(3692)
|
|
|
|
console.log(
|
|
`Geometry Dash API Server started on http://${app.server?.hostname}:${app.server?.port}/`
|
|
)
|