Initial index support

This commit is contained in:
2025-02-12 17:14:41 +01:00
parent ed9c002b67
commit 0cd964343b
7 changed files with 333 additions and 56 deletions

View File

@ -167,7 +167,7 @@ func SubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFun
http.Error(w, "Bitte den Artikel eingeben.", http.StatusBadRequest)
return
}
if err := b.WriteArticleToFile(c, article.UUID, content); err != nil {
if err := article.WriteContentToFile(c, content); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@ -291,7 +291,7 @@ func ResubmitArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerF
return
}
if err = b.WriteArticleToFile(c, article.UUID, []byte(content)); err != nil {
if err = article.WriteContentToFile(c, []byte(content)); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@ -535,7 +535,7 @@ func ReviewRejectedArticle(c *b.Config, db *b.DB, s map[string]*Session) http.Ha
}
}
func PublishArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFunc {
func PublishArticle(c *b.Config, db *b.DB, s map[string]*Session, i *b.Index) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
session, err := ManageSession(w, r, c, s)
if err != nil {
@ -573,6 +573,19 @@ func PublishArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFu
return
}
content, err := article.ReadContent(c)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err = i.Add(article.UUID.String(), content); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if article.EditedID != 0 {
oldArticle, err := db.GetArticle(article.EditedID)
if err != nil {
@ -587,7 +600,14 @@ func PublishArticle(c *b.Config, db *b.DB, s map[string]*Session) http.HandlerFu
return
}
if err = os.Remove(filepath.Join(c.ArticleDir, fmt.Sprint(oldArticle.UUID, ".md"))); err != nil {
uuid := oldArticle.UUID.String()
if err = i.Delete(uuid); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err = os.Remove(filepath.Join(c.ArticleDir, uuid+".md")); err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return