diff --git a/db.go b/db.go index 4d31bb8..013e026 100644 --- a/db.go +++ b/db.go @@ -43,7 +43,7 @@ type WikiData struct { Locked string } -func getCurrentText(title string, version int) (string, []versionsInfo, bool, time.Duration, bool, string) { +func getCurrentText(title string, version int) (string, []versionsInfo, bool, time.Duration, bool, string, int) { Open(RuntimeArgs.DatabaseLocation) defer Close() title = strings.ToLower(title) @@ -53,8 +53,9 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti currentText := "" encrypted := false locked := "" + currentVersionNum := -1 if !open { - return currentText, vi, isCurrent, totalTime, encrypted, locked + return currentText, vi, isCurrent, totalTime, encrypted, locked, currentVersionNum } err := db.View(func(tx *bolt.Tx) error { var err error @@ -75,6 +76,7 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti currentText = p.CurrentText encrypted = p.Encrypted locked = p.Locked + currentVersionNum = len(p.Diffs) - 1 if version > -1 && version < len(p.Diffs) { // get that version of text instead currentText = rebuildTextsToDiffN(p, version) @@ -87,7 +89,7 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti if err != nil { fmt.Printf("Could not get WikiData: %s", err) } - return currentText, vi, isCurrent, totalTime, encrypted, locked + return currentText, vi, isCurrent, totalTime, encrypted, locked, currentVersionNum } func (p *WikiData) load(title string) error { diff --git a/routes.go b/routes.go index 7341415..4ae02bc 100644 --- a/routes.go +++ b/routes.go @@ -93,7 +93,7 @@ func encryptionRoute(c *gin.Context) { if option == "/decrypt" { if c.BindJSON(&jsonLoad) == nil { var err error - currentText, _, _, _, encrypted, _ := getCurrentText(title, -1) + currentText, _, _, _, encrypted, _, _ := getCurrentText(title, -1) if encrypted == true { currentText, err = decryptString(currentText, jsonLoad.Password) if err != nil { @@ -241,7 +241,7 @@ func editNote(c *gin.Context) { } else { version := c.DefaultQuery("version", "-1") versionNum, _ := strconv.Atoi(version) - currentText, versions, currentVersion, totalTime, encrypted, locked := getCurrentText(title, versionNum) + currentText, versions, currentVersion, totalTime, encrypted, locked, currentVersionNum := getCurrentText(title, versionNum) if strings.Contains(c.Request.Header.Get("User-Agent"), "curl/") { c.Data(200, "text/plain", []byte(currentText)) return @@ -262,17 +262,18 @@ func editNote(c *gin.Context) { CodeType := getCodeType(title) c.HTML(http.StatusOK, "index.tmpl", gin.H{ - "Title": title, - "WikiName": RuntimeArgs.WikiName, - "ExternalIP": RuntimeArgs.ExternalIP, - "CurrentText": currentText, - "NumRows": numRows, - "Versions": versions, - "TotalTime": totalTimeString, - "SocketType": RuntimeArgs.Socket, - "NoEdit": !currentVersion, - "Coding": len(CodeType) > 0, - "CodeType": CodeType, + "Title": title, + "WikiName": RuntimeArgs.WikiName, + "ExternalIP": RuntimeArgs.ExternalIP, + "CurrentText": currentText, + "CurrentVersionNum": currentVersionNum, + "NumRows": numRows, + "Versions": versions, + "TotalTime": totalTimeString, + "SocketType": RuntimeArgs.Socket, + "NoEdit": !currentVersion, + "Coding": len(CodeType) > 0, + "CodeType": CodeType, }) } } @@ -287,7 +288,7 @@ func everythingElse(c *gin.Context) { if strings.ToLower(title) == "help" { versionNum = -1 } - currentText, versions, _, totalTime, encrypted, locked := getCurrentText(title, versionNum) + currentText, versions, _, totalTime, encrypted, locked, _ := getCurrentText(title, versionNum) if (strings.Contains(currentText, "self-destruct\n") || strings.Contains(currentText, "\nself-destruct")) && strings.ToLower(title) != "help" { currentText = strings.Replace(currentText, "self-destruct\n", `> *This page has been deleted, you cannot return after closing.*`+"\n", 1) currentText = strings.Replace(currentText, "\nself-destruct", "\n"+`> *This page has been deleted, you cannot return after closing.*`, 1) @@ -301,7 +302,7 @@ func everythingElse(c *gin.Context) { if strings.ToLower(title) == "help" { versionNum = -1 } - currentText, _, _, _, _, _ := getCurrentText(title, versionNum) + currentText, _, _, _, _, _, _ := getCurrentText(title, versionNum) c.Writer.Header().Set("Content-Type", contentType(title)) c.Writer.Header().Set("Access-Control-Allow-Origin", "*") c.Writer.Header().Set("Access-Control-Max-Age", "86400") diff --git a/templates/index.tmpl b/templates/index.tmpl index 41b203e..6786578 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -86,6 +86,7 @@