Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ws conn token error unprocessed #163

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/pkg/errors v0.9.1
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/shamsher31/goimgtype v1.0.0
github.com/sirupsen/logrus v1.9.2
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20220106031843-2efeb10ca2f6
google.golang.org/protobuf v1.31.0 // indirect
Expand All @@ -26,6 +25,7 @@ require golang.org/x/net v0.11.0
require (
github.com/OpenIMSDK/Open-IM-Server v0.0.0-20230712062720-2e6ea7b193c3
github.com/google/go-cmp v0.5.9
golang.org/x/image v0.3.0
)

require (
Expand All @@ -39,7 +39,6 @@ require (
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/mattn/go-sqlite3 v1.14.12 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/shamsher31/goimgext v1.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.0.2 // indirect
github.com/xdg-go/stringprep v1.0.2 // indirect
Expand All @@ -49,7 +48,6 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/image v0.3.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo=
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM=
github.com/shamsher31/goimgext v1.0.0 h1:wFKf9GeeE0Xr6UQtliaPgYYgTju2izobM7XpCEgUCC8=
github.com/shamsher31/goimgext v1.0.0/go.mod h1:rYLKgXuTGBIaH49z+jUVSWz7gUWIZmqvYUsdvJbNNOc=
github.com/shamsher31/goimgtype v1.0.0 h1:7nmPz5GEb01sjFUojCbZJcBI68A8tmLXoCFbb5I34u4=
github.com/shamsher31/goimgtype v1.0.0/go.mod h1:OZm3NZQDbK0ezlk9IV5oq3cWQwjF1oVSxKNx19bkf64=
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
32 changes: 32 additions & 0 deletions internal/conversation_msg/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package conversation_msg

import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
_ "golang.org/x/image/bmp"
_ "golang.org/x/image/tiff"
_ "golang.org/x/image/webp"
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"open_im_sdk/sdk_struct"
"os"
)

func getImageInfo(filePath string) (*sdk_struct.ImageInfo, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, errs.Wrap(err, "image file open err")
}
defer file.Close()
info, err := file.Stat()
if err != nil {
return nil, err
}
img, format, err := image.Decode(file)
if err != nil {
return nil, errs.Wrap(err, "image file decode err")
}
size := img.Bounds().Max
return &sdk_struct.ImageInfo{Width: int32(size.X), Height: int32(size.Y), Type: "image/" + format, Size: info.Size()}, nil
}
32 changes: 0 additions & 32 deletions internal/conversation_msg/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"context"
"fmt"
"image"
"open_im_sdk/internal/file"
"open_im_sdk/internal/util"
"open_im_sdk/open_im_sdk_callback"
Expand Down Expand Up @@ -47,7 +46,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"

"github.com/jinzhu/copier"
imgtype "github.com/shamsher31/goimgtype"
)

func (c *Conversation) GetAllConversationList(ctx context.Context) ([]*model_struct.LocalConversation, error) {
Expand Down Expand Up @@ -1048,36 +1046,6 @@ func (c *Conversation) SearchLocalMessages(ctx context.Context, searchParam *sdk
func (c *Conversation) SetMessageLocalEx(ctx context.Context, conversationID string, clientMsgID string, localEx string) error {
return c.db.UpdateColumnsMessage(ctx, conversationID, clientMsgID, map[string]interface{}{"local_ex": localEx})
}
func getImageInfo(filePath string) (*sdk_struct.ImageInfo, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, utils.Wrap(err, "open file err")
}
defer func() {
if file != nil {
file.Close()
}
}()

img, _, err := image.Decode(file)
if err != nil {
return nil, utils.Wrap(err, "image file Decode err")
}

datatype, err := imgtype.Get(filePath)
if err != nil {
return nil, utils.Wrap(err, "image file get type err")
}
fi, err := os.Stat(filePath)
if err != nil {
return nil, utils.Wrap(err, "image file Stat err")
}

b := img.Bounds()

return &sdk_struct.ImageInfo{int32(b.Max.X), int32(b.Max.Y), datatype, fi.Size()}, nil

}

func (c *Conversation) initBasicInfo(ctx context.Context, message *sdk_struct.MsgStruct, msgFrom, contentType int32) error {
message.CreateTime = utils.GetCurrentTimestampByMill()
Expand Down
15 changes: 14 additions & 1 deletion internal/interaction/long_conn_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,20 @@ func (c *LongConnMgr) reConn(ctx context.Context, num *int) error {
if err := json.Unmarshal(body, &apiResp); err != nil {
return err
}
c.listener.OnConnectFailed(int32(apiResp.ErrCode), apiResp.ErrMsg)
switch apiResp.ErrCode {
case
errs.TokenExpiredError,
errs.TokenInvalidError,
errs.TokenMalformedError,
errs.TokenNotValidYetError,
errs.TokenUnknownError,
errs.TokenKickedError,
errs.TokenNotExistError:
c.listener.OnUserTokenExpired()
_ = common.TriggerCmdLogOut(ctx, c.loginMgrCh)
default:
c.listener.OnConnectFailed(int32(apiResp.ErrCode), apiResp.ErrMsg)
}
log.ZWarn(ctx, "long conn establish failed", sdkerrs.New(apiResp.ErrCode, apiResp.ErrMsg, apiResp.ErrDlt))
return errs.NewCodeError(apiResp.ErrCode, apiResp.ErrMsg).WithDetail(apiResp.ErrDlt).Wrap()
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/content_type/content_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var ext = map[string]string{
"jpeg": "image/jpeg",
"gif": "image/gif",
"bmp": "image/bmp",
"tif": "image/tiff",
"tiff": "image/tiff",
"ico": "image/x-icon",
"svg": "image/svg+xml",
"webp": "image/webp",
Expand Down
Loading