mirror of
https://github.com/retailcrm/mg-bot-helper.git
synced 2025-04-20 01:10:58 +00:00
Add url normalizer
This commit is contained in:
parent
8b35fde2df
commit
62636a5f32
3 changed files with 13 additions and 5 deletions
|
@ -1,5 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var rx = regexp.MustCompile(`/+$`)
|
||||
|
||||
func getConnection(uid string) *Connection {
|
||||
var connection Connection
|
||||
orm.DB.First(&connection, "client_id = ?", uid)
|
||||
|
@ -32,3 +38,7 @@ func (c *Connection) createConnection() error {
|
|||
func (c *Connection) saveConnection() error {
|
||||
return orm.DB.Model(c).Where("client_id = ?", c.ClientID).Update(c).Error
|
||||
}
|
||||
|
||||
func (c *Connection) NormalizeApiUrl() {
|
||||
c.APIURL = rx.ReplaceAllString(c.APIURL, ``)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -195,8 +194,9 @@ func activityHandler(c *gin.Context) {
|
|||
conn.Active = activity.Active && !activity.Freeze
|
||||
|
||||
if systemUrl != "" {
|
||||
conn.APIURL = strings.TrimRight(systemUrl, "/")
|
||||
conn.APIURL = systemUrl
|
||||
}
|
||||
conn.NormalizeApiUrl()
|
||||
|
||||
if err := conn.setConnectionActivity(); err != nil {
|
||||
c.Error(err)
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"syscall"
|
||||
|
||||
"github.com/getsentry/raven-go"
|
||||
|
@ -24,7 +23,6 @@ func init() {
|
|||
|
||||
var (
|
||||
sentry *raven.Client
|
||||
rx = regexp.MustCompile(`/+$`)
|
||||
wm = NewWorkersManager()
|
||||
)
|
||||
|
||||
|
@ -129,7 +127,7 @@ func checkConnectionForRequest() gin.HandlerFunc {
|
|||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": getLocalizedMessage("incorrect_url_key")})
|
||||
return
|
||||
}
|
||||
conn.APIURL = rx.ReplaceAllString(conn.APIURL, ``)
|
||||
conn.NormalizeApiUrl()
|
||||
|
||||
c.Set("connection", conn)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue