Files
pika/internal/assets/paths.go
T

56 lines
1.0 KiB
Go

package assets
import (
"encoding/base64"
"os"
"path/filepath"
)
const (
defaultWebDir = "web/dist"
defaultThemeDir = "themes/default"
defaultAgentDir = "bin/agents"
)
func WebDir() string {
if dir := os.Getenv("PIKA_WEB_DIR"); dir != "" {
return dir
}
return defaultWebDir
}
func DefaultThemeDir() string {
if dir := os.Getenv("PIKA_DEFAULT_THEME_DIR"); dir != "" {
return dir
}
return defaultThemeDir
}
func AgentDir() string {
if dir := os.Getenv("PIKA_AGENT_DIR"); dir != "" {
return dir
}
return defaultAgentDir
}
func AgentPath(filename string) string {
return filepath.Join(AgentDir(), filename)
}
func DefaultLogoBase64() string {
for _, path := range []string{
os.Getenv("PIKA_DEFAULT_LOGO_PATH"),
filepath.Join(DefaultThemeDir(), "dist", "logo.png"),
filepath.Join(WebDir(), "logo.png"),
} {
if path == "" {
continue
}
logo, err := os.ReadFile(path)
if err == nil && len(logo) > 0 {
return "data:image/png;base64," + base64.StdEncoding.EncodeToString(logo)
}
}
return ""
}