commit f767c5177e446adb29e7369848de1e96bcf351c2
parent d9fe68c4c7603b27e8965c2ab0f19d887ee60903
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 19 Jan 2023 03:51:18 -0800
simplify code
Diffstat:
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/pkg/web/handlers/api/v1/msgInterceptor.go b/pkg/web/handlers/api/v1/msgInterceptor.go
@@ -16,16 +16,10 @@ type MsgInterceptor struct{}
func (i MsgInterceptor) InterceptMsg(cmd *Command) {
// Only check maximum length of message if we are uploading a file
// Trim whitespaces and ensure minimum length
- trimmedMsg := strings.TrimSpace(cmd.message)
- if cmd.upload != nil && !utils.ValidateRuneLength(trimmedMsg, 0, maxMsgLen) {
+ minLen := utils.Ternary(cmd.upload != nil, 0, minMsgLen)
+ if !utils.ValidateRuneLength(strings.TrimSpace(cmd.message), minLen, maxMsgLen) {
cmd.dataMessage = cmd.origMessage
- cmd.err = fmt.Errorf("maximum %d characters", maxMsgLen)
- return
- }
- // Not uploading a file, check min and max length
- if cmd.upload == nil && !utils.ValidateRuneLength(trimmedMsg, minMsgLen, maxMsgLen) {
- cmd.dataMessage = cmd.origMessage
- cmd.err = fmt.Errorf("%d - %d characters", minMsgLen, maxMsgLen)
+ cmd.err = fmt.Errorf("%d - %d characters", minLen, maxMsgLen)
return
}