diff --git a/cmd/backend/atom.go b/cmd/backend/atom.go index 8ce4fe0..6133818 100644 --- a/cmd/backend/atom.go +++ b/cmd/backend/atom.go @@ -31,12 +31,11 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) { entry := atom.NewEntry(articleTitle) entry.ID = atom.NewID(fmt.Sprint("urn:entry:", article.ID)) entry.Published = atom.NewDate(article.Created) + entry.Content = atom.NewContent(atom.OutOfLine, "text/hmtl", article.ContentLink) if article.AutoGenerated { - entry.Content = atom.NewContent(atom.InlineText, "text", "") + entry.Summary = atom.NewText("text", "automatically generated") } else { - entry.Content = atom.NewContent(atom.OutOfLine, "text/hmtl", article.ContentLink) - articleSummary, err := ConvertToPlain(article.Summary) if err != nil { return nil, fmt.Errorf("error converting description to plain text for Atom feed: %v", err) diff --git a/cmd/backend/config.go b/cmd/backend/config.go index 6b8b5d3..8d52a8b 100644 --- a/cmd/backend/config.go +++ b/cmd/backend/config.go @@ -52,7 +52,7 @@ func newConfig() *Config { PDFDir: "/var/www/cpolis/pdfs", PicsDir: "/var/www/cpolis/pics", Port: ":8080", - Version: "v0.13.3", + Version: "v0.13.4", WebDir: "/var/www/cpolis/web", } } diff --git a/cmd/calls/images.go b/cmd/calls/images.go index 4d894bc..9fb4d42 100644 --- a/cmd/calls/images.go +++ b/cmd/calls/images.go @@ -6,12 +6,15 @@ import ( "path/filepath" b "streifling.com/jason/cpolis/cmd/backend" + f "streifling.com/jason/cpolis/cmd/frontend" ) -func ServeImage(c *b.Config) http.HandlerFunc { +func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if !tokenIsVerified(w, r, c) { - return + if _, err := f.GetSession(w, r, c, s); err != nil { + if !tokenIsVerified(w, r, c) { + return + } } absFilepath, err := filepath.Abs(c.PicsDir) diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go index 8819166..305c26b 100644 --- a/cmd/frontend/articles.go +++ b/cmd/frontend/articles.go @@ -32,7 +32,7 @@ type EditorHTMLData struct { func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -64,7 +64,7 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -157,7 +157,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -245,7 +245,7 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func ShowUnpublishedUnrejectedAndPublishedRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -289,7 +289,7 @@ func ShowUnpublishedUnrejectedAndPublishedRejectedArticles(c *b.Config, db *b.DB func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -327,7 +327,7 @@ func ShowRejectedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerF func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -392,7 +392,7 @@ func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Handler func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -486,7 +486,7 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -521,7 +521,7 @@ func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func ShowCurrentIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -545,7 +545,7 @@ func ShowCurrentIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -582,7 +582,7 @@ func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore, action strin func ReviewArticle(c *b.Config, db *b.DB, s *b.CookieStore, action, title, button string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -662,7 +662,7 @@ func ReviewArticle(c *b.Config, db *b.DB, s *b.CookieStore, action, title, butto func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -715,7 +715,7 @@ func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func AllowEditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -774,7 +774,7 @@ func AllowEditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc func EditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/cmd/frontend/images.go b/cmd/frontend/images.go index a6424b8..d6aecbe 100644 --- a/cmd/frontend/images.go +++ b/cmd/frontend/images.go @@ -5,14 +5,13 @@ import ( "html/template" "log" "net/http" - "path/filepath" b "streifling.com/jason/cpolis/cmd/backend" ) func UploadImage(c *b.Config, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -45,7 +44,7 @@ func UploadImage(c *b.Config, s *b.CookieStore) http.HandlerFunc { func UploadBanner(c *b.Config, s *b.CookieStore, fileKey, htmlFile, htmlTemplate string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -81,22 +80,3 @@ func UploadBanner(c *b.Config, s *b.CookieStore, fileKey, htmlFile, htmlTemplate } } } - -func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - absFilepath, err := filepath.Abs(c.PicsDir) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - http.ServeFile(w, r, absFilepath+"/"+r.PathValue("img")) - } -} diff --git a/cmd/frontend/issues.go b/cmd/frontend/issues.go index d290681..a3f3ea4 100644 --- a/cmd/frontend/issues.go +++ b/cmd/frontend/issues.go @@ -13,7 +13,7 @@ import ( func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/cmd/frontend/pdf.go b/cmd/frontend/pdf.go index eda5820..ada1eec 100644 --- a/cmd/frontend/pdf.go +++ b/cmd/frontend/pdf.go @@ -12,7 +12,7 @@ import ( func UploadPDF(c *b.Config, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/cmd/frontend/sessions.go b/cmd/frontend/sessions.go index cb2e99f..ffef532 100644 --- a/cmd/frontend/sessions.go +++ b/cmd/frontend/sessions.go @@ -26,8 +26,8 @@ func saveSession(w http.ResponseWriter, r *http.Request, s *b.CookieStore, u *b. return nil } -// getSession is used for verifying that the user is logged in and returns their session and an error. -func getSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*b.Session, error) { +// GetSession is used for verifying that the user is logged in and returns their session and an error. +func GetSession(w http.ResponseWriter, r *http.Request, c *b.Config, s *b.CookieStore) (*b.Session, error) { msg := "Keine gültige Session. Bitte erneut anmelden." tmpl, tmplErr := template.ParseFiles(c.WebDir+"/templates/index.html", c.WebDir+"/templates/login.html") @@ -142,7 +142,7 @@ func Login(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -167,7 +167,7 @@ func Logout(c *b.Config, s *b.CookieStore) http.HandlerFunc { func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/cmd/frontend/tags.go b/cmd/frontend/tags.go index 9b92729..290c815 100644 --- a/cmd/frontend/tags.go +++ b/cmd/frontend/tags.go @@ -10,7 +10,7 @@ import ( func CreateTag(c *b.Config, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -27,7 +27,7 @@ func CreateTag(c *b.Config, s *b.CookieStore) http.HandlerFunc { func AddTag(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/cmd/frontend/users.go b/cmd/frontend/users.go index fbd705a..e3aed55 100644 --- a/cmd/frontend/users.go +++ b/cmd/frontend/users.go @@ -27,7 +27,7 @@ func checkUserStrings(user *b.User) (string, int, bool) { func CreateUser(c *b.Config, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -44,7 +44,7 @@ func CreateUser(c *b.Config, s *b.CookieStore) http.HandlerFunc { func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -122,7 +122,7 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func EditSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -147,7 +147,7 @@ func EditSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -293,7 +293,7 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -325,7 +325,7 @@ func ShowAllUsers(c *b.Config, db *b.DB, s *b.CookieStore, action string) http.H func EditUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - if _, err := getSession(w, r, c, s); err != nil { + if _, err := GetSession(w, r, c, s); err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -356,7 +356,7 @@ func EditUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -440,7 +440,7 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func DeleteUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - session, err := getSession(w, r, c, s) + session, err := GetSession(w, r, c, s) if err != nil { log.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/cmd/main.go b/cmd/main.go index 4f9f697..e2f05db 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -68,8 +68,7 @@ func main() { 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/{img}", f.ServeImage(config, store)) - mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config)) + mux.HandleFunc("GET /image/serve/{pic}", c.ServeImage(config, store)) 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)) diff --git a/web/templates/editor.html b/web/templates/editor.html index 7860dba..5ccd247 100644 --- a/web/templates/editor.html +++ b/web/templates/editor.html @@ -90,7 +90,7 @@ {{define "article-banner-template"}}
- +
{{end}} diff --git a/web/templates/review-article.html b/web/templates/review-article.html index c04b65b..1266fd1 100644 --- a/web/templates/review-article.html +++ b/web/templates/review-article.html @@ -3,7 +3,7 @@
- Banner Image + Banner Image
Titel