feat: custom hide error message by regexp (close #1468)

This commit is contained in:
Noah Hsu
2022-08-08 12:52:54 +08:00
parent d6437a337f
commit 2b04cf4ac3
8 changed files with 144 additions and 20 deletions

View File

@ -1,11 +1,23 @@
package common
import (
"strings"
"github.com/alist-org/alist/v3/cmd/flags"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
func hidePrivacy(msg string) string {
for _, r := range conf.PrivacyReg {
msg = r.ReplaceAllStringFunc(msg, func(s string) string {
return strings.Repeat("*", len(s))
})
}
return msg
}
// ErrorResp is used to return error response
// @param l: if true, log error
func ErrorResp(c *gin.Context, err error, code int, l ...bool) {
@ -18,7 +30,7 @@ func ErrorResp(c *gin.Context, err error, code int, l ...bool) {
}
c.JSON(200, Resp{
Code: code,
Message: err.Error(),
Message: hidePrivacy(err.Error()),
Data: nil,
})
c.Abort()
@ -30,7 +42,7 @@ func ErrorStrResp(c *gin.Context, str string, code int, l ...bool) {
}
c.JSON(200, Resp{
Code: code,
Message: str,
Message: hidePrivacy(str),
Data: nil,
})
c.Abort()