批量查询
This commit is contained in:
parent
c6ef8a8706
commit
bfaf686ff0
@ -159,10 +159,15 @@ func (y *Yggdrasil) GetProfile() httprouter.Handle {
|
||||
func (y *Yggdrasil) BatchProfile() httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
ctx := r.Context()
|
||||
a, has := getAnyModel[[]string](ctx, w, r.Body, y.validate, y.logger)
|
||||
a, has := getAnyModel[[]string](ctx, w, r.Body, nil, y.logger)
|
||||
if !has {
|
||||
return
|
||||
}
|
||||
if len(a) > 5 {
|
||||
y.logger.DebugContext(ctx, "最多同时查询五个")
|
||||
handleYgError(ctx, w, yggdrasil.Error{ErrorMessage: "最多同时查询五个"}, 400)
|
||||
return
|
||||
}
|
||||
ul, err := y.yggdrasilService.BatchProfile(ctx, a)
|
||||
if err != nil {
|
||||
y.logger.WarnContext(ctx, err.Error())
|
||||
|
@ -49,7 +49,7 @@ type RefreshToken struct {
|
||||
type UserInfo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Properties []UserProperties `json:"properties"`
|
||||
Properties []UserProperties `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
type UserProperties struct {
|
||||
|
@ -33,7 +33,7 @@ func newYggdrasil(r *httprouter.Router, handelY yggdrasil.Yggdrasil) error {
|
||||
r.DELETE("/api/yggdrasil/api/user/profile/:uuid/:textureType", warpHJSON(handelY.DelTexture()))
|
||||
|
||||
r.GET("/api/yggdrasil/sessionserver/session/minecraft/profile/:uuid", warpHJSON(handelY.GetProfile()))
|
||||
r.POST("/api/profiles/minecraft", warpHJSON(handelY.BatchProfile()))
|
||||
r.POST("/api/yggdrasil/api/profiles/minecraft", warpHJSON(handelY.BatchProfile()))
|
||||
|
||||
r.GET("/api/yggdrasil", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
w.Write([]byte(`{
|
||||
|
@ -15,10 +15,11 @@ func DeCodeBody[T any](r io.Reader, v *validator.Validate) (T, error) {
|
||||
if err != nil {
|
||||
return a, fmt.Errorf("DeCodeBody: %w", err)
|
||||
}
|
||||
|
||||
err = v.Struct(a)
|
||||
if err != nil {
|
||||
return a, fmt.Errorf("DeCodeBody: %w", err)
|
||||
if v != nil {
|
||||
err = v.Struct(a)
|
||||
if err != nil {
|
||||
return a, fmt.Errorf("DeCodeBody: %w", err)
|
||||
}
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user