You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
631 B

package app
import (
"io/ioutil"
"recook/internal/back"
"recook/internal/secure"
"strings"
"github.com/gin-gonic/gin"
)
func decrypt() gin.HandlerFunc {
return func(c *gin.Context) {
if c.Request.Method == "POST" &&
strings.Contains(c.Request.Header.Get("Content-Type"), "application/json") &&
!strings.Contains(c.Request.URL.Path, "callback") {
b, _ := ioutil.ReadAll(c.Request.Body)
if len(b) == 0 {
c.Set("recook", nil)
} else {
body, err := secure.Decrypt(b)
if err != nil {
back.Err(c, err.Error())
c.Abort()
return
}
c.Set("recook", body)
}
}
c.Next()
}
}