photoprism/pkg/rnd/uid.go
Michael Mayer 713593da4e Auth: Add CLI command to create access tokens for apps #782 #808 #3943
You can now run "photoprism auth add" to create new client access tokens
that allow external applications to use the built-in REST API.

Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-01-05 16:31:07 +01:00

27 lines
570 B
Go

package rnd
import (
"strconv"
"time"
)
const (
PrefixNone = byte(0)
PrefixMixed = byte('*')
)
// GenerateUID returns a unique id with prefix as string.
func GenerateUID(prefix byte) string {
return generateUID(prefix, time.Now())
}
// generateUID returns a unique id with prefix as string at a given time.
func generateUID(prefix byte, t time.Time) string {
result := make([]byte, 0, 16)
result = append(result, prefix)
result = append(result, strconv.FormatInt(t.UTC().Unix(), 36)[0:6]...)
result = append(result, Base36(9)...)
return string(result)
}