switch url to id in invitation process

This commit is contained in:
ycc
2023-08-31 23:51:20 +02:00
parent 539e2c528e
commit e0faaf8cef
5 changed files with 208 additions and 209 deletions

View File

@ -9,7 +9,7 @@ import (
)
func (r *RedisRouter) CreateInvitation(invitation []byte, timeout int, password string, serverTimeout int, urlLen int) (string, time.Time) {
id := r.createShortUrl(urlLen)
id := r.createShortId(urlLen)
if timeout > serverTimeout {
timeout = serverTimeout
}
@ -54,17 +54,17 @@ func (r *RedisRouter) GetInvitationAnswer(id string) ([]byte, error) {
return []byte(mwan), nil
}
func (r *RedisRouter) createShortUrl(length int) string {
url := ""
func (r *RedisRouter) createShortId(length int) string {
id := ""
alphabet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
// for not in redis
for {
for i := 1; i <= length; i++ {
url += string(alphabet[rand.Intn(61)])
id += string(alphabet[rand.Intn(61)])
}
if r.Client.Get("mwiv:"+url).Err() == redis.Nil {
if r.Client.Get("mwiv:"+id).Err() == redis.Nil {
break
}
}
return url
return id
}