1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
This commit is contained in:
Zack Scholl 2017-03-22 08:21:49 -06:00
parent dfa18bca5a
commit 29460a6c26
2 changed files with 18 additions and 1 deletions

View File

@ -61,6 +61,18 @@ func handlePageRequest(c *gin.Context) {
for i, v := range versionsInt64 {
versionsText[i] = time.Unix(v/1000000000, 0).String()
}
if command == "raw" {
c.Writer.Header().Set("Content-Type", contentType(p.Name))
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Max")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Data(200, contentType(p.Name), []byte(rawText))
return
}
c.HTML(http.StatusOK, "index.html", gin.H{
"EditPage": command == "edit",
"ViewPage": command == "view",
@ -83,7 +95,11 @@ func handlePageUpdate(c *gin.Context) {
}
var json QueryJSON
if c.BindJSON(&json) != nil {
c.String(http.StatusBadRequest, "Problem binding keys")
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Wrong JSON"})
return
}
if len(json.NewText) > 100000 {
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Too much"})
return
}
log.Trace("Update: %v", json)

View File

@ -262,6 +262,7 @@
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
<a href="#" id="menuLink1" class="pure-menu-link">Other</a>
<ul class="pure-menu-children">
<li class="pure-menu-item"><a href="/{{ .Page }}/raw" class="pure-menu-link">Raw</a></li>
<li class="pure-menu-item"><a href="/{{ .Page }}/history" class="pure-menu-link">History</a></li>
<hr>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="selfDestructPage">Self-destruct</a></li>