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

Add -debounce for setting the debounce time

This commit is contained in:
Zack Scholl 2017-11-04 15:30:44 -06:00
parent 85877602e0
commit 63bdbb5824
3 changed files with 16 additions and 5 deletions

View File

@ -19,8 +19,9 @@ import (
var customCSS []byte var customCSS []byte
var defaultLock string var defaultLock string
var debounceTime int
func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string, defaultPassword string) { func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defaultPage string, defaultPassword string, debounce int) {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
router := gin.Default() router := gin.Default()
store := sessions.NewCookieStore([]byte("secret")) store := sessions.NewCookieStore([]byte("secret"))
@ -63,11 +64,15 @@ func serve(host, port, crt_path, key_path string, TLS bool, cssFile string, defa
fmt.Printf("Loaded CSS file, %d bytes\n", len(customCSS)) fmt.Printf("Loaded CSS file, %d bytes\n", len(customCSS))
} }
// lock all pages automatically
if defaultPassword != "" { if defaultPassword != "" {
fmt.Println("running with locked pages") fmt.Println("running with locked pages")
defaultLock = HashPassword(defaultPassword) defaultLock = HashPassword(defaultPassword)
} }
// set the debounce time
debounceTime = debounce
if TLS { if TLS {
http.ListenAndServeTLS(host+":"+port, crt_path, key_path, router) http.ListenAndServeTLS(host+":"+port, crt_path, key_path, router)
} else { } else {
@ -334,6 +339,7 @@ func handlePageRequest(c *gin.Context) {
"RecentlyEdited": getRecentlyEdited(page, c), "RecentlyEdited": getRecentlyEdited(page, c),
"IsPublished": p.IsPublished, "IsPublished": p.IsPublished,
"CustomCSS": len(customCSS) > 0, "CustomCSS": len(customCSS) > 0,
"Debounce": debounceTime,
}) })
} }

View File

@ -38,7 +38,7 @@ func main() {
} else { } else {
fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port")) fmt.Printf("\nRunning cowyo server (version %s) at http://%s:%s\n\n", version, host, c.GlobalString("port"))
} }
serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css"), c.GlobalString("default-page"), c.GlobalString("lock")) serve(c.GlobalString("host"), c.GlobalString("port"), c.GlobalString("cert"), c.GlobalString("key"), TLS, c.GlobalString("css"), c.GlobalString("default-page"), c.GlobalString("lock"), c.GlobalInt("debounce"))
return nil return nil
} }
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
@ -87,6 +87,11 @@ func main() {
Value: "", Value: "",
Usage: "password to lock editing all files (default: all pages unlocked)", Usage: "password to lock editing all files (default: all pages unlocked)",
}, },
cli.IntFlag{
Name: "debounce",
Value: 500,
Usage: "debounce time for saving data, in milliseconds",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "debug, d", Name: "debug, d",
Usage: "turn on debugging", Usage: "turn on debugging",

View File

@ -176,7 +176,7 @@ body#pad textarea {
$('#saveEditButton').removeClass() $('#saveEditButton').removeClass()
$('#saveEditButton').text("Saving") $('#saveEditButton').text("Saving")
upload(); upload();
}, 500)); }, {{ .Debounce }}));
function upload() { function upload() {
$.ajax({ $.ajax({
@ -531,10 +531,10 @@ body#pad textarea {
<a href="#" id="menuLink1" class="pure-menu-link">View</a> <a href="#" id="menuLink1" class="pure-menu-link">View</a>
<ul class="pure-menu-children"> <ul class="pure-menu-children">
<li class="pure-menu-item"> <li class="pure-menu-item">
<a href="/{{ .Page }}/view" class="pure-menu-link">Current</a> <a href="/{{ .Page }}/read" class="pure-menu-link">Current</a>
</li> </li>
{{ range .RecentlyEdited}} {{ range .RecentlyEdited}}
<li class="pure-menu-item"><a class="pure-menu-link" href="/{{.}}/view/">{{.}}</a></li> <li class="pure-menu-item"><a class="pure-menu-link" href="/{{.}}/read">{{.}}</a></li>
{{ end }} {{ end }}
</ul> </ul>
</li> </li>