update api request required

pull/1499/head
AndrewZuo01 2 years ago
parent 44f1578d8e
commit 0c0bfe1f51

@ -23,6 +23,7 @@ func main() {
msgGatewayCmd.AddWsPortFlag() msgGatewayCmd.AddWsPortFlag()
msgGatewayCmd.AddPortFlag() msgGatewayCmd.AddPortFlag()
msgGatewayCmd.AddPrometheusPortFlag() msgGatewayCmd.AddPrometheusPortFlag()
if err := msgGatewayCmd.Exec(); err != nil { if err := msgGatewayCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }

@ -19,9 +19,9 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10" "github.com/go-playground/validator/v10"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/openimsdk/open-im-server/v3/pkg/authverify" "github.com/openimsdk/open-im-server/v3/pkg/authverify"
"github.com/openimsdk/open-im-server/v3/pkg/common/config" "github.com/openimsdk/open-im-server/v3/pkg/common/config"
"strings"
"github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/msg"
@ -150,19 +150,44 @@ func (m *MessageApi) DeleteMsgPhysicalBySeq(c *gin.Context) {
func (m *MessageApi) DeleteMsgPhysical(c *gin.Context) { func (m *MessageApi) DeleteMsgPhysical(c *gin.Context) {
a2r.Call(msg.MsgClient.DeleteMsgPhysical, m.Client, c) a2r.Call(msg.MsgClient.DeleteMsgPhysical, m.Client, c)
} }
func isValidFileExtension(fileURL string, validExtensions []string) bool {
for _, ext := range validExtensions {
if strings.HasSuffix(strings.ToLower(fileURL), ext) {
return true
}
}
return false
}
func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendMsgReq *msg.SendMsgReq, err error) { func (m *MessageApi) getSendMsgReq(c *gin.Context, req apistruct.SendMsg) (sendMsgReq *msg.SendMsgReq, err error) {
var data interface{} var data interface{}
log.ZDebug(c, "getSendMsgReq", "req", req.Content) log.ZDebug(c, "getSendMsgReq", "req", req.Content)
switch req.ContentType { switch req.ContentType {
case constant.Text: case constant.Text:
data = apistruct.TextElem{} data = apistruct.TextElem{}
case constant.Picture: case constant.Picture:
data = apistruct.PictureElem{} data = apistruct.PictureElem{}
validPictureExtensions := []string{".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".heic", ".webp", ".svg"}
if !isValidFileExtension(data.(apistruct.PictureElem).SnapshotPicture.Url, validPictureExtensions) {
return nil, errs.ErrArgs.WithDetail("SnapshotPicture file must be in a valid format (e.g., .jpg, .jpeg, .png, .gif, .bmp, .tiff, .heic, .webp, .svg)")
}
if !isValidFileExtension(data.(apistruct.PictureElem).BigPicture.Url, validPictureExtensions) {
return nil, errs.ErrArgs.WithDetail("BigPicture file must be in a valid format (e.g., .jpg, .jpeg, .png, .gif, .bmp, .tiff, .heic, .webp, .svg)")
}
if !isValidFileExtension(data.(apistruct.PictureElem).SourcePicture.Url, validPictureExtensions) {
return nil, errs.ErrArgs.WithDetail("SourcePicture file must be in a valid format (e.g., .jpg, .jpeg, .png, .gif, .bmp, .tiff, .heic, .webp, .svg)")
}
case constant.Voice: case constant.Voice:
data = apistruct.SoundElem{} data = apistruct.SoundElem{}
if !isValidFileExtension(data.(apistruct.PictureElem).SourcePicture.Url, validPictureExtensions) {
return nil, errs.ErrArgs.WithDetail("picture file must be in a valid format (e.g., .jpg, .jpeg, .png, .gif, .bmp, .tiff, .heic, .webp, .svg)")
}
case constant.Video: case constant.Video:
data = apistruct.VideoElem{} data = apistruct.VideoElem{}
validVideoExtensions := []string{".mp4", ".avi", ".mov", ".wmv", ".flv", ".mkv"}
if !isValidFileExtension(data.(apistruct.VideoElem).VideoURL, validVideoExtensions) {
return nil, errs.ErrArgs.WithDetail("video file must be in a valid format (e.g., .mp4, .avi, .mov, .wmv, .flv, .mkv)")
}
case constant.File: case constant.File:
data = apistruct.FileElem{} data = apistruct.FileElem{}
case constant.Custom: case constant.Custom:

@ -117,6 +117,7 @@ func (ws *WsServer) UnRegister(c *Client) {
} }
func (ws *WsServer) Validate(s interface{}) error { func (ws *WsServer) Validate(s interface{}) error {
//?question?
return nil return nil
} }

@ -16,56 +16,56 @@ package apistruct
type PictureBaseInfo struct { type PictureBaseInfo struct {
UUID string `mapstructure:"uuid"` UUID string `mapstructure:"uuid"`
Type string `mapstructure:"type"` Type string `mapstructure:"type" validate:"required"`
Size int64 `mapstructure:"size"` Size int64 `mapstructure:"size"`
Width int32 `mapstructure:"width"` Width int32 `mapstructure:"width" validate:"required"`
Height int32 `mapstructure:"height"` Height int32 `mapstructure:"height" validate:"required"`
Url string `mapstructure:"url"` Url string `mapstructure:"url" validate:"required"`
} }
type PictureElem struct { type PictureElem struct {
SourcePath string `mapstructure:"sourcePath"` SourcePath string `mapstructure:"sourcePath"`
SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"` SourcePicture PictureBaseInfo `mapstructure:"sourcePicture" validate:"required"`
BigPicture PictureBaseInfo `mapstructure:"bigPicture"` BigPicture PictureBaseInfo `mapstructure:"bigPicture" validate:"required"`
SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"` SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture" validate:"required"`
} }
type SoundElem struct { type SoundElem struct {
UUID string `mapstructure:"uuid"` UUID string `mapstructure:"uuid"`
SoundPath string `mapstructure:"soundPath"` SoundPath string `mapstructure:"soundPath"`
SourceURL string `mapstructure:"sourceUrl"` SourceURL string `mapstructure:"sourceUrl" validate:"required"`
DataSize int64 `mapstructure:"dataSize"` DataSize int64 `mapstructure:"dataSize"`
Duration int64 `mapstructure:"duration"` Duration int64 `mapstructure:"duration" validate:"required,min=1"`
} }
type VideoElem struct { type VideoElem struct {
VideoPath string `mapstructure:"videoPath"` VideoPath string `mapstructure:"videoPath" `
VideoUUID string `mapstructure:"videoUUID"` VideoUUID string `mapstructure:"videoUUID"`
VideoURL string `mapstructure:"videoUrl"` VideoURL string `mapstructure:"videoUrl" validate:"required"`
VideoType string `mapstructure:"videoType"` VideoType string `mapstructure:"videoType" validate:"required"`
VideoSize int64 `mapstructure:"videoSize"` VideoSize int64 `mapstructure:"videoSize" validate:"required"`
Duration int64 `mapstructure:"duration"` Duration int64 `mapstructure:"duration" validate:"required"`
SnapshotPath string `mapstructure:"snapshotPath"` SnapshotPath string `mapstructure:"snapshotPath"`
SnapshotUUID string `mapstructure:"snapshotUUID"` SnapshotUUID string `mapstructure:"snapshotUUID"`
SnapshotSize int64 `mapstructure:"snapshotSize"` SnapshotSize int64 `mapstructure:"snapshotSize"`
SnapshotURL string `mapstructure:"snapshotUrl"` SnapshotURL string `mapstructure:"snapshotUrl" validate:"required"`
SnapshotWidth int32 `mapstructure:"snapshotWidth"` SnapshotWidth int32 `mapstructure:"snapshotWidth" validate:"required"`
SnapshotHeight int32 `mapstructure:"snapshotHeight"` SnapshotHeight int32 `mapstructure:"snapshotHeight"validate:"required"`
} }
type FileElem struct { type FileElem struct {
FilePath string `mapstructure:"filePath"` FilePath string `mapstructure:"filePath" `
UUID string `mapstructure:"uuid"` UUID string `mapstructure:"uuid"`
SourceURL string `mapstructure:"sourceUrl"` SourceURL string `mapstructure:"sourceUrl" validate:"required"`
FileName string `mapstructure:"fileName"` FileName string `mapstructure:"fileName" validate:"required"`
FileSize int64 `mapstructure:"fileSize"` FileSize int64 `mapstructure:"fileSize" validate:"required"`
} }
type AtElem struct { type AtElem struct {
Text string `mapstructure:"text"` Text string `mapstructure:"text"`
AtUserList []string `mapstructure:"atUserList"` AtUserList []string `mapstructure:"atUserList" validate:"required,max=1000"`
IsAtSelf bool `mapstructure:"isAtSelf"` IsAtSelf bool `mapstructure:"isAtSelf"`
} }
type LocationElem struct { type LocationElem struct {
Description string `mapstructure:"description"` Description string `mapstructure:"description" `
Longitude float64 `mapstructure:"longitude"` Longitude float64 `mapstructure:"longitude" validate:"required"`
Latitude float64 `mapstructure:"latitude"` Latitude float64 `mapstructure:"latitude" validate:"required"`
} }
type CustomElem struct { type CustomElem struct {
Data string `mapstructure:"data" validate:"required"` Data string `mapstructure:"data" validate:"required"`

Loading…
Cancel
Save