mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-05 20:11:14 +08:00
* statistics user register * refactor: router change * minio init * UserRegisterCount * push use local conn * refactor: user pb update * remove online push close grpc conn * refactor: user pb update * refactor:pb file * msgs statistics * msgs statistics * revoke userID * refactor: errcode update * active user * active user * active user * refactor: errcode update * feat: conn update token * active user * active user * feat: conn update token * active user * feat: conn update token * feat: conn update token * feat: conn update token * add tx_oss cos * active user * active user * group create * group create * feat: group notification show to conversation * feat: group notification show to conversation * group active * user active * sendNotificationWithName * withname * privateChat * a2r call option * grpc with detail return error * change log error * chain unary interceptor * api nil slice map * fix sync has read * fix: text update * fix: update add model * set conversations update * set privateChat * fix: content update * remove unuse rpc * msgDestruct * cron use rpc mw * set IsMsgDestruct * msg destruct * msgDestruct * s3 minio, cos, oss support * feat: add implement of GetUsersOnlineStatus, #472 (#477) * s3 minio, cos, oss support * s3 route * remove extendMsg code * s3 route * remove unuse code * s3 pb * s3 pb * s3 pb * s3 presigned put * s3 presigned test * s3 presigned test * s3 presigned test * s3 presigned test * s3 presigned test * s3 presigned test * s3 presigned test * s3 presigned test * Update .gitignore (#482) * s3 debug log * s3 debug log * cron add log and fix cron * add log * cron * s3 config * fix kick user bug * s3 cos * add kick log * s3 cos test * s3 cos test * s3 cos test * kick user log * kickuserlog * s3 cos copy * s3 cos copy * s3 url * s3 url * s3 AccessURL * log * s3 InitiateMultipartUpload add ExpireTime --------- Co-authored-by: withchao <993506633@qq.com> Co-authored-by: wangchuxiao <wangchuxiao97@outlook.com> Co-authored-by: BanTanger <88583317+BanTanger@users.noreply.github.com> Co-authored-by: withchao <48119764+withchao@users.noreply.github.com> Co-authored-by: Alan <68671759+hanzhixiao@users.noreply.github.com>
152 lines
4.6 KiB
Go
152 lines
4.6 KiB
Go
package third
|
|
|
|
import (
|
|
"context"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/s3/cont"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
|
"time"
|
|
)
|
|
|
|
func (t *thirdServer) PartLimit(ctx context.Context, req *third.PartLimitReq) (*third.PartLimitResp, error) {
|
|
limit := t.s3dataBase.PartLimit()
|
|
return &third.PartLimitResp{
|
|
MinPartSize: limit.MinPartSize,
|
|
MaxPartSize: limit.MaxPartSize,
|
|
MaxNumSize: int32(limit.MaxNumSize),
|
|
}, nil
|
|
}
|
|
|
|
func (t *thirdServer) PartSize(ctx context.Context, req *third.PartSizeReq) (*third.PartSizeResp, error) {
|
|
size, err := t.s3dataBase.PartSize(ctx, req.Size)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &third.PartSizeResp{Size: size}, nil
|
|
}
|
|
|
|
func (t *thirdServer) InitiateMultipartUpload(ctx context.Context, req *third.InitiateMultipartUploadReq) (*third.InitiateMultipartUploadResp, error) {
|
|
defer log.ZDebug(ctx, "return")
|
|
if err := checkUploadName(ctx, req.Name); err != nil {
|
|
return nil, err
|
|
}
|
|
expireTime := time.Now().Add(t.defaultExpire)
|
|
result, err := t.s3dataBase.InitiateMultipartUpload(ctx, req.Hash, req.Size, t.defaultExpire, int(req.MaxParts))
|
|
if err != nil {
|
|
if haErr, ok := errs.Unwrap(err).(*cont.HashAlreadyExistsError); ok {
|
|
obj := &relation.ObjectModel{
|
|
Name: req.Name,
|
|
UserID: mcontext.GetOpUserID(ctx),
|
|
Hash: req.Hash,
|
|
Key: haErr.Object.Key,
|
|
Size: haErr.Object.Size,
|
|
ContentType: req.ContentType,
|
|
Cause: req.Cause,
|
|
CreateTime: time.Now(),
|
|
}
|
|
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
|
return nil, err
|
|
}
|
|
return &third.InitiateMultipartUploadResp{
|
|
Url: t.apiAddress(obj.Name),
|
|
}, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
var sign *third.AuthSignParts
|
|
if result.Sign != nil && len(result.Sign.Parts) > 0 {
|
|
sign = &third.AuthSignParts{
|
|
Url: result.Sign.URL,
|
|
Query: toPbMapArray(result.Sign.Query),
|
|
Header: toPbMapArray(result.Sign.Header),
|
|
Parts: make([]*third.SignPart, len(result.Sign.Parts)),
|
|
}
|
|
for i, part := range result.Sign.Parts {
|
|
sign.Parts[i] = &third.SignPart{
|
|
PartNumber: int32(part.PartNumber),
|
|
Url: part.URL,
|
|
Query: toPbMapArray(part.Query),
|
|
Header: toPbMapArray(part.Header),
|
|
}
|
|
}
|
|
}
|
|
return &third.InitiateMultipartUploadResp{
|
|
Upload: &third.UploadInfo{
|
|
UploadID: result.UploadID,
|
|
PartSize: result.PartSize,
|
|
Sign: sign,
|
|
ExpireTime: expireTime.UnixMilli(),
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func (t *thirdServer) AuthSign(ctx context.Context, req *third.AuthSignReq) (*third.AuthSignResp, error) {
|
|
defer log.ZDebug(ctx, "return")
|
|
partNumbers := utils.Slice(req.PartNumbers, func(partNumber int32) int { return int(partNumber) })
|
|
result, err := t.s3dataBase.AuthSign(ctx, req.UploadID, partNumbers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp := &third.AuthSignResp{
|
|
Url: result.URL,
|
|
Query: toPbMapArray(result.Query),
|
|
Header: toPbMapArray(result.Header),
|
|
Parts: make([]*third.SignPart, len(result.Parts)),
|
|
}
|
|
for i, part := range result.Parts {
|
|
resp.Parts[i] = &third.SignPart{
|
|
PartNumber: int32(part.PartNumber),
|
|
Url: part.URL,
|
|
Query: toPbMapArray(part.Query),
|
|
Header: toPbMapArray(part.Header),
|
|
}
|
|
}
|
|
return resp, nil
|
|
}
|
|
|
|
func (t *thirdServer) CompleteMultipartUpload(ctx context.Context, req *third.CompleteMultipartUploadReq) (*third.CompleteMultipartUploadResp, error) {
|
|
defer log.ZDebug(ctx, "return")
|
|
if err := checkUploadName(ctx, req.Name); err != nil {
|
|
return nil, err
|
|
}
|
|
result, err := t.s3dataBase.CompleteMultipartUpload(ctx, req.UploadID, req.Parts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
obj := &relation.ObjectModel{
|
|
Name: req.Name,
|
|
UserID: mcontext.GetOpUserID(ctx),
|
|
Hash: result.Hash,
|
|
Key: result.Key,
|
|
Size: result.Size,
|
|
ContentType: req.ContentType,
|
|
Cause: req.Cause,
|
|
CreateTime: time.Now(),
|
|
}
|
|
if err := t.s3dataBase.SetObject(ctx, obj); err != nil {
|
|
return nil, err
|
|
}
|
|
return &third.CompleteMultipartUploadResp{
|
|
Url: t.apiAddress(obj.Name),
|
|
}, nil
|
|
}
|
|
|
|
func (t *thirdServer) AccessURL(ctx context.Context, req *third.AccessURLReq) (*third.AccessURLResp, error) {
|
|
expireTime, rawURL, err := t.s3dataBase.AccessURL(ctx, req.Name, t.defaultExpire)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &third.AccessURLResp{
|
|
Url: rawURL,
|
|
ExpireTime: expireTime.UnixMilli(),
|
|
}, nil
|
|
}
|
|
|
|
func (t *thirdServer) apiAddress(name string) string {
|
|
return t.apiURL + name
|
|
}
|