parent
7502b4ac0f
commit
7f815b3184
@ -0,0 +1,43 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/tx"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AesKeyDatabase interface {
|
||||
AcquireAesKey(ctx context.Context, conversationType int32, userId, friendId, groupId string) (key *relation.AesKeyModel, err error)
|
||||
AcquireAesKeys(ctx context.Context, userId string) (key []*relation.AesKeyModel, err error)
|
||||
}
|
||||
|
||||
type aesKeyDatabase struct {
|
||||
key relation.AesKeyModelInterface
|
||||
tx tx.Tx
|
||||
}
|
||||
|
||||
func newAesKeyDatabase(key relation.AesKeyModelInterface, tx tx.Tx) *aesKeyDatabase {
|
||||
return &aesKeyDatabase{key: key, tx: tx}
|
||||
}
|
||||
|
||||
func (a *aesKeyDatabase) AcquireAesKey(ctx context.Context, conversationType int32, userId, friendId, groupId string) (key *relation.AesKeyModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (a *aesKeyDatabase) AcquireAesKeys(ctx context.Context, userId string) (key []*relation.AesKeyModel, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (a *aesKeyDatabase) generateKeyConversationsID(args ...string) string {
|
||||
sort.Strings(args)
|
||||
combinedStr := strings.Join(args, "")
|
||||
md5Value := md5.Sum([]byte(combinedStr))
|
||||
md5Str := fmt.Sprintf("%x", md5Value)
|
||||
return md5Str[:16]
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/tools/utils"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AesKeyGorm struct {
|
||||
*MetaDB
|
||||
}
|
||||
|
||||
func NewAesKeyGorm(db *gorm.DB) *AesKeyGorm {
|
||||
return &AesKeyGorm{NewMetaDB(db, &relation.AesKeyModel{})}
|
||||
}
|
||||
|
||||
func (a *AesKeyGorm) Installs(ctx context.Context, keys []*relation.AesKeyModel) (err error) {
|
||||
return utils.Wrap(a.db(ctx).Create(&keys).Error, "")
|
||||
}
|
||||
|
||||
func (a *AesKeyGorm) GetAesKey(tx context.Context, KeyConversationsID string) (key *relation.AesKeyModel, err error) {
|
||||
key = &relation.AesKeyModel{}
|
||||
return key, utils.Wrap(a.db(tx).Where("key_conversations_id = ? ", KeyConversationsID).Take(key).Error, "")
|
||||
}
|
||||
|
||||
func (a *AesKeyGorm) GetAllAesKey(tx context.Context, UserID string) (keys []*relation.AesKeyModel, err error) {
|
||||
return keys, utils.Wrap(a.db(tx).Where("owner_user_id = ? or friend_user_id = ? ", UserID, UserID).Take(keys).Error, "")
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package relation
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
AesKeyModelTableName = "aes_keys"
|
||||
)
|
||||
|
||||
type AesKeyModel struct {
|
||||
KeyConversationsID string `gorm:"column:key_conversations_id;primary_key;size:64" json:"keyConversationsID"`
|
||||
Key string `gorm:"column:key" json:"key"`
|
||||
ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
OwnerUserID string `gorm:"column:owner_user_id;size:64" json:"ownerUserID"`
|
||||
FriendUserID string `gorm:"column:friend_user_id;size:64" json:"friendUserID"`
|
||||
GroupID string `gorm:"column:group_id;size:64" json:"groupID"`
|
||||
}
|
||||
|
||||
func (AesKeyModel) TableName() string {
|
||||
return AesKeyModelTableName
|
||||
}
|
||||
|
||||
type AesKeyModelInterface interface {
|
||||
Installs(ctx context.Context, friends []*AesKeyModel) (err error)
|
||||
GetAesKey(tx context.Context, KeyConversationsID string) (key *AesKeyModel, err error)
|
||||
GetAllAesKey(tx context.Context, UserID string) (key []*AesKeyModel, err error)
|
||||
}
|
Loading…
Reference in new issue