This commit is contained in:
withchao 2023-04-23 11:44:33 +08:00
parent f815e9bd9a
commit cfbf1593c6
3 changed files with 29 additions and 5 deletions

View File

@ -96,7 +96,7 @@ credential: #腾讯cos发送图片、视频、文件时需要请自行申
object: object:
enable: minio enable: minio
apiURL: http://127.0.0.1:10002/third/object?name= apiURL: http://127.0.0.1:10002/third/object
minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK中 object_storage参数为minio minio: #MinIO 发送图片、视频、文件时需要,请自行申请后替换,必须修改。 客户端初始化InitSDK中 object_storage参数为minio
tempBucket: "openim" tempBucket: "openim"
dataBucket: "openim" dataBucket: "openim"

View File

@ -2,6 +2,7 @@ package third
import ( import (
"context" "context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/obj" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/obj"
@ -11,9 +12,14 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check" "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check"
"google.golang.org/grpc" "google.golang.org/grpc"
"net/url"
) )
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error { func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
u, err := url.Parse(config.Config.Object.ApiURL)
if err != nil {
return err
}
rdb, err := cache.NewRedis() rdb, err := cache.NewRedis()
if err != nil { if err != nil {
return err return err
@ -32,7 +38,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
third.RegisterThirdServer(server, &thirdServer{ third.RegisterThirdServer(server, &thirdServer{
thirdDatabase: controller.NewThirdDatabase(cache.NewCacheModel(rdb)), thirdDatabase: controller.NewThirdDatabase(cache.NewCacheModel(rdb)),
userCheck: check.NewUserCheck(client), userCheck: check.NewUserCheck(client),
s3dataBase: controller.NewS3Database(o, relation.NewObjectHash(db), relation.NewObjectInfo(db), relation.NewObjectPut(db)), s3dataBase: controller.NewS3Database(o, relation.NewObjectHash(db), relation.NewObjectInfo(db), relation.NewObjectPut(db), u),
}) })
return nil return nil
} }

View File

@ -9,7 +9,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/obj" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/obj"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "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/log"
@ -18,6 +17,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/google/uuid" "github.com/google/uuid"
"io" "io"
"net/url"
"path" "path"
"strconv" "strconv"
"time" "time"
@ -39,8 +39,9 @@ type S3Database interface {
CleanExpirationObject(ctx context.Context, t time.Time) CleanExpirationObject(ctx context.Context, t time.Time)
} }
func NewS3Database(obj obj.Interface, hash relation.ObjectHashModelInterface, info relation.ObjectInfoModelInterface, put relation.ObjectPutModelInterface) S3Database { func NewS3Database(obj obj.Interface, hash relation.ObjectHashModelInterface, info relation.ObjectInfoModelInterface, put relation.ObjectPutModelInterface, url *url.URL) S3Database {
return &s3Database{ return &s3Database{
url: url,
obj: obj, obj: obj,
hash: hash, hash: hash,
info: info, info: info,
@ -49,6 +50,7 @@ func NewS3Database(obj obj.Interface, hash relation.ObjectHashModelInterface, in
} }
type s3Database struct { type s3Database struct {
url *url.URL
obj obj.Interface obj obj.Interface
hash relation.ObjectHashModelInterface hash relation.ObjectHashModelInterface
info relation.ObjectInfoModelInterface info relation.ObjectInfoModelInterface
@ -96,7 +98,23 @@ func (c *s3Database) CheckHash(hash string) error {
} }
func (c *s3Database) urlName(name string) string { func (c *s3Database) urlName(name string) string {
return config.Config.Object.ApiURL + name u := url.URL{
Scheme: c.url.Scheme,
Opaque: c.url.Opaque,
User: c.url.User,
Host: c.url.Host,
Path: c.url.Path,
RawPath: c.url.RawPath,
OmitHost: c.url.OmitHost,
ForceQuery: c.url.ForceQuery,
RawQuery: c.url.RawQuery,
Fragment: c.url.Fragment,
RawFragment: c.url.RawFragment,
}
v := make(url.Values, 1)
v.Set("name", name)
u.RawQuery = v.Encode()
return u.String()
} }
func (c *s3Database) UUID() string { func (c *s3Database) UUID() string {