Antonio Mika
·
2026-10-10
1package feeds
2
3import (
4 "html/template"
5 "log/slog"
6 "path/filepath"
7 "strings"
8
9 "github.com/picosh/pico/pkg/shared"
10 "github.com/picosh/pico/pkg/shared/router"
11)
12
13// staticDir holds feeds' templates and public files.
14const staticDir = "pkg/apps/feeds"
15
16type Config struct {
17 Debug bool
18 SendgridKey string
19 Domain string
20 Port string
21 Protocol string
22 DbURL string
23 Space string
24 AllowedExt []string
25 Logger *slog.Logger
26}
27
28func NewConfig(service string) *Config {
29 debug := shared.GetEnv("FEEDS_DEBUG", "0")
30 domain := shared.GetEnv("FEEDS_DOMAIN", "feeds.pico.sh")
31 port := shared.GetEnv("FEEDS_WEB_PORT", "3000")
32 protocol := shared.GetEnv("FEEDS_PROTOCOL", "https")
33 dbURL := shared.GetEnv("DATABASE_URL", "")
34 sendgridKey := shared.GetEnv("SENDGRID_API_KEY", "")
35 withPipe := strings.ToLower(shared.GetEnv("PICO_PIPE_ENABLED", "true")) == "true"
36
37 return &Config{
38 Debug: debug == "1",
39 SendgridKey: sendgridKey,
40 Domain: domain,
41 Port: port,
42 Protocol: protocol,
43 DbURL: dbURL,
44 Space: "feeds",
45 AllowedExt: []string{".txt", ".lxt"},
46 Logger: shared.CreateLogger(service, withPipe),
47 }
48}
49
50func (c *Config) StaticPath(fname string) string {
51 return filepath.Join(staticDir, fname)
52}
53
54func (c *Config) Static() router.Static {
55 return router.Static{
56 Dir: staticDir,
57 Logger: c.Logger,
58 Site: shared.SitePageData{
59 Domain: template.URL(c.Domain),
60 HomeURL: template.URL("//" + c.Domain),
61 },
62 }
63}