Skip to content

Commit 7f63a1f

Browse files
authored
Merge branch 'dev' into dev-patch-abskrj
2 parents 7c808e7 + 8b08eb9 commit 7f63a1f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

utils/helper.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,26 @@ package utils
33
import (
44
"bytes"
55
"crypto/rand"
6-
"encoding/binary"
6+
"encoding/base64"
77
"log"
8-
math_rand "math/rand"
9-
"strconv"
108
)
119

1210
/*
13-
VideoIDGen returns an unique videoID and appends the fileExtension to it,
11+
FileIDGen returns an unique videoID and appends the fileExtension to it,
1412
it takes the fileExtensionas parameter
1513
*/
1614
func FileIDGen(fileExtension string) string {
17-
var b [8]byte
18-
if _, err := rand.Read(b[:]); err != nil {
19-
return err.Error()
20-
}
15+
length := 8
16+
randomBytes := make([]byte, length)
2117

22-
var i int64 = int64(binary.LittleEndian.Uint64(b[:]))
23-
math_rand.Seed(i)
18+
_, err := rand.Read(randomBytes)
19+
if err != nil {
20+
return ""
21+
}
2422

25-
// Generate a 8 digit random number
26-
randomNumber := math_rand.Intn(99999999-10000000) + 10000000
23+
uid := base64.URLEncoding.EncodeToString(randomBytes)[:length]
2724

28-
// VideoID = (8-digit random number) + (file Name)
29-
return strconv.Itoa(randomNumber) + fileExtension
25+
return uid + fileExtension
3026
}
3127

3228
// WrapStringInQuotes returns the string wrapped in quotes

0 commit comments

Comments
 (0)