Fix comment routing

pull/47/head
Jan-Lukas Else 2 months ago
parent bef19c61fb
commit 4407f0aae1

@ -3,6 +3,7 @@ package main
import (
"database/sql"
"errors"
"fmt"
"net/http"
"net/url"
"path"
@ -101,7 +102,7 @@ func (a *goBlog) createComment(bc *configBlog, target, comment, name, website, o
if commentID, err := result.LastInsertId(); err != nil {
return "", http.StatusInternalServerError, errors.New("failed to save comment to database")
} else {
commentAddress := bc.getRelativePath(path.Join(commentPath, strconv.Itoa(int(commentID))))
commentAddress := bc.getRelativePath(fmt.Sprintf("%s/%d", commentPath, commentID))
// Send webmention
_ = a.createWebmention(a.getFullAddress(commentAddress), a.getFullAddress(target))
// Return comment path
@ -111,7 +112,7 @@ func (a *goBlog) createComment(bc *configBlog, target, comment, name, website, o
if err := a.db.updateComment(updateId, comment, name, website); err != nil {
return "", http.StatusInternalServerError, errors.New("failed to update comment in database")
}
commentAddress := bc.getRelativePath(path.Join(commentPath, strconv.Itoa(updateId)))
commentAddress := bc.getRelativePath(fmt.Sprintf("%s/%d", commentPath, updateId))
// Send webmention
_ = a.createWebmention(a.getFullAddress(commentAddress), a.getFullAddress(target))
// Return comment path

@ -81,6 +81,8 @@ func (a *goBlog) commentsAdmin(w http.ResponseWriter, r *http.Request) {
})
}
const commentDeleteSubPath = "/delete"
func (a *goBlog) commentsAdminDelete(w http.ResponseWriter, r *http.Request) {
id, err := strconv.Atoi(r.FormValue("commentid"))
if err != nil {

@ -383,9 +383,9 @@ func (a *goBlog) blogCommentsRouter(conf *configBlog) func(r chi.Router) {
r.Use(a.authMiddleware)
r.Get("/", a.commentsAdmin)
r.Get(paginationPath, a.commentsAdmin)
r.Post("/delete", a.commentsAdminDelete)
r.Post(commentDeleteSubPath, a.commentsAdminDelete)
r.Get(commentEditSubPath, a.serveCommentsEditor)
r.Post("/edit", a.serveCommentsEditor)
r.Post(commentEditSubPath, a.serveCommentsEditor)
})
})
}

@ -147,7 +147,7 @@ func (a *goBlog) renderBase(hb *htmlbuilder.HtmlBuilder, rd *renderData, title,
}
if a.commentsEnabledForBlog(rd.Blog) {
hb.WriteUnescaped(" • ")
hb.WriteElementOpen("a", "href", "/comment")
hb.WriteElementOpen("a", "href", rd.Blog.getRelativePath(commentPath))
hb.WriteEscaped(a.ts.GetTemplateStringVariant(rd.Blog.Lang, "comments"))
hb.WriteElementClose("a")
}
@ -1271,7 +1271,7 @@ func (a *goBlog) renderCommentsAdmin(hb *htmlbuilder.HtmlBuilder, rd *renderData
hb.WriteUnescaped(c.Comment)
hb.WriteElementClose("p")
// Delete form
hb.WriteElementOpen("form", "class", "actions", "method", "post", "action", rd.Blog.getRelativePath("/comment/delete"))
hb.WriteElementOpen("form", "class", "actions", "method", "post", "action", rd.Blog.getRelativePath(commentPath+commentDeleteSubPath))
hb.WriteElementOpen("input", "type", "hidden", "name", "commentid", "value", c.ID)
hb.WriteElementOpen("input", "type", "submit", "value", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "delete"))
hb.WriteElementClose("form")

@ -359,7 +359,7 @@ func (a *goBlog) renderInteractions(hb *htmlbuilder.HtmlBuilder, rd *renderData)
hb.WriteElementOpen("input", "type", "submit", "value", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "send"))
hb.WriteElementClose("form")
// Show form to create a new comment
hb.WriteElementOpen("form", "class", "fw p", "method", "post", "action", "/comment")
hb.WriteElementOpen("form", "class", "fw p", "method", "post", "action", rd.Blog.getRelativePath(commentPath))
hb.WriteElementOpen("input", "type", "hidden", "name", "target", "value", rd.Canonical)
hb.WriteElementOpen("input", "type", "text", "name", "name", "placeholder", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "nameopt"))
hb.WriteElementOpen("input", "type", "url", "name", "website", "placeholder", a.ts.GetTemplateStringVariant(rd.Blog.Lang, "websiteopt"))

Loading…
Cancel
Save