去除不必要的代码

This commit is contained in:
xmdhs 2023-10-13 00:38:39 +08:00
parent c2edef7ac4
commit 06d38841b1
No known key found for this signature in database
GPG Key ID: E809D6D43DEFCC95

View File

@ -152,38 +152,13 @@ func (y *Yggdrasil) Refresh(ctx context.Context, t *model.TokenClaims) (yggdrasi
} }
func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool, host string) (yggdrasil.UserInfo, error) { func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool, host string) (yggdrasil.UserInfo, error) {
baseURl := func() string {
if y.config.TextureBaseUrl == "" {
u := &url.URL{}
u.Host = host
u.Scheme = "http"
u.Path = "texture"
return u.String()
}
return y.config.TextureBaseUrl
}()
c := cache.CacheHelp[yggdrasil.UserTextures]{Cache: y.cache} c := cache.CacheHelp[yggdrasil.UserTextures]{Cache: y.cache}
key := []byte("Profile" + uuid) key := []byte("Profile" + uuid)
ut, err := c.Get(key) ut, err := c.Get(key)
if err != nil { if err != nil {
return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", err) return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", err)
} }
if ut.ProfileName != "" { if ut.ProfileName == "" {
for k, v := range ut.Textures {
u, err := url.Parse(v.Url)
if err != nil {
return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", err)
}
baseu, err := url.Parse(baseURl)
if err != nil {
return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", err)
}
u.Host = baseu.Host
v.Url = u.String()
ut.Textures[k] = v
}
} else {
up, err := y.client.UserProfile.Query().Where(userprofile.UUID(uuid)).WithUsertexture().Only(ctx) up, err := y.client.UserProfile.Query().Where(userprofile.UUID(uuid)).WithUsertexture().Only(ctx)
if err != nil { if err != nil {
var nf *ent.NotFoundError var nf *ent.NotFoundError
@ -200,6 +175,17 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool,
Timestamp: time.Now().UnixMilli(), Timestamp: time.Now().UnixMilli(),
} }
baseURl := func() string {
if y.config.TextureBaseUrl == "" {
u := &url.URL{}
u.Host = host
u.Scheme = "http"
u.Path = "texture"
return u.String()
}
return y.config.TextureBaseUrl
}()
for _, v := range up.Edges.Usertexture { for _, v := range up.Edges.Usertexture {
dt, err := y.client.Texture.Query().Where(texture.ID(v.TextureID)).Only(ctx) dt, err := y.client.Texture.Query().Where(texture.ID(v.TextureID)).Only(ctx)
if err != nil { if err != nil {
@ -223,15 +209,10 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool,
texturesBase64 := ut.Base64() texturesBase64 := ut.Base64()
pl := []yggdrasil.UserProperties{} pl := []yggdrasil.UserProperties{{
pl = append(pl, yggdrasil.UserProperties{
Name: "textures", Name: "textures",
Value: texturesBase64, Value: texturesBase64,
}) }}
pl = append(pl, yggdrasil.UserProperties{
Name: "uploadableTextures",
Value: "skin,cape",
})
if !unsigned { if !unsigned {
s := sign.NewAuthlibSignWithKey(y.prikey) s := sign.NewAuthlibSignWithKey(y.prikey)