@ -19,11 +19,12 @@ import (
"path/filepath"
"path/filepath"
"time"
"time"
redis 2 "github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/redis"
redis Cache "github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/redis"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
"github.com/openimsdk/tools/db/pagination"
"github.com/openimsdk/tools/s3"
"github.com/openimsdk/tools/s3"
"github.com/openimsdk/tools/s3/cont"
"github.com/openimsdk/tools/s3/cont"
"github.com/redis/go-redis/v9"
"github.com/redis/go-redis/v9"
@ -39,15 +40,19 @@ type S3Database interface {
SetObject ( ctx context . Context , info * model . Object ) error
SetObject ( ctx context . Context , info * model . Object ) error
StatObject ( ctx context . Context , name string ) ( * s3 . ObjectInfo , error )
StatObject ( ctx context . Context , name string ) ( * s3 . ObjectInfo , error )
FormData ( ctx context . Context , name string , size int64 , contentType string , duration time . Duration ) ( * s3 . FormData , error )
FormData ( ctx context . Context , name string , size int64 , contentType string , duration time . Duration ) ( * s3 . FormData , error )
FindByExpires ( ctx context . Context , duration time . Time ) ( [ ] * model . Object , error )
FindByExpires ( ctx context . Context , duration time . Time , pagination pagination . Pagination ) ( total int64 , objects [ ] * model . Object , err error )
DeleteObject ( ctx context . Context , name string ) error
DeleteObject ( ctx context . Context , name string ) error
DeleteSpecifiedData ( ctx context . Context , engine string , name string ) error
DeleteSpecifiedData ( ctx context . Context , engine string , name string ) error
FindNotDelByS3 ( ctx context . Context , key string , duration time . Time ) ( int64 , error )
DelS3Key ( ctx context . Context , engine string , keys ... string ) error
GetImageThumbnailKey ( ctx context . Context , name string ) ( string , error )
}
}
func NewS3Database ( rdb redis . UniversalClient , s3 s3 . Interface , obj database . ObjectInfo ) S3Database {
func NewS3Database ( rdb redis . UniversalClient , s3 s3 . Interface , obj database . ObjectInfo ) S3Database {
return & s3Database {
return & s3Database {
s3 : cont . New ( redis2 . NewS3Cache ( rdb , s3 ) , s3 ) ,
s3 : cont . New ( redisCache . NewS3Cache ( rdb , s3 ) , s3 ) ,
cache : redis2 . NewObjectCacheRedis ( rdb , obj ) ,
cache : redisCache . NewObjectCacheRedis ( rdb , obj ) ,
s3cache : redisCache . NewS3Cache ( rdb , s3 ) ,
db : obj ,
db : obj ,
}
}
}
}
@ -55,6 +60,7 @@ func NewS3Database(rdb redis.UniversalClient, s3 s3.Interface, obj database.Obje
type s3Database struct {
type s3Database struct {
s3 * cont . Controller
s3 * cont . Controller
cache cache . ObjectCache
cache cache . ObjectCache
s3cache cont . S3Cache
db database . ObjectInfo
db database . ObjectInfo
}
}
@ -115,8 +121,9 @@ func (s *s3Database) StatObject(ctx context.Context, name string) (*s3.ObjectInf
func ( s * s3Database ) FormData ( ctx context . Context , name string , size int64 , contentType string , duration time . Duration ) ( * s3 . FormData , error ) {
func ( s * s3Database ) FormData ( ctx context . Context , name string , size int64 , contentType string , duration time . Duration ) ( * s3 . FormData , error ) {
return s . s3 . FormData ( ctx , name , size , contentType , duration )
return s . s3 . FormData ( ctx , name , size , contentType , duration )
}
}
func ( s * s3Database ) FindByExpires ( ctx context . Context , duration time . Time ) ( [ ] * model . Object , error ) {
func ( s * s3Database ) FindByExpires ( ctx context . Context , duration time . Time , pagination pagination . Pagination ) ( total int64 , objects [ ] * model . Object , err error ) {
return s . db . FindByExpires ( ctx , duration )
return s . db . FindByExpires ( ctx , duration , pagination )
}
}
func ( s * s3Database ) DeleteObject ( ctx context . Context , name string ) error {
func ( s * s3Database ) DeleteObject ( ctx context . Context , name string ) error {
@ -125,3 +132,15 @@ func (s *s3Database) DeleteObject(ctx context.Context, name string) error {
func ( s * s3Database ) DeleteSpecifiedData ( ctx context . Context , engine string , name string ) error {
func ( s * s3Database ) DeleteSpecifiedData ( ctx context . Context , engine string , name string ) error {
return s . db . Delete ( ctx , engine , name )
return s . db . Delete ( ctx , engine , name )
}
}
func ( s * s3Database ) FindNotDelByS3 ( ctx context . Context , key string , duration time . Time ) ( int64 , error ) {
return s . db . FindNotDelByS3 ( ctx , key , duration )
}
func ( s * s3Database ) DelS3Key ( ctx context . Context , engine string , keys ... string ) error {
return s . s3cache . DelS3Key ( ctx , engine , keys ... )
}
func ( s * s3Database ) GetImageThumbnailKey ( ctx context . Context , name string ) ( string , error ) {
return s . s3 . GetImageThumbnailKey ( ctx , name )
}