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: { summary: "获取玩家信息", description: "获取玩家信息。详情请见 authlib-injector 文档。", tags: [ "api" ], 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 }))) } } export const telegramBind = { method: 'GET', url: '/api/telegram/bind/:uuid', schema: { summary: "获取 Telegram 绑定", description: "获取玩家对应 Telegram 绑定,返回纯文本。", tags: [ "webapi" ], response: { 200: { type: 'string' } } }, preHandler: getOverridePreHandler('/api/telegram/bind/:uuid'), handler: getOverrideHandler('/api/telegram/bind/:uuid') ?? async function (req, rep) { const { uuid } = req.params const player = await Player.findOne({ uuid: uuidToNoSymboUUID(uuid) }) await rep.code(200).send(player?.telegram ?? "") } }