From 8548d1d5967a0a01b57b6ae5e034938e58fe343b Mon Sep 17 00:00:00 2001 From: Josh Yan Date: Wed, 17 Jul 2024 14:03:57 -0700 Subject: [PATCH] cmt --- server/routes.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/routes.go b/server/routes.go index be3547183..7f55a36cf 100644 --- a/server/routes.go +++ b/server/routes.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "io" - "log" "log/slog" "math" "net" @@ -943,7 +942,7 @@ func (s *Server) CreateBlobHandler(c *gin.Context) { c.Status(http.StatusOK) return } - if c.GetHeader("X-Redirect-Create") == "1" && s.IsLocal(c) { + if c.GetHeader("X-Redirect-Create") == "1" && s.IsServerKeyPublicKey(c) { c.Header("LocalLocation", path) c.Status(http.StatusTemporaryRedirect) return @@ -963,7 +962,7 @@ func (s *Server) CreateBlobHandler(c *gin.Context) { c.Status(http.StatusCreated) } -func (s *Server) IsLocal(c *gin.Context) bool { +func (s *Server) IsServerKeyPublicKey(c *gin.Context) bool { if authz := c.GetHeader("Authorization"); authz != "" { parts := strings.Split(authz, ":") if len(parts) != 3 { @@ -997,14 +996,13 @@ func (s *Server) IsLocal(c *gin.Context) bool { serverPublicKey, err := auth.GetPublicKey() if err != nil { - log.Fatal(err) + slog.Error(fmt.Sprintf("failed to get server public key: %v", err)) } if bytes.Equal(serverPublicKey.Marshal(), clientPublicKey.Marshal()) { return true } - c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"}) return false }