From 95ec99daf0d20ec39311f7bbaac4f384e3596a47 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 12 Jul 2023 21:33:11 +0800 Subject: [PATCH 1/2] fix bug ContentType is wrong range for Check --- pkg/common/constant/constant.go | 27 ++++++++++++++------------- pkg/proto/sdkws/sdkws.go | 6 +++--- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 72cc34af8..f1abdcf64 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -4,19 +4,20 @@ const ( ///ContentType //UserRelated - Text = 101 - Picture = 102 - Voice = 103 - Video = 104 - File = 105 - AtText = 106 - Merger = 107 - Card = 108 - Location = 109 - Custom = 110 - Revoke = 111 - Typing = 113 - Quote = 114 + ContentTypeBegin = 100 + Text = 101 + Picture = 102 + Voice = 103 + Video = 104 + File = 105 + AtText = 106 + Merger = 107 + Card = 108 + Location = 109 + Custom = 110 + Revoke = 111 + Typing = 113 + Quote = 114 AdvancedText = 117 diff --git a/pkg/proto/sdkws/sdkws.go b/pkg/proto/sdkws/sdkws.go index 094cb823b..19bf7f968 100644 --- a/pkg/proto/sdkws/sdkws.go +++ b/pkg/proto/sdkws/sdkws.go @@ -12,10 +12,10 @@ func (x *MsgData) Check() error { if x.Content == nil { return errs.ErrArgs.Wrap("content is empty") } - if x.ContentType < 101 || x.ContentType > 203 { - return errs.ErrArgs.Wrap("content is empty") + if x.ContentType <= constant.ContentTypeBegin || x.ContentType >= constant.NotificationEnd { + return errs.ErrArgs.Wrap("content type is invalid") } - if x.SessionType < 1 || x.SessionType > 4 { + if x.SessionType < constant.SingleChatType || x.SessionType > constant.NotificationChatType { return errs.ErrArgs.Wrap("sessionType is invalid") } if x.SessionType == constant.SingleChatType || x.SessionType == constant.NotificationChatType { From b46f3410ad663738d1b691a17ca8d093d84d9cfb Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 12 Jul 2023 22:07:25 +0800 Subject: [PATCH 2/2] Add feature: Replace apiURL (in config.yaml) with an external IP address --- .env | 1 + install_im_server.sh | 4 ++++ scripts/init_pwd.sh | 2 ++ 3 files changed, 7 insertions(+) diff --git a/.env b/.env index 75f9707da..048662d97 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ USER=root PASSWORD=openIM123 MINIO_ENDPOINT=http://127.0.0.1:10005 +API_URL=http://127.0.0.1:10002/object/ DATA_DIR=./ diff --git a/install_im_server.sh b/install_im_server.sh index b08597e80..c526d43db 100644 --- a/install_im_server.sh +++ b/install_im_server.sh @@ -9,6 +9,10 @@ source .env echo $MINIO_ENDPOINT # Replace local IP address with the public IP address in .env file +if [ $API_URL == "http://127.0.0.1:10002/object/" ]; then + sed -i "s/127.0.0.1/${internet_ip}/" .env +fi + if [ $MINIO_ENDPOINT == "http://127.0.0.1:10005" ]; then sed -i "s/127.0.0.1/${internet_ip}/" .env fi diff --git a/scripts/init_pwd.sh b/scripts/init_pwd.sh index 25ee559a3..a3ce6048a 100755 --- a/scripts/init_pwd.sh +++ b/scripts/init_pwd.sh @@ -51,6 +51,8 @@ sed -i '/redis:/,/password:/s/password: .*/password: '${PASSWORD}'/' $config_fil sed -i "/minio:/,/isDistributedMod:/ s/accessKeyID:.*/accessKeyID: $USER/" $config_file sed -i "/minio:/,/isDistributedMod:/ s/secretAccessKey:.*/secretAccessKey: $PASSWORD/" $config_file sed -i '/minio:/,/endpoint:/s|endpoint: .*|endpoint: '${MINIO_ENDPOINT}'|' $config_file +sed -i '/object:/,/apiURL:/s|apiURL: .*|apiURL: '${API_URL}'|' $config_file + # Replace secret for token sed -i "s/secret: .*/secret: $PASSWORD/" $config_file