Skip to content

Commit

Permalink
去除不必要的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xmdhs committed Oct 12, 2023
1 parent c2edef7 commit 06d3884
Showing 1 changed file with 14 additions and 33 deletions.
47 changes: 14 additions & 33 deletions service/yggdrasil/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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}
key := []byte("Profile" + uuid)
ut, err := c.Get(key)
if err != nil {
return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", err)
}
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 {
if ut.ProfileName == "" {
up, err := y.client.UserProfile.Query().Where(userprofile.UUID(uuid)).WithUsertexture().Only(ctx)
if err != nil {
var nf *ent.NotFoundError
Expand All @@ -200,6 +175,17 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool,
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 {
dt, err := y.client.Texture.Query().Where(texture.ID(v.TextureID)).Only(ctx)
if err != nil {
Expand All @@ -223,15 +209,10 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool,

texturesBase64 := ut.Base64()

pl := []yggdrasil.UserProperties{}
pl = append(pl, yggdrasil.UserProperties{
pl := []yggdrasil.UserProperties{{
Name: "textures",
Value: texturesBase64,
})
pl = append(pl, yggdrasil.UserProperties{
Name: "uploadableTextures",
Value: "skin,cape",
})
}}

if !unsigned {
s := sign.NewAuthlibSignWithKey(y.prikey)
Expand Down

0 comments on commit 06d3884

Please sign in to comment.