Compare commits

..

2 Commits

Author SHA1 Message Date
8934da692b feat: 添加 gitea 构建脚本
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 5m9s
2025-06-05 02:25:55 +08:00
e7c4dc58b7 feat: 添加公钥缓存功能 2025-06-05 02:25:03 +08:00

View File

@@ -62,8 +62,9 @@ type HomeRouter interface {
} }
type homeRouterImpl struct { type homeRouterImpl struct {
serverMeta ServerMeta serverMeta ServerMeta
myPubKey KeyPair myPubKey KeyPair
cachedPubKey *PublicKeys
} }
func NewHomeRouter(meta *ServerMeta) HomeRouter { func NewHomeRouter(meta *ServerMeta) HomeRouter {
@@ -81,6 +82,10 @@ func (h *homeRouterImpl) Home(c *gin.Context) {
} }
func (h *homeRouterImpl) PublicKeys(c *gin.Context) { func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
if h.cachedPubKey != nil {
c.JSON(http.StatusOK, h.cachedPubKey)
return
}
publicKeys := PublicKeys{} publicKeys := PublicKeys{}
err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys) err := util.GetObject("https://api.minecraftservices.com/publickeys", &publicKeys)
if err != nil { if err != nil {
@@ -90,4 +95,5 @@ func (h *homeRouterImpl) PublicKeys(c *gin.Context) {
publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey) publicKeys.ProfilePropertyKeys = append(publicKeys.ProfilePropertyKeys, h.myPubKey)
publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey) publicKeys.PlayerCertificateKeys = append(publicKeys.PlayerCertificateKeys, h.myPubKey)
c.JSON(http.StatusOK, publicKeys) c.JSON(http.StatusOK, publicKeys)
h.cachedPubKey = &publicKeys
} }