blob: 779b95a91831fa32a545d58b9cf51a2ca599defa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package internal
import (
"crypto/md5"
"encoding/hex"
"fmt"
"time"
)
// GenerateCardID creates a unique ID for a card based on timestamp and Bulgarian word
// Format: epochMillis_md5(word)[:8]
func GenerateCardID(bulgarianWord string) string {
// Get current timestamp in milliseconds
now := time.Now()
epochMillis := now.UnixNano() / 1000000
// Calculate MD5 hash of the word
hash := md5.Sum([]byte(bulgarianWord))
hashStr := hex.EncodeToString(hash[:])[:8] // Use first 8 chars of MD5
// Combine timestamp and hash
return fmt.Sprintf("%d_%s", epochMillis, hashStr)
}
// SanitizeFilename creates a safe filename from a string
func SanitizeFilename(s string) string {
result := ""
for _, r := range s {
if isAlphaNumeric(r) || r == '-' || r == '_' {
result += string(r)
} else {
result += "_"
}
}
return result
}
// isAlphaNumeric checks if a rune is alphanumeric
func isAlphaNumeric(r rune) bool {
return (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') ||
(r >= '0' && r <= '9') || (r >= 'а' && r <= 'я') ||
(r >= 'А' && r <= 'Я')
}
|