Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Jun 3, 2023
1 parent 3a1590d commit 28266ac
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 60 deletions.
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/ansrivas/fiberprometheus/v2 v2.6.0
github.com/antoniodipinto/ikisocket v0.0.0-20230224142534-cb796a15fd08
github.com/gabriel-vasile/mimetype v1.4.2
github.com/go-playground/validator/v10 v10.14.0
github.com/goccy/go-json v0.10.2
github.com/gofiber/fiber/v2 v2.46.0
github.com/gofiber/template v1.8.1
Expand Down Expand Up @@ -43,15 +42,12 @@ require (
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gofiber/adaptor/v2 v2.2.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jxskiss/base62 v1.1.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lithammer/shortuuid/v4 v4.0.0 // indirect
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 // indirect
github.com/livekit/mediatransportutil v0.0.0-20230523035537-27577c4e1646 // indirect
Expand Down
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down Expand Up @@ -346,8 +339,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/lithammer/shortuuid/v4 v4.0.0 h1:QRbbVkfgNippHOS8PXDkti4NaWeyYfcBTHtw7k08o4c=
github.com/lithammer/shortuuid/v4 v4.0.0/go.mod h1:Zs8puNcrvf2rV9rTH51ZLLcj7ZXqQI3lv67aw4KiB1Y=
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkDaKb5iXdynYrzB84ErPPO4LbRASk58=
Expand Down
34 changes: 0 additions & 34 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"database/sql"
"github.com/go-playground/validator/v10"
"github.com/mynaparrot/plugnmeet-protocol/factory"
"github.com/mynaparrot/plugnmeet-protocol/plugnmeet"
"github.com/mynaparrot/plugnmeet-protocol/utils"
Expand All @@ -11,9 +10,6 @@ import (
"gopkg.in/natefinch/lumberjack.v2"
"io"
"os"
"reflect"
"regexp"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -165,36 +161,6 @@ type ErrorResponse struct {
Tag string
}

func (a *AppConfig) DoValidateReq(r interface{}) []*ErrorResponse {
var errors []*ErrorResponse

validate := validator.New()
_ = validate.RegisterValidation("require-valid-Id", ValidateId)
validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
if name == "-" {
return ""
}
return name
})

err := validate.Struct(r)
if err != nil {
for _, err := range err.(validator.ValidationErrors) {
var element ErrorResponse
element.FailedField = err.Field()
element.Tag = err.Tag()
errors = append(errors, &element)
}
}
return errors
}

func ValidateId(fl validator.FieldLevel) bool {
isValid := regexp.MustCompile(`^[a-zA-Z0-9\-_.:]+$`).MatchString
return isValid(fl.Field().String())
}

func (a *AppConfig) FormatDBTable(table string) string {
if a.MySqlInfo.Prefix != "" {
return a.MySqlInfo.Prefix + table
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/manage_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ func HandleFileUpload(c *fiber.Ctx) error {
})
}

check := config.AppCnf.DoValidateReq(req)
if len(check) > 0 {
if req.Sid == "" || req.RoomId == "" || req.UserId == "" {
_ = c.SendStatus(fiber.StatusBadRequest)
return c.JSON(fiber.Map{
"status": false,
"msg": check,
"msg": "missing required fields",
})
}

Expand Down Expand Up @@ -103,11 +102,12 @@ func HandleConvertWhiteboardFile(c *fiber.Ctx) error {
"msg": err.Error(),
})
}
check := config.AppCnf.DoValidateReq(req)
if len(check) > 0 {

if req.Sid == "" || req.RoomId == "" || req.UserId == "" {
_ = c.SendStatus(fiber.StatusBadRequest)
return c.JSON(fiber.Map{
"status": false,
"msg": check,
"msg": "missing required fields",
})
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/models/data_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
)

type DataMessageReq struct {
Sid string `json:"sid" validate:"required"`
RoomId string `json:"room_id" validate:"required"`
MsgType string `json:"msg_type" validate:"required"`
Msg string `json:"msg" validate:"required"`
Sid string `json:"sid"`
RoomId string `json:"room_id"`
MsgType string `json:"msg_type"`
Msg string `json:"msg"`
RequestedUserId string `json:"-"`
SendTo []string // user sids
IsAdmin bool
Expand Down
6 changes: 3 additions & 3 deletions pkg/models/manage_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
)

type ManageFile struct {
Sid string `json:"sid" validate:"required"`
RoomId string `json:"roomId" validate:"required"`
UserId string `json:"userId" validate:"required"`
Sid string `json:"sid"`
RoomId string `json:"roomId"`
UserId string `json:"userId"`
FilePath string `json:"file_path"`
Resumable bool `json:"resumable"`
uploadFileSettings *config.UploadFileSettings
Expand Down

0 comments on commit 28266ac

Please sign in to comment.