mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Use meta instead of storing in history
This commit is contained in:
parent
aa1b7a1afb
commit
4821e7ae62
14
handlers.go
14
handlers.go
@ -79,7 +79,10 @@ func handlePageRelinquish(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
message := "Relinquished"
|
message := "Relinquished"
|
||||||
p := Open(json.Page)
|
p := Open(json.Page)
|
||||||
name, _ := p.Text.GetPreviousByIndex(0)
|
name := p.Meta
|
||||||
|
if name == "" {
|
||||||
|
name = json.Page
|
||||||
|
}
|
||||||
text := p.Text.GetCurrent()
|
text := p.Text.GetCurrent()
|
||||||
isLocked := p.IsEncrypted
|
isLocked := p.IsEncrypted
|
||||||
isEncrypted := p.IsEncrypted
|
isEncrypted := p.IsEncrypted
|
||||||
@ -241,10 +244,10 @@ func handlePageExists(c *gin.Context) {
|
|||||||
func handlePageUpdate(c *gin.Context) {
|
func handlePageUpdate(c *gin.Context) {
|
||||||
type QueryJSON struct {
|
type QueryJSON struct {
|
||||||
Page string `json:"page"`
|
Page string `json:"page"`
|
||||||
FileName string `json:"file_name"`
|
|
||||||
NewText string `json:"new_text"`
|
NewText string `json:"new_text"`
|
||||||
IsEncrypted bool `json:"is_encrypted"`
|
IsEncrypted bool `json:"is_encrypted"`
|
||||||
IsPrimed bool `json:"is_primed"`
|
IsPrimed bool `json:"is_primed"`
|
||||||
|
Meta string `json:"meta"`
|
||||||
}
|
}
|
||||||
var json QueryJSON
|
var json QueryJSON
|
||||||
err := c.BindJSON(&json)
|
err := c.BindJSON(&json)
|
||||||
@ -253,7 +256,7 @@ func handlePageUpdate(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Wrong JSON"})
|
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Wrong JSON"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(json.NewText) > 10000000 {
|
if len(json.NewText) > 100000000 {
|
||||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Too much"})
|
c.JSON(http.StatusOK, gin.H{"success": false, "message": "Too much"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -270,9 +273,7 @@ func handlePageUpdate(c *gin.Context) {
|
|||||||
} else if p.IsEncrypted {
|
} else if p.IsEncrypted {
|
||||||
message = "Encrypted, must decrypt first"
|
message = "Encrypted, must decrypt first"
|
||||||
} else {
|
} else {
|
||||||
// Add the page name into the history so it can be retrieved
|
p.Meta = json.Meta
|
||||||
p.Update(json.FileName)
|
|
||||||
// Add the page text so it can be retried as the latest part of the history
|
|
||||||
p.Update(json.NewText)
|
p.Update(json.NewText)
|
||||||
if json.IsEncrypted {
|
if json.IsEncrypted {
|
||||||
p.IsEncrypted = true
|
p.IsEncrypted = true
|
||||||
@ -280,6 +281,7 @@ func handlePageUpdate(c *gin.Context) {
|
|||||||
if json.IsPrimed {
|
if json.IsPrimed {
|
||||||
p.IsPrimedForSelfDestruct = true
|
p.IsPrimedForSelfDestruct = true
|
||||||
}
|
}
|
||||||
|
p.Save()
|
||||||
message = "Saved"
|
message = "Saved"
|
||||||
success = true
|
success = true
|
||||||
}
|
}
|
||||||
|
1
page.go
1
page.go
@ -16,6 +16,7 @@ import (
|
|||||||
type Page struct {
|
type Page struct {
|
||||||
Name string
|
Name string
|
||||||
Text versionedtext.VersionedText
|
Text versionedtext.VersionedText
|
||||||
|
Meta string
|
||||||
RenderedPage string
|
RenderedPage string
|
||||||
IsLocked bool
|
IsLocked bool
|
||||||
PassphraseToUnlock string
|
PassphraseToUnlock string
|
||||||
|
Loading…
Reference in New Issue
Block a user