* Update main.css * Update torrent_item.jet.html * Update main.js * Update torrent_item.jet.html * Update main.js * Update main.js * Update main.js * Update main.js * Update main.js * Update template_functions_test.go * Update template_functions_test.go * Update user.go * Update profile.jet.html * Update view.jet.html * Update template_functions.go * Update en-us.all.json * Add files via upload * Update CHANGELOG.md * Update main.css * Update template_functions.go * Add files via upload * Update en-us.all.json * Update template_functions_test.go * Update view.jet.html * Update main.css * Update ja-jp.all.json * Update main.css * Update edit.jet.html * Update main.css * Update tomorrow.css * Update ja-jp.all.json * Update main.css * Update view.jet.html * Update comment.go * Update create.go * Update classic.css * Make GetOldNavFromRequest return true by default * Update view.jet.html * Force torrent date in UTC+0 timezone during display * ditto * Update ja-jp.all.json * Update oldNav.jet.html * Update structs.go * Update default_config.yml * Update torrent.go * Update stats.go * Update stats.go * Update user.go * Update template_functions.go * Update template_functions_test.go * Update torrent.go * Update comment.go * Update view.jet.html * Update main.css * Update user.go * Update template_functions.go * Update profile.jet.html * Update main.js
59 lignes
1,4 Kio
Go
59 lignes
1,4 Kio
Go
package torrentController
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/NyaaPantsu/nyaa/config"
|
|
"github.com/NyaaPantsu/nyaa/controllers/router"
|
|
"github.com/NyaaPantsu/nyaa/models/comments"
|
|
"github.com/NyaaPantsu/nyaa/models/torrents"
|
|
"github.com/NyaaPantsu/nyaa/utils/captcha"
|
|
msg "github.com/NyaaPantsu/nyaa/utils/messages"
|
|
"github.com/NyaaPantsu/nyaa/utils/sanitize"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// PostCommentHandler : Controller for posting a comment
|
|
func PostCommentHandler(c *gin.Context) {
|
|
id, _ := strconv.ParseInt(c.Param("id"), 10, 32)
|
|
|
|
torrent, err := torrents.FindByID(uint(id))
|
|
if err != nil {
|
|
c.Status(http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
currentUser := router.GetUser(c)
|
|
messages := msg.GetMessages(c)
|
|
|
|
if currentUser.NeedsCaptcha() {
|
|
userCaptcha := captcha.Extract(c)
|
|
if !captcha.Authenticate(userCaptcha) {
|
|
messages.AddErrorT("errors", "bad_captcha")
|
|
}
|
|
}
|
|
content := sanitize.Sanitize(c.PostForm("comment"), "comment")
|
|
|
|
userID := currentUser.ID
|
|
if c.PostForm("anonymous") == "true" {
|
|
userID = 0
|
|
}
|
|
|
|
if strings.TrimSpace(content) == "" {
|
|
messages.AddErrorT("errors", "comment_empty")
|
|
}
|
|
if len(content) > config.Get().CommentLength {
|
|
messages.AddErrorT("errors", "comment_toolong")
|
|
}
|
|
if !messages.HasErrors() {
|
|
|
|
_, err := comments.Create(content, torrent, userID)
|
|
if err != nil {
|
|
messages.Error(err)
|
|
}
|
|
}
|
|
url := "/view/" + strconv.FormatUint(uint64(torrent.ID), 10)
|
|
c.Redirect(302, url)
|
|
}
|