organizer/envvars.go
2023-01-15 21:09:26 +01:00

50 lines
1.3 KiB
Go

package main
import (
"os/user"
"runtime"
"strconv"
"text/template"
"git.milar.in/nyaanime/logic"
"git.milar.in/milarin/envvars/v2"
)
var (
DownloadPath = envvars.String("DOWNLOAD_PATH", "")
ThreadCount = envvars.Int("THREADS", runtime.NumCPU())
DeleteLowPriorityFiles = envvars.Bool("DELETE_LOW_PRIORITY_FILES", false)
TelegramBotToken = envvars.String("TELEGRAM_API_TOKEN", "")
TelegramChatID = envvars.Int64("TELEGRAM_CHAT_ID", 0)
TelegramOrganizeMessagePatternStr = logic.EscSeqReplacer.Replace(envvars.String("TELEGRAM_ORGANIZE_MESSAGE_PATTERN", `Download finished\n\n{{.Title.UserPreferred}} episode {{.Episode}}`))
TelegramOrganizeMessagePattern = template.Must(template.New("telegram-organize-message-pattern").Parse(TelegramOrganizeMessagePatternStr))
Uid = envvars.Object("UID", 1000, func(s string) (int, error) {
if uid, err := strconv.Atoi(s); err == nil {
return uid, nil
}
usr, err := user.Lookup(s)
if err != nil {
return 0, err
}
return strconv.Atoi(usr.Uid)
})
Gid = envvars.Object("GID", 1000, func(s string) (int, error) {
if gid, err := strconv.Atoi(s); err == nil {
return gid, nil
}
grp, err := user.LookupGroup(s)
if err != nil {
return 0, err
}
return strconv.Atoi(grp.Gid)
})
)