lsp-yggdrasil/src/routes/api.js

49 lines
1.5 KiB
JavaScript

import { getOverrideHandler, getOverridePreHandler } from "../config.js"
import { uuidToNoSymboUUID } from "../generator.js"
import { Player } from "../models/player.js"
export const profiles = {
method: 'POST',
url: '/api/profiles/minecraft',
schema: {
body: {
type: 'array',
items: {
type: 'string'
}
},
response: {
200: {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'string'
},
name: {
type: 'string'
}
}
}
}
}
},
preHandler: getOverridePreHandler('/api/profiles/minecraft') ?? async function(req, rep) {
if(req.body.length >= 3) {
await rep.code(400).send({
error: "IllegalArgumentException",
errorMessage: "请求内容过长, 最大请求玩家数: 2",
cause: "请求内容过长, 最大请求玩家数: 2"
})
}
},
handler: getOverrideHandler('/api/profiles/minecraft') ?? async function (req, rep) {
const { body } = req
const profiles = await Player.find({ username: { $in: body } })
return await rep.code(200).send(profiles.map(profile => ({
id: uuidToNoSymboUUID(profile.uuid),
name: profile.username
})))
}
}