diff --git a/routes/routes.go b/routes/routes.go index e0b017b..e97c6a2 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -2,7 +2,7 @@ package routes import ( "crypto/sha512" - "encoding/base64" + "encoding/hex" "net/http" "git.1750studios.com/ToddShepard/ShortDragon/database" @@ -47,17 +47,17 @@ func Encode(c *gin.Context) { if URL.Short.String == "" { hasher := sha512.New() hasher.Write([]byte(URL.Long.String)) - base := base64.StdEncoding.EncodeToString(hasher.Sum(nil)) + hash := hex.EncodeToString(hasher.Sum(nil)) i := 2 for { - database.Db.Model(&database.URL{}).Where("short = ?", base[0:i]).Count(&count) - if count > 0 && i < len(base) { + database.Db.Model(&database.URL{}).Where("short = ?", hash[0:i]).Count(&count) + if count > 0 && i < len(hash) { i = i + 1 } else if count > 0 { c.AbortWithStatus(http.StatusConflict) return } else { - URL.Short.String = base[0:i] + URL.Short.String = hash[0:i] break } }