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
This commit is contained in:
parent
b704768ded
commit
e33e3a7d1b
2
main.go
2
main.go
@ -27,6 +27,7 @@ var RuntimeArgs struct {
|
||||
ServerCRT string
|
||||
ServerKey string
|
||||
SourcePath string
|
||||
AdminKey string
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -34,6 +35,7 @@ func main() {
|
||||
databaseFile := path.Join(path.Dir(executableFile), "data.db")
|
||||
flag.StringVar(&RuntimeArgs.Port, "p", ":12312", "port to bind")
|
||||
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.ServerKey, "key", "", "location of ssl key")
|
||||
flag.CommandLine.Usage = func() {
|
||||
|
36
routes.go
36
routes.go
@ -9,6 +9,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/russross/blackfriday"
|
||||
@ -48,7 +49,14 @@ func everythingElse(c *gin.Context) {
|
||||
option := c.Param("option")
|
||||
title := c.Param("title")
|
||||
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" {
|
||||
renderList(c, title)
|
||||
} else if title == "static" {
|
||||
@ -67,13 +75,8 @@ func serveStaticFile(c *gin.Context, option string) {
|
||||
}
|
||||
}
|
||||
|
||||
func renderMarkdown(c *gin.Context, title string) {
|
||||
var p CowyoData
|
||||
err := p.load(strings.ToLower(title))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
unsafe := blackfriday.MarkdownCommon([]byte(p.CurrentText))
|
||||
func renderMarkdown(c *gin.Context, currentText string, title string) {
|
||||
unsafe := blackfriday.MarkdownCommon([]byte(currentText))
|
||||
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
|
||||
html2 := string(html)
|
||||
r, _ := regexp.Compile("\\$\\$(.*?)\\$\\$")
|
||||
@ -186,5 +189,20 @@ func deleteListItem(c *gin.Context) {
|
||||
"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