From ce43e45a6c1400c712f500095e60fd2563bf3d83 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Thu, 8 Aug 2024 21:26:59 +0200 Subject: [PATCH] Deleted hints of custom preview function --- cmd/frontend/articles.go | 72 +++++++--------------------------------- cmd/main.go | 2 -- 2 files changed, 12 insertions(+), 62 deletions(-) diff --git a/cmd/frontend/articles.go b/cmd/frontend/articles.go index 7f95a04..7b1bfba 100644 --- a/cmd/frontend/articles.go +++ b/cmd/frontend/articles.go @@ -23,15 +23,6 @@ const ( PreviewMode ) -type EditorHTMLData struct { - Title string - Description string - Content string - HTMLContent template.HTML - Tags []*b.Tag - Mode int -} - func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { session, err := s.Get(r, "cookie") @@ -55,6 +46,15 @@ func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + type editorHTMLData struct { + Title string + Description string + Content string + HTMLContent template.HTML + Tags []*b.Tag + Mode int + } + session, err := s.Get(r, "cookie") if err != nil { tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html") @@ -62,11 +62,11 @@ func WriteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc { template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg) } - var data EditorHTMLData + var data editorHTMLData if session.Values["article"] == nil { - data = EditorHTMLData{} + data = editorHTMLData{} } else { - data = session.Values["article"].(EditorHTMLData) + data = session.Values["article"].(editorHTMLData) } data.Mode = EditMode @@ -489,51 +489,3 @@ func UploadImage(c *b.Config) http.HandlerFunc { json.NewEncoder(w).Encode(url) } } - -func PreviewArticle(c *b.Config, s *b.CookieStore) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var err error - data := EditorHTMLData{Mode: PreviewMode} - - data.Title, err = b.ConvertToPlain(r.PostFormValue("article-title")) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - data.Description, err = b.ConvertToPlain(r.PostFormValue("article-description")) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - data.Content = r.PostFormValue("article-content") - content, err := b.ConvertToHTML(data.Content) - if err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - data.HTMLContent = template.HTML(content) - - session, err := s.Get(r, "cookie") - if err != nil { - tmpl, err := template.ParseFiles(c.WebDir + "/templates/login.html") - msg := "Session nicht mehr gültig. Bitte erneut anmelden." - template.Must(tmpl, err).ExecuteTemplate(w, "page-content", msg) - } - - session.Values["article"] = data - if err = session.Save(r, w); err != nil { - log.Println(err) - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html") - tmpl = template.Must(tmpl, err) - tmpl.ExecuteTemplate(w, "page-content", data) - } -} diff --git a/cmd/main.go b/cmd/main.go index 220e945..a382324 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -12,7 +12,6 @@ import ( func init() { gob.Register(b.User{}) - gob.Register(f.EditorHTMLData{}) } func main() { @@ -74,7 +73,6 @@ func main() { mux.HandleFunc("POST /add-tag", f.AddTag(config, db, store)) mux.HandleFunc("POST /add-user", f.AddUser(config, db, store)) mux.HandleFunc("POST /login", f.Login(config, db, store)) - mux.HandleFunc("POST /preview-article", f.PreviewArticle(config, store)) mux.HandleFunc("POST /resubmit-article/{id}", f.ResubmitArticle(config, db, store)) mux.HandleFunc("POST /submit-article", f.SubmitArticle(config, db, store)) mux.HandleFunc("POST /update-self", f.UpdateSelf(config, db, store))