Files
podstalk/main.go
T
jbrechtel 0861f7510b
Build and Deploy / build-and-deploy (push) Failing after 13s
Per-user podcasts, file uploads, RSS images, Docker support
- Each user owns a podcast: podcast title/author/image on users table
- Episodes scoped by user_id with context-based auth
- Audio file upload replaces URL linking, served from /uploads/
- Podcast and per-episode images with itunes:image in RSS
- RSS per-user via ?user=N, dashboard shows user-specific feed URL
- Settings form for title + author + image per user
- Docker multi-stage build (golang:1.25-alpine / alpine:3.21)
- Removed PODSTALK_TITLE/AUTHOR env vars
2026-07-08 09:20:19 -04:00

96 lines
2.2 KiB
Go

package main
import (
"embed"
"fmt"
"html/template"
"log"
"net/http"
"os"
"podstalk/handler"
"podstalk/store"
)
//go:embed template/*.html
var templateFS embed.FS
func main() {
dbPath := os.Getenv("PODSTALK_DB")
if dbPath == "" {
dbPath = "podstalk.db"
}
uploadDir := os.Getenv("PODSTALK_UPLOAD_DIR")
if uploadDir == "" {
uploadDir = "uploads"
}
baseURL := os.Getenv("PODSTALK_LINK")
if baseURL == "" {
baseURL = "http://localhost:8080"
}
st, err := store.New(dbPath)
if err != nil {
log.Fatalf("failed to open database: %v", err)
}
defer st.Close()
tmpl, err := template.New("").ParseFS(templateFS, "template/*.html")
if err != nil {
log.Fatalf("failed to parse templates: %v", err)
}
tpl := handler.NewTemplates(tmpl)
sessions := handler.NewSessionStore()
authMid := &handler.AuthMiddleware{Store: st, Sessions: sessions}
authH := &handler.AuthHandler{Store: st, Sessions: sessions, Tpl: tpl}
epH := &handler.EpisodeHandler{
Store: st,
Tpl: tpl,
UploadDir: uploadDir,
BaseURL: baseURL,
}
setH := &handler.SettingsHandler{
Store: st,
UploadDir: uploadDir,
}
rssH := &handler.RSSHandler{
Store: st,
Link: baseURL,
}
// Auth routes.
http.HandleFunc("/signup", authMid.RedirectIfAuthed(authH.ServeSignup))
http.HandleFunc("/signin", authMid.RedirectIfAuthed(authH.ServeSignin))
http.HandleFunc("/signout", authH.ServeSignout)
// Protected routes.
http.HandleFunc("/", authMid.RequireAuth(epH.ServeDashboard))
http.HandleFunc("/episodes/new", authMid.RequireAuth(epH.ServeNew))
http.HandleFunc("/episodes/edit", authMid.RequireAuth(epH.ServeEdit))
http.HandleFunc("/episodes/delete", authMid.RequireAuth(epH.ServeDelete))
http.HandleFunc("/settings", authMid.RequireAuth(setH.ServeSettings))
// Public RSS feed — per-user via ?user=N query param.
http.HandleFunc("/rss", rssH.ServeRSS)
// Public uploaded files.
http.HandleFunc("/uploads/", epH.ServeUpload)
port := envOrDefault("PORT", "8080")
addr := fmt.Sprintf(":%s", port)
log.Printf("Podstalk listening on http://0.0.0.0%s", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}
func envOrDefault(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}