forked from damongolding/immich-kiosk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
102 lines (79 loc) · 2.33 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
99
100
101
102
package main
import (
"embed"
"fmt"
"net/http"
"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 frontend/public
var public embed.FS
func init() {
routes.KioskVersion = version
}
func main() {
baseConfig := config.New()
err := baseConfig.Load()
if err != nil {
log.Error("Failed to load config", "err", err)
}
if baseConfig.Kiosk.Debug {
log.SetTimeFormat("15:04:05")
log.SetLevel(log.DebugLevel)
if baseConfig.Kiosk.DebugVerbose {
log.Debug("DEBUG VERBOSE mode on")
} else {
log.Debug("DEBUG mode on")
}
zone, _ := time.Now().Zone()
log.Debug("🕐", "current_time", time.Now().Format(time.Kitchen), "current_zone", zone)
}
fmt.Println(kioskBanner)
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,form: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/kiosk.*.css", "frontend/public/assets/css/kiosk.css", public)
// JS cache busting
e.FileFS("/assets/js/kiosk.*.js", "frontend/public/assets/js/kiosk.js", public)
// serve embdedd staic assets
e.StaticFS("/assets", echo.MustSubFS(public, "frontend/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)
}
}