1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Allow saving filename in history for cowyodel

This commit is contained in:
Zack Scholl 2017-08-12 08:05:01 -06:00
parent 89d0f828b0
commit c0b6365440

View File

@ -79,6 +79,7 @@ func handlePageRelinquish(c *gin.Context) {
} }
message := "Relinquished" message := "Relinquished"
p := Open(json.Page) p := Open(json.Page)
name, _ := p.Text.GetPreviousByIndex(0)
text := p.Text.GetCurrent() text := p.Text.GetCurrent()
isLocked := p.IsEncrypted isLocked := p.IsEncrypted
isEncrypted := p.IsEncrypted isEncrypted := p.IsEncrypted
@ -87,7 +88,13 @@ func handlePageRelinquish(c *gin.Context) {
p.Erase() p.Erase()
message = "Relinquished and erased" message = "Relinquished and erased"
} }
c.JSON(http.StatusOK, gin.H{"success": true, "message": message, "text": text, "locked": isLocked, "encrypted": isEncrypted, "destroyed": destroyed}) c.JSON(http.StatusOK, gin.H{"success": true,
"name": name,
"message": message,
"text": text,
"locked": isLocked,
"encrypted": isEncrypted,
"destroyed": destroyed})
} }
func handlePageRequest(c *gin.Context) { func handlePageRequest(c *gin.Context) {
@ -234,6 +241,7 @@ 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"`
@ -262,6 +270,10 @@ 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.Update(json.FileName)
// time.Sleep(1 * time.Second)
// 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