-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
93 lines (81 loc) · 2.01 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
package main
import (
"context"
"embed"
"fmt"
"os"
"strings"
"time"
"github.com/cufee/feedlr-yt/internal/api/youtube"
"github.com/cufee/feedlr-yt/internal/api/youtube/auth"
"github.com/cufee/feedlr-yt/internal/database"
"github.com/cufee/feedlr-yt/internal/logic/background"
"github.com/cufee/feedlr-yt/internal/server"
"github.com/cufee/feedlr-yt/internal/sessions"
"github.com/go-webauthn/webauthn/webauthn"
"github.com/rs/zerolog/log"
"github.com/microcosm-cc/bluemonday"
)
//go:generate templ generate
// Embed assets
//
//go:embed assets/*
var assetsFs embed.FS
func main() {
db, err := database.NewSQLiteClient(os.Getenv("DATABASE_PATH"))
if err != nil {
panic(err)
}
authClient := auth.NewClient(db)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
done, err := authClient.Authenticate(ctx, os.Getenv("YOUTUBE_API_SKIP_AUTH_CACHE") == "true")
if err != nil {
cancel()
panic(err)
}
go func() {
defer cancel()
<-done
log.Info().Msg("Youtube API Authenticated")
}()
yt, err := youtube.NewClient(os.Getenv("YOUTUBE_API_KEY"), authClient)
if err != nil {
panic(err)
}
youtube.DefaultClient = yt
_, err = background.StartCronTasks(db)
if err != nil {
panic(err)
}
ses, err := sessions.New(db)
if err != nil {
panic(err)
}
host := os.Getenv("COOKIE_DOMAIN")
origin := fmt.Sprintf("https://%s", host)
if strings.Contains(origin, "localhost:") {
origin = fmt.Sprintf("http://%s", host)
}
wa, err := webauthn.New(&webauthn.Config{
RPDisplayName: "Feedlr",
RPID: strings.Split(host, ":")[0],
RPOrigins: []string{origin},
Timeouts: webauthn.TimeoutsConfig{
Login: webauthn.TimeoutConfig{
Enforce: true,
Timeout: time.Minute * 1,
TimeoutUVD: time.Minute * 1,
},
Registration: webauthn.TimeoutConfig{
Enforce: true,
Timeout: time.Minute * 5,
TimeoutUVD: time.Minute * 5,
},
},
})
if err != nil {
panic(err)
}
start := server.New(db, ses, assetsFs, bluemonday.StrictPolicy(), wa)
start()
}