Kick off old clients

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-04-11 19:11:33 +08:00
parent 64fa24d6ce
commit 569c84175e
5 changed files with 19 additions and 5 deletions
+15 -1
View File
@@ -2,11 +2,25 @@ package middleware
import (
"honoka-chan/config"
"honoka-chan/database"
"honoka-chan/handler"
"honoka-chan/utils"
"net/http"
"github.com/gin-gonic/gin"
)
func KlabHeader(ctx *gin.Context) {
func CommonMid(ctx *gin.Context) {
authorizeStr := ctx.Request.Header["Authorize"]
userId := ctx.Request.Header[http.CanonicalHeaderKey("User-ID")]
if len(userId) > 0 {
authStr, _ := utils.GetAuthorizeToken(authorizeStr)
res, _ := database.LevelDb.Get([]byte(userId[0]))
if authStr != string(res) {
ctx.String(http.StatusForbidden, handler.ErrorMsg)
return
}
}
ctx.Header("Content-Type", "application/json; charset=utf-8")
ctx.Header("X-Powered-By", config.Conf.Server.PoweredBy)
ctx.Header("server_version", config.Conf.Server.VersionDate)