forked from damongolding/immich-kiosk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
98 lines (76 loc) · 2.16 KB
/
main.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"embed"
"fmt"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/damongolding/immich-kiosk/config"
"github.com/damongolding/immich-kiosk/routes"
)
// version current build version number
var version string
//go:embed public
var public embed.FS
func init() {
routes.KioskVersion = version
debugModeEnv := os.Getenv("KIOSK_DEBUG")
debugMode, _ := strconv.ParseBool(debugModeEnv)
if debugMode {
log.SetLevel(log.DebugLevel)
log.Debug("DEBUG mode on")
zone, _ := time.Now().Zone()
log.Debug("🕐", "current_time", time.Now().Format(time.Kitchen), "current_zone", zone)
}
}
func main() {
baseConfig := config.New()
err := baseConfig.Load()
if err != nil {
log.Error("Failed to load config", "err", err)
}
fmt.Println(smallBanner)
versionStyle := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#5af78e")).Render(version)
fmt.Print("Version ", versionStyle, "\n\n")
e := echo.New()
e.HideBanner = true
// Middleware
e.Use(middleware.Recover())
e.Use(middleware.RequestID())
if baseConfig.Kiosk.Password != "" {
e.Use(middleware.KeyAuthWithConfig(middleware.KeyAuthConfig{
Skipper: func(c echo.Context) bool {
// skip auth for assets
if strings.HasPrefix(c.Request().URL.String(), "/assets") {
return true
}
return false
},
KeyLookup: "query:password",
Validator: func(queryPassword string, c echo.Context) (bool, error) {
return queryPassword == baseConfig.Kiosk.Password, nil
},
ErrorHandler: func(err error, c echo.Context) error {
return c.String(http.StatusUnauthorized, "Unauthorized")
},
}))
}
// CSS cache busting
e.FileFS("/assets/css/style.*.css", "public/assets/css/style.css", public)
// serve embdedd staic assets
e.StaticFS("/assets", echo.MustSubFS(public, "public/assets"))
e.GET("/", routes.Home(baseConfig))
e.GET("/image", routes.NewImage(baseConfig))
e.POST("/image", routes.NewImage(baseConfig))
e.GET("/clock", routes.Clock(baseConfig))
err = e.Start(":3000")
if err != nil {
log.Fatal(err)
}
}