From 07e1983fccd58edfc55b35ad7fb5adbe221373fe Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 27 Oct 2024 15:12:30 +0100 Subject: [PATCH] Add call to serve atom feed --- cmd/backend/config.go | 2 +- cmd/calls/atom.go | 26 ++++++++++++++++++++++++++ cmd/calls/images.go | 2 +- cmd/main.go | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 cmd/calls/atom.go diff --git a/cmd/backend/config.go b/cmd/backend/config.go index 565e190..0eea7d3 100644 --- a/cmd/backend/config.go +++ b/cmd/backend/config.go @@ -39,9 +39,9 @@ func newConfig() *Config { return &Config{ AESKeyFile: "/var/www/cpolis/aes.key", ArticleDir: "/var/www/cpolis/articles", + AtomFeed: "/var/www/cpolis/cpolis.atom", ConfigFile: "/etc/cpolis/config.toml", DBName: "cpolis", - AtomFeed: "/var/www/cpolis/cpolis.atom", FirebaseKey: "/var/www/cpolis/serviceAccountKey.json", GOBKeyFile: "/var/www/cpolis/gob.key", LogFile: "/var/log/cpolis.log", diff --git a/cmd/calls/atom.go b/cmd/calls/atom.go new file mode 100644 index 0000000..7d57463 --- /dev/null +++ b/cmd/calls/atom.go @@ -0,0 +1,26 @@ +package calls + +import ( + "log" + "net/http" + "path/filepath" + + b "streifling.com/jason/cpolis/cmd/backend" +) + +func ServeAtomFeed(c *b.Config) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if !tokenIsVerified(w, r, c) { + return + } + + absFilepath, err := filepath.Abs(c.AtomFeed) + if err != nil { + log.Println(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + http.ServeFile(w, r, absFilepath) + } +} diff --git a/cmd/calls/images.go b/cmd/calls/images.go index dd7a491..4d894bc 100644 --- a/cmd/calls/images.go +++ b/cmd/calls/images.go @@ -8,7 +8,7 @@ import ( b "streifling.com/jason/cpolis/cmd/backend" ) -func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc { +func ServeImage(c *b.Config) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if !tokenIsVerified(w, r, c) { return diff --git a/cmd/main.go b/cmd/main.go index 76874be..9950445 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -66,8 +66,9 @@ func main() { mux.HandleFunc("GET /article/review-unpublished/{id}", f.ReviewArticle(config, db, store, "publish", "Artikel veröffentlichen", "Veröffentlichen")) mux.HandleFunc("GET /article/serve/{id}", c.ServeArticle(config, db)) mux.HandleFunc("GET /article/write", f.WriteArticle(config, db, store)) + mux.HandleFunc("GET /atom/serve", c.ServeAtomFeed(config)) mux.HandleFunc("GET /hub", f.ShowHub(config, db, store)) - mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config, store)) + mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config)) mux.HandleFunc("GET /issue/this", f.ShowCurrentIssue(config, db, store)) mux.HandleFunc("GET /logout", f.Logout(config, store)) mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))