mirror of
https://github.com/JustKato/FreePad.git
synced 2026-02-23 15:50:46 +02:00
+ Handle post data
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/JustKato/FreePad/lib/helper"
|
||||
"github.com/JustKato/FreePad/lib/objects"
|
||||
@@ -23,7 +23,27 @@ func HomeRoutes(router *gin.Engine) {
|
||||
// Get the post we are looking for.
|
||||
postName := c.Param("post")
|
||||
|
||||
fmt.Println("Sanitizing ", postName)
|
||||
// Sanitize the postName
|
||||
newPostName, err := url.QueryUnescape(postName)
|
||||
if err == nil {
|
||||
postName = newPostName
|
||||
}
|
||||
postName = sanitize.AlphaNumeric(postName, true)
|
||||
|
||||
post := objects.GetPost(postName)
|
||||
|
||||
c.HTML(200, "page.html", gin.H{
|
||||
"title": postName,
|
||||
"post_content": post.Content,
|
||||
"last_modified": post.LastModified,
|
||||
"domain_base": helper.GetDomainBase(),
|
||||
})
|
||||
})
|
||||
|
||||
router.POST("/:post", func(c *gin.Context) {
|
||||
// Get the post we are looking for.
|
||||
postName := c.Param("post")
|
||||
postContent := c.PostForm("content")
|
||||
|
||||
// Sanitize the postName
|
||||
newPostName, err := url.QueryUnescape(postName)
|
||||
@@ -32,14 +52,26 @@ func HomeRoutes(router *gin.Engine) {
|
||||
}
|
||||
postName = sanitize.AlphaNumeric(postName, true)
|
||||
|
||||
fmt.Println("Fetching ", postName)
|
||||
p := objects.Post{
|
||||
Name: postName,
|
||||
Content: postContent,
|
||||
LastModified: time.Now().Format("02/01/2006 03:04:05 PM"),
|
||||
}
|
||||
|
||||
post := objects.GetPost(postName)
|
||||
// Write the post
|
||||
err = objects.WritePost(p)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"error": err,
|
||||
})
|
||||
|
||||
c.HTML(200, "page.html", gin.H{
|
||||
"title": postName,
|
||||
"post_content": post.Content,
|
||||
"domain_base": helper.GetDomainBase(),
|
||||
// End
|
||||
return
|
||||
}
|
||||
|
||||
// Return the success message
|
||||
c.JSON(200, gin.H{
|
||||
"pad": p,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user