feat(yggdrasil): 实现 MC 1.21.7 单用户名查 UUID 接口
对应官方 api.minecraftservices.com/minecraft/profile/lookup/name/{name},
1.21.7 的 /whitelist add 等命令会请求该接口(authlib-injector issue #277)。
authlib-injector 把 api.minecraftservices.com override 到 {apiRoot}/minecraftservices,
故路由注册在 mcServices 组下:
GET /api/yggdrasil/minecraftservices/minecraft/profile/lookup/name/:name
复用 ProfileSearchByNameSingle,返回 {id,name},未找到返回 404。
go build ./... && go test ./... 全部通过。
This commit is contained in:
@@ -682,6 +682,41 @@ func (h *YggdrasilHandler) GetProfileByName(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// LookupProfileByName 单用户名查 UUID(authlib-injector issue #277 / MC 1.21.7)
|
||||
// @Summary MinecraftServices 按用户名查 UUID
|
||||
// @Description 对应官方 api.minecraftservices.com/minecraft/profile/lookup/name/{name},
|
||||
// @Description 1.21.7 的 /whitelist add 等命令会请求该接口。authlib-injector 把
|
||||
// @Description api.minecraftservices.com override 到 {apiRoot}/minecraftservices。
|
||||
// @Description 返回 {id,name},未找到返回 404。
|
||||
// @Tags Yggdrasil
|
||||
// @Produce json
|
||||
// @Param name path string true "用户名"
|
||||
// @Success 200 {object} model.NameAndId "档案标识"
|
||||
// @Failure 404 {object} map[string]string "档案不存在"
|
||||
// @Router /api/yggdrasil/minecraftservices/minecraft/profile/lookup/name/{name} [get]
|
||||
func (h *YggdrasilHandler) LookupProfileByName(c *gin.Context) {
|
||||
name := c.Param("name")
|
||||
if name == "" {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "用户不存在"})
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.container.ProfileService.ProfileSearchByNameSingle(c.Request.Context(), name)
|
||||
if err != nil {
|
||||
h.logger.Warn("按用户名查档失败", zap.String("name", name), zap.Error(err))
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "用户不存在"})
|
||||
return
|
||||
}
|
||||
if result == nil {
|
||||
h.logger.Info("用户名未找到", zap.String("name", name))
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "用户不存在"})
|
||||
return
|
||||
}
|
||||
|
||||
h.logger.Info("成功获取档案", zap.String("name", name), zap.String("uuid", result.ID))
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// GetMetaData 获取Yggdrasil元数据
|
||||
// @Summary Yggdrasil元数据
|
||||
// @Description Yggdrasil协议: 获取服务器元数据
|
||||
|
||||
Reference in New Issue
Block a user