mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added current version number information (really lazily)
Former-commit-id: 94c07c4ea5425b921b79415dbb532f1557f81d7c [formerly 831d807551fce85448eb75159812c23a8bf3ead3] [formerly 07049a072587969f1fc4632fdd56edd33aae1f31 [formerly 189adc2fe2
]]
Former-commit-id: 0581c8c6ff9af9741dfc1e7c4f2270cba635bd1c [formerly 9f7127a4e6031c2525fa21477b15569c0ac43cd2]
Former-commit-id: fd2a63bad694b3c74728d9c5ecca20f66be1dfaa
This commit is contained in:
parent
24f4d873e7
commit
639d64bb26
8
db.go
8
db.go
@ -43,7 +43,7 @@ type WikiData struct {
|
|||||||
Locked string
|
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)
|
Open(RuntimeArgs.DatabaseLocation)
|
||||||
defer Close()
|
defer Close()
|
||||||
title = strings.ToLower(title)
|
title = strings.ToLower(title)
|
||||||
@ -53,8 +53,9 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti
|
|||||||
currentText := ""
|
currentText := ""
|
||||||
encrypted := false
|
encrypted := false
|
||||||
locked := ""
|
locked := ""
|
||||||
|
currentVersionNum := -1
|
||||||
if !open {
|
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 {
|
err := db.View(func(tx *bolt.Tx) error {
|
||||||
var err error
|
var err error
|
||||||
@ -75,6 +76,7 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti
|
|||||||
currentText = p.CurrentText
|
currentText = p.CurrentText
|
||||||
encrypted = p.Encrypted
|
encrypted = p.Encrypted
|
||||||
locked = p.Locked
|
locked = p.Locked
|
||||||
|
currentVersionNum = len(p.Diffs) - 1
|
||||||
if version > -1 && version < len(p.Diffs) {
|
if version > -1 && version < len(p.Diffs) {
|
||||||
// get that version of text instead
|
// get that version of text instead
|
||||||
currentText = rebuildTextsToDiffN(p, version)
|
currentText = rebuildTextsToDiffN(p, version)
|
||||||
@ -87,7 +89,7 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool, ti
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Could not get WikiData: %s", err)
|
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 {
|
func (p *WikiData) load(title string) error {
|
||||||
|
31
routes.go
31
routes.go
@ -93,7 +93,7 @@ func encryptionRoute(c *gin.Context) {
|
|||||||
if option == "/decrypt" {
|
if option == "/decrypt" {
|
||||||
if c.BindJSON(&jsonLoad) == nil {
|
if c.BindJSON(&jsonLoad) == nil {
|
||||||
var err error
|
var err error
|
||||||
currentText, _, _, _, encrypted, _ := getCurrentText(title, -1)
|
currentText, _, _, _, encrypted, _, _ := getCurrentText(title, -1)
|
||||||
if encrypted == true {
|
if encrypted == true {
|
||||||
currentText, err = decryptString(currentText, jsonLoad.Password)
|
currentText, err = decryptString(currentText, jsonLoad.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -241,7 +241,7 @@ func editNote(c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
version := c.DefaultQuery("version", "-1")
|
version := c.DefaultQuery("version", "-1")
|
||||||
versionNum, _ := strconv.Atoi(version)
|
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/") {
|
if strings.Contains(c.Request.Header.Get("User-Agent"), "curl/") {
|
||||||
c.Data(200, "text/plain", []byte(currentText))
|
c.Data(200, "text/plain", []byte(currentText))
|
||||||
return
|
return
|
||||||
@ -262,17 +262,18 @@ func editNote(c *gin.Context) {
|
|||||||
|
|
||||||
CodeType := getCodeType(title)
|
CodeType := getCodeType(title)
|
||||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||||
"Title": title,
|
"Title": title,
|
||||||
"WikiName": RuntimeArgs.WikiName,
|
"WikiName": RuntimeArgs.WikiName,
|
||||||
"ExternalIP": RuntimeArgs.ExternalIP,
|
"ExternalIP": RuntimeArgs.ExternalIP,
|
||||||
"CurrentText": currentText,
|
"CurrentText": currentText,
|
||||||
"NumRows": numRows,
|
"CurrentVersionNum": currentVersionNum,
|
||||||
"Versions": versions,
|
"NumRows": numRows,
|
||||||
"TotalTime": totalTimeString,
|
"Versions": versions,
|
||||||
"SocketType": RuntimeArgs.Socket,
|
"TotalTime": totalTimeString,
|
||||||
"NoEdit": !currentVersion,
|
"SocketType": RuntimeArgs.Socket,
|
||||||
"Coding": len(CodeType) > 0,
|
"NoEdit": !currentVersion,
|
||||||
"CodeType": CodeType,
|
"Coding": len(CodeType) > 0,
|
||||||
|
"CodeType": CodeType,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,7 +288,7 @@ func everythingElse(c *gin.Context) {
|
|||||||
if strings.ToLower(title) == "help" {
|
if strings.ToLower(title) == "help" {
|
||||||
versionNum = -1
|
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" {
|
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, "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)
|
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" {
|
if strings.ToLower(title) == "help" {
|
||||||
versionNum = -1
|
versionNum = -1
|
||||||
}
|
}
|
||||||
currentText, _, _, _, _, _ := getCurrentText(title, versionNum)
|
currentText, _, _, _, _, _, _ := getCurrentText(title, versionNum)
|
||||||
c.Writer.Header().Set("Content-Type", contentType(title))
|
c.Writer.Header().Set("Content-Type", contentType(title))
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
|
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
|
||||||
|
@ -86,6 +86,7 @@
|
|||||||
<li class="dropdown active">
|
<li class="dropdown active">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit <span class="caret"></span></a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit <span class="caret"></span></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
|
<li class="dropdown-header">Version: #{{ .CurrentVersionNum }}</li>
|
||||||
<li class="dropdown-header">Time edited: {{ .TotalTime }}</li>
|
<li class="dropdown-header">Time edited: {{ .TotalTime }}</li>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li class="dropdown-header">Other versions</li>
|
<li class="dropdown-header">Other versions</li>
|
||||||
|
Loading…
Reference in New Issue
Block a user