2017-06-30 21:10:25 +05:30
|
|
|
package utils
|
2016-07-05 03:58:09 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
"encoding/hex"
|
2017-06-30 21:10:25 +05:30
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
2016-07-05 03:58:09 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func ParseUsername(username string) string {
|
|
|
|
const suffix = ".png"
|
|
|
|
if strings.HasSuffix(username, suffix) {
|
|
|
|
username = strings.TrimSuffix(username, suffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
return username
|
|
|
|
}
|
|
|
|
|
|
|
|
func BuildNonElyTexturesHash(username string) string {
|
2016-07-06 17:15:14 +05:30
|
|
|
hour := getCurrentHour()
|
2016-07-05 03:58:09 +05:30
|
|
|
hasher := md5.New()
|
|
|
|
hasher.Write([]byte("non-ely-" + strconv.FormatInt(hour, 10) + "-" + username))
|
|
|
|
|
|
|
|
return hex.EncodeToString(hasher.Sum(nil))
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:43:09 +05:30
|
|
|
func BuildElyUrl(route string) string {
|
2017-04-13 16:50:04 +05:30
|
|
|
prefix := "http://ely.by"
|
|
|
|
if !strings.HasPrefix(route, prefix) {
|
|
|
|
route = prefix + route
|
|
|
|
}
|
|
|
|
|
|
|
|
return route
|
2016-07-29 03:43:09 +05:30
|
|
|
}
|
|
|
|
|
2017-06-30 21:10:25 +05:30
|
|
|
var timeNow = time.Now
|
|
|
|
|
2016-07-06 17:15:14 +05:30
|
|
|
func getCurrentHour() int64 {
|
2017-06-30 21:10:25 +05:30
|
|
|
n := timeNow()
|
2016-07-06 17:15:14 +05:30
|
|
|
return time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix()
|
|
|
|
}
|
2016-07-29 03:43:09 +05:30
|
|
|
|