mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added admin priveleges to list all the notes
Former-commit-id: d3b4678faa17ce571251859c4c078e9caf5124e6 [formerly 1a403d45516aa9172cd5411cb14c18242770c8ed] [formerly 892b010c8ca3dc6ce297350195569e5694ebaeef [formerly e33e3a7d1b
]]
Former-commit-id: 81562a26ff15a36ac01701736faa537cbd1ea91d [formerly 61532530901c7be80e95c9aadd10b3c5edea3678]
Former-commit-id: 99bd94c9163a02621a5edfbde537ba8cc9f77620
This commit is contained in:
parent
7012b2b1a6
commit
c6877580ff
2
main.go
2
main.go
@ -27,6 +27,7 @@ var RuntimeArgs struct {
|
|||||||
ServerCRT string
|
ServerCRT string
|
||||||
ServerKey string
|
ServerKey string
|
||||||
SourcePath string
|
SourcePath string
|
||||||
|
AdminKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -34,6 +35,7 @@ func main() {
|
|||||||
databaseFile := path.Join(path.Dir(executableFile), "data.db")
|
databaseFile := path.Join(path.Dir(executableFile), "data.db")
|
||||||
flag.StringVar(&RuntimeArgs.Port, "p", ":12312", "port to bind")
|
flag.StringVar(&RuntimeArgs.Port, "p", ":12312", "port to bind")
|
||||||
flag.StringVar(&RuntimeArgs.DatabaseLocation, "db", databaseFile, "location of database file")
|
flag.StringVar(&RuntimeArgs.DatabaseLocation, "db", databaseFile, "location of database file")
|
||||||
|
flag.StringVar(&RuntimeArgs.AdminKey, "a", "", "key to use admin priveleges")
|
||||||
flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of ssl crt")
|
flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of ssl crt")
|
||||||
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key")
|
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key")
|
||||||
flag.CommandLine.Usage = func() {
|
flag.CommandLine.Usage = func() {
|
||||||
|
36
routes.go
36
routes.go
@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/boltdb/bolt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/microcosm-cc/bluemonday"
|
"github.com/microcosm-cc/bluemonday"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/russross/blackfriday"
|
||||||
@ -48,7 +49,14 @@ func everythingElse(c *gin.Context) {
|
|||||||
option := c.Param("option")
|
option := c.Param("option")
|
||||||
title := c.Param("title")
|
title := c.Param("title")
|
||||||
if option == "/view" {
|
if option == "/view" {
|
||||||
renderMarkdown(c, title)
|
var p CowyoData
|
||||||
|
err := p.load(strings.ToLower(title))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
renderMarkdown(c, p.CurrentText, title)
|
||||||
|
} else if option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
|
||||||
|
renderMarkdown(c, listEverything(), "Everything")
|
||||||
} else if option == "/list" {
|
} else if option == "/list" {
|
||||||
renderList(c, title)
|
renderList(c, title)
|
||||||
} else if title == "static" {
|
} else if title == "static" {
|
||||||
@ -67,13 +75,8 @@ func serveStaticFile(c *gin.Context, option string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderMarkdown(c *gin.Context, title string) {
|
func renderMarkdown(c *gin.Context, currentText string, title string) {
|
||||||
var p CowyoData
|
unsafe := blackfriday.MarkdownCommon([]byte(currentText))
|
||||||
err := p.load(strings.ToLower(title))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
unsafe := blackfriday.MarkdownCommon([]byte(p.CurrentText))
|
|
||||||
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
|
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
|
||||||
html2 := string(html)
|
html2 := string(html)
|
||||||
r, _ := regexp.Compile("\\$\\$(.*?)\\$\\$")
|
r, _ := regexp.Compile("\\$\\$(.*?)\\$\\$")
|
||||||
@ -186,5 +189,20 @@ func deleteListItem(c *gin.Context) {
|
|||||||
"message": "?",
|
"message": "?",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func listEverything() string {
|
||||||
|
everything := ""
|
||||||
|
db.View(func(tx *bolt.Tx) error {
|
||||||
|
// Assume bucket exists and has keys
|
||||||
|
b := tx.Bucket([]byte("datas"))
|
||||||
|
c := b.Cursor()
|
||||||
|
for k, v := c.First(); k != nil; k, v = c.Next() {
|
||||||
|
if len(v) > 1 {
|
||||||
|
everything += "- [" + string(k) + "](/" + string(k) + "/view) (" + strconv.Itoa(len(v)) + ")\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return everything
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user