2025-01-24 00:18:41 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2025-01-24 15:15:54 +00:00
|
|
|
"github.com/Jaculabilis/intake/core"
|
2025-01-24 00:18:41 +00:00
|
|
|
"github.com/Jaculabilis/intake/web/html"
|
|
|
|
)
|
|
|
|
|
2025-01-24 15:15:54 +00:00
|
|
|
type SourceData struct {
|
|
|
|
Name string
|
2025-01-24 00:18:41 +00:00
|
|
|
}
|
|
|
|
|
2025-01-24 15:15:54 +00:00
|
|
|
type HomeData struct {
|
|
|
|
Sources []SourceData
|
|
|
|
}
|
|
|
|
|
|
|
|
func (env *Env) rootHandler(writer http.ResponseWriter, req *http.Request) {
|
|
|
|
names, err := core.GetSources(env.db)
|
|
|
|
if err != nil {
|
|
|
|
writer.Write([]byte(err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
var sources []SourceData
|
|
|
|
for _, name := range names {
|
|
|
|
sources = append(sources, SourceData{name})
|
|
|
|
}
|
|
|
|
data := HomeData{sources}
|
|
|
|
html.Home(writer, data)
|
|
|
|
}
|
2025-01-24 00:18:41 +00:00
|
|
|
|
2025-01-24 15:15:54 +00:00
|
|
|
func (env *Env) styleHandler(writer http.ResponseWriter, req *http.Request) {
|
|
|
|
writer.Header()["Cache-Control"] = []string{"public, max-age=86400"}
|
2025-01-25 05:27:26 +00:00
|
|
|
writer.Header()["Content-Type"] = []string{"text/css; charset=utf-8"}
|
2025-01-24 15:15:54 +00:00
|
|
|
writer.Write(html.Stylesheet)
|
2025-01-24 00:18:41 +00:00
|
|
|
}
|