store unknown servers in the invitation process answer and finalize + server storage fixes and testing
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2024-06-05 14:45:01 +02:00
parent c0fd74f1e6
commit af55df1ff5
4 changed files with 172 additions and 4 deletions

View File

@ -55,6 +55,39 @@ func (ss *ServerStorage) StoreServer(sc *Server) error {
}
// Check if a server exists in a badger database with Server.GetUid() as key
func (ss *ServerStorage) ServerExists(sc *Server) (bool, error) {
err := ss.open()
if err != nil {
return false, err
}
defer ss.close()
shakey := sha256.Sum256([]byte(sc.GetServerCard().GetUid()))
key := shakey[:]
// check if key exists in badger database
err = ss.db.View(func(txn *badger.Txn) error {
_, err := txn.Get(key)
return err
}) // Add a comma here
if err != nil { // key does not exist
return false, nil
}
return true, nil
}
// Store a server in a badger database with Server.GetUid() as key if it is not already there
func (ss *ServerStorage) StoreServerIfNotExists(sc *Server) error {
exists, err := ss.ServerExists(sc)
if err != nil {
return err
}
if !exists {
return ss.StoreServer(sc)
}
return nil
}
// LoadServer function loads a Server from a badger database with Server.GetUid() as key
func (ss *ServerStorage) LoadServer(uid string) (*Server, error) {
var sc Server