Implement banner images in a more standard way

This commit is contained in:
2024-10-29 16:36:40 +01:00
parent be829e662b
commit 20a12c6299
6 changed files with 40 additions and 63 deletions

View File

@@ -80,7 +80,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
article := &b.Article{
Title: r.PostFormValue("article-title"),
BannerLink: r.PostFormValue("article-banner-url"),
BannerLink: c.Domain + "/image/serve/" + r.PostFormValue("article-banner-url"),
Summary: r.PostFormValue("article-summary"),
Published: false,
Rejected: false,
@@ -181,6 +181,12 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
return
}
bannerLink := c.Domain + "/image/serve/" + r.PostFormValue("article-banner-url")
if len(bannerLink) == 0 {
http.Error(w, "Bitte ein Titelbild einfügen.", http.StatusBadRequest)
return
}
summary := r.PostFormValue("article-summary")
if len(summary) == 0 {
http.Error(w, "Bitte die Beschreibung eingeben.", http.StatusBadRequest)
@@ -202,6 +208,7 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
if err = db.UpdateAttributes(
&b.Attribute{Table: "articles", ID: id, AttName: "title", Value: title},
&b.Attribute{Table: "articles", ID: id, AttName: "banner_link", Value: bannerLink},
&b.Attribute{Table: "articles", ID: id, AttName: "summary", Value: summary},
&b.Attribute{Table: "articles", ID: id, AttName: "rejected", Value: false},
&b.Attribute{Table: "articles", ID: id, AttName: "is_in_issue", Value: r.PostFormValue("issue") == "on"},
@@ -347,13 +354,7 @@ func ReviewRejectedArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.Handler
}
imgURL := strings.Split(data.Article.BannerLink, "/")
imgFileName := imgURL[len(imgURL)-1]
data.BannerImage, err = b.ServeBase64Image(c, imgFileName)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data.BannerImage = imgURL[len(imgURL)-1]
articleAbsName := fmt.Sprint(c.ArticleDir, "/", data.Article.ID, ".md")
content, err := os.ReadFile(articleAbsName)
@@ -624,13 +625,7 @@ func ReviewArticle(c *b.Config, db *b.DB, s *b.CookieStore, action, title, butto
}
imgURL := strings.Split(article.BannerLink, "/")
imgFileName := imgURL[len(imgURL)-1]
data.BannerImage, err = b.ServeBase64Image(c, imgFileName)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data.BannerImage = imgURL[len(imgURL)-1]
data.Article.Summary, err = b.ConvertToPlain(article.Summary)
if err != nil {
@@ -807,13 +802,7 @@ func EditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
}
imgURL := strings.Split(data.Article.BannerLink, "/")
imgFileName := imgURL[len(imgURL)-1]
data.BannerImage, err = b.ServeBase64Image(c, imgFileName)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
data.BannerImage = imgURL[len(imgURL)-1]
content, err := os.ReadFile(fmt.Sprint(c.ArticleDir, "/", data.Article.ID, ".md"))
if err != nil {