92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
package key
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type KeyObjectTypeEnum int
|
|
|
|
const (
|
|
KeyObjectTypeEnum_User KeyObjectTypeEnum = iota
|
|
KeyObjectTypeEnum_Doc
|
|
KeyObjectTypeEnum_KnowledgeBase
|
|
)
|
|
|
|
var objStringMap = map[KeyObjectTypeEnum]string{
|
|
KeyObjectTypeEnum_User: "user",
|
|
KeyObjectTypeEnum_Doc: "doc",
|
|
KeyObjectTypeEnum_KnowledgeBase: "doc",
|
|
}
|
|
|
|
func KeyIDByExternalID(obj KeyObjectTypeEnum, externalID string) string {
|
|
for k, v := range objStringMap {
|
|
if k == obj {
|
|
return fmt.Sprintf("dms:%s:extid:%s", v, externalID)
|
|
}
|
|
}
|
|
|
|
return fmt.Sprintf("dms:unknownobj_%d:extid:%s", int(obj), externalID)
|
|
}
|
|
|
|
func KeyModelByExternalID(obj KeyObjectTypeEnum, externalID string) string {
|
|
for k, v := range objStringMap {
|
|
if k == obj {
|
|
return fmt.Sprintf("dms:%s:model:%s", v, externalID)
|
|
}
|
|
}
|
|
|
|
return fmt.Sprintf("dms:unknownobj_%d:model:%s", int(obj), externalID)
|
|
}
|
|
|
|
func KeyDocSubtreeVersion(path string) string {
|
|
return fmt.Sprintf("dms:doc:version:%s", path)
|
|
}
|
|
|
|
func KeyDocSubtree(path string, version int64, depth *int) string {
|
|
depthKey := "all"
|
|
if depth != nil {
|
|
depthKey = fmt.Sprintf("%d", *depth)
|
|
}
|
|
return fmt.Sprintf("dms:doc:subtree:%s:v%d:%s", path, version, depthKey)
|
|
}
|
|
|
|
func KeyUserQueryList(queryHash string, page, pageSize int) string {
|
|
return fmt.Sprintf("dms:user:query:%s:p%d:s%d", queryHash, page, pageSize)
|
|
}
|
|
|
|
func KeyUserQueryPrefix() string {
|
|
return "dms:user:query:*"
|
|
}
|
|
|
|
func KeyUserQueryVersion() string {
|
|
return "dms:user:query:version"
|
|
}
|
|
|
|
func KeyJWTActiveToken(tokenHash string) string {
|
|
return fmt.Sprintf("dms:auth:jwt:active:%s", tokenHash)
|
|
}
|
|
|
|
func KeyJWTBlacklistToken(tokenHash string) string {
|
|
return fmt.Sprintf("dms:auth:jwt:blacklist:%s", tokenHash)
|
|
}
|
|
|
|
func KeyJWTUserTokenSet(userExternalID string) string {
|
|
return fmt.Sprintf("dms:auth:jwt:user_tokens:%s", userExternalID)
|
|
}
|
|
|
|
func KeyESDocumentIndex(prefix string) string {
|
|
return fmt.Sprintf("%s_documents", prefix)
|
|
}
|
|
|
|
func KeyCollabDocUpdates(docID string) string {
|
|
return fmt.Sprintf("collab:yjs:doc:updates:%s", docID)
|
|
}
|
|
|
|
func KeyCollabRoom(docID string) string {
|
|
return fmt.Sprintf("collab:room:doc-%s", docID)
|
|
}
|
|
|
|
func KeyCollabDirtyDocSet() string {
|
|
return "collab:yjs:dirty:doc"
|
|
}
|