mirror of
https://github.com/unmojang/drasl.git
synced 2025-09-08 14:45:23 -04:00
Fix player faces on admin page
This commit is contained in:
parent
5c1f6c1cfa
commit
8ccb3babeb
7
front.go
7
front.go
@ -62,9 +62,10 @@ func NewTemplate(app *App) *Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"PlayerSkinURL": app.PlayerSkinURL,
|
"PrimaryPlayerSkinURL": app.PrimaryPlayerSkinURL,
|
||||||
"InviteURL": app.InviteURL,
|
"PlayerSkinURL": app.PlayerSkinURL,
|
||||||
"IsDefaultAdmin": app.IsDefaultAdmin,
|
"InviteURL": app.InviteURL,
|
||||||
|
"IsDefaultAdmin": app.IsDefaultAdmin,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
|
11
model.go
11
model.go
@ -291,17 +291,6 @@ func (app *App) InviteURL(invite *Invite) (string, error) {
|
|||||||
return url + "?invite=" + invite.Code, nil
|
return url + "?invite=" + invite.Code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) PlayerSkinURL(player *Player) (*string, error) {
|
|
||||||
if !player.SkinHash.Valid {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
url, err := app.SkinURL(player.SkinHash.String)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &url, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (app *App) CapeURL(hash string) (string, error) {
|
func (app *App) CapeURL(hash string) (string, error) {
|
||||||
return url.JoinPath(app.FrontEndURL, "web/texture/cape/"+hash+".png")
|
return url.JoinPath(app.FrontEndURL, "web/texture/cape/"+hash+".png")
|
||||||
}
|
}
|
||||||
|
11
player.go
11
player.go
@ -602,3 +602,14 @@ func (app *App) DeletePlayer(caller *User, player *Player) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) PlayerSkinURL(player *Player) (*string, error) {
|
||||||
|
if !player.SkinHash.Valid {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
url, err := app.SkinURL(player.SkinHash.String)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &url, nil
|
||||||
|
}
|
||||||
|
49
user.go
49
user.go
@ -7,11 +7,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/samber/mo"
|
||||||
"github.com/zitadel/oidc/v3/pkg/client/rp"
|
"github.com/zitadel/oidc/v3/pkg/client/rp"
|
||||||
"github.com/zitadel/oidc/v3/pkg/oidc"
|
"github.com/zitadel/oidc/v3/pkg/oidc"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -674,3 +676,50 @@ func (app *App) DeleteOIDCIdentity(
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) PrimaryPlayerSkinURL(user *User) (*string, error) {
|
||||||
|
if len(user.Players) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
player := (func() mo.Option[*Player] {
|
||||||
|
if len(user.Players) == 0 {
|
||||||
|
return mo.None[*Player]()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, player := range user.Players {
|
||||||
|
if player.Name == user.Username {
|
||||||
|
if player.SkinHash.Valid {
|
||||||
|
return mo.Some(&player)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playersDecreasingAge := make([]*Player, 0, len(user.Players))
|
||||||
|
for i := range user.Players {
|
||||||
|
playersDecreasingAge = append(playersDecreasingAge, &user.Players[i])
|
||||||
|
}
|
||||||
|
slices.SortFunc(playersDecreasingAge, func(a *Player, b *Player) int {
|
||||||
|
return a.CreatedAt.Compare(b.CreatedAt)
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, player := range playersDecreasingAge {
|
||||||
|
if player.SkinHash.Valid {
|
||||||
|
return mo.Some(player)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mo.None[*Player]()
|
||||||
|
})()
|
||||||
|
|
||||||
|
if p, ok := player.Get(); ok {
|
||||||
|
skinURL, err := app.SkinURL(p.SkinHash.String)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &skinURL, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
@ -103,7 +103,11 @@
|
|||||||
<td style="width: 30px">
|
<td style="width: 30px">
|
||||||
<div
|
<div
|
||||||
class="list-profile-picture"
|
class="list-profile-picture"
|
||||||
{{/*style="background-image: url({{ PlayerSkinURL $user }});"*/}}
|
{{ with $playerSkinURL := PrimaryPlayerSkinURL $user }}
|
||||||
|
{{ if $playerSkinURL }}
|
||||||
|
style="background-image: url({{ $playerSkinURL }});"
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
></div>
|
></div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
class="list-profile-picture"
|
class="list-profile-picture"
|
||||||
{{ with $playerSkinURL := PlayerSkinURL $player }}
|
{{ with $playerSkinURL := PlayerSkinURL $player }}
|
||||||
{{ if $playerSkinURL }}
|
{{ if $playerSkinURL }}
|
||||||
style="background-image: url({{ PlayerSkinURL $player }});"
|
style="background-image: url({{ $playerSkinURL }});"
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
></div>
|
></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user