1
0

more verbose

This commit is contained in:
Antonio 2023-06-17 11:37:39 +08:00
parent 3fb4afed4d
commit a64532a5a0

View File

@ -3,6 +3,7 @@ package main
import (
"bufio"
"os"
"strings"
gin "github.com/gin-gonic/gin"
)
@ -50,7 +51,15 @@ func Authorization(c *gin.Context) {
}
}
if len(API_KEYS) != 0 && !API_KEYS[c.Request.Header.Get("Authorization")] {
c.JSON(401, gin.H{"error": "Unauthorized"})
if c.Request.Header.Get("Authorization") == "" {
c.JSON(401, gin.H{"error": "No API key provided. Get one at https://discord.gg/9K2BvbXEHT"})
} else if strings.HasPrefix(c.Request.Header.Get("Authorization"), "Bearer sk-") {
c.JSON(401, gin.H{"error": "You tried to use the official API key which is not supported."})
} else if strings.HasPrefix(c.Request.Header.Get("Authorization"), "Bearer eyJhbGciOiJSUzI1NiI") {
return
} else {
c.JSON(401, gin.H{"error": "Invalid API key."})
}
c.Abort()
return
}