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

One more global

This commit is contained in:
Daniel Heath 2018-04-28 12:16:10 +10:00
parent c2cd54a12d
commit d095915f83

View File

@ -24,7 +24,6 @@ import (
const minutesToUnlock = 10.0 const minutesToUnlock = 10.0
var defaultLock string
var needSitemapUpdate = true var needSitemapUpdate = true
var pathToData string var pathToData string
var log *lumber.ConsoleLogger var log *lumber.ConsoleLogger
@ -45,6 +44,13 @@ type Site struct {
Logger *lumber.ConsoleLogger Logger *lumber.ConsoleLogger
} }
func (s Site) defaultLock() string {
if s.DefaultPassword == "" {
return ""
}
return HashPassword(s.DefaultPassword)
}
func Serve( func Serve(
filepathToData, filepathToData,
host, host,
@ -171,7 +177,7 @@ func (s Site) Router() *gin.Engine {
router.POST("/relinquish", handlePageRelinquish) // relinquish returns the page no matter what (and destroys if nessecary) router.POST("/relinquish", handlePageRelinquish) // relinquish returns the page no matter what (and destroys if nessecary)
router.POST("/exists", handlePageExists) router.POST("/exists", handlePageExists)
router.POST("/prime", handlePrime) router.POST("/prime", handlePrime)
router.POST("/lock", handleLock) router.POST("/lock", s.handleLock)
router.POST("/publish", handlePublish) router.POST("/publish", handlePublish)
router.POST("/encrypt", handleEncrypt) router.POST("/encrypt", handleEncrypt)
router.DELETE("/oldlist", handleClearOldListItems) router.DELETE("/oldlist", handleClearOldListItems)
@ -180,12 +186,6 @@ func (s Site) Router() *gin.Engine {
// start long-processes as threads // start long-processes as threads
go thread_SiteMap() go thread_SiteMap()
// lock all pages automatically
if s.DefaultPassword != "" {
fmt.Println("running with locked pages")
defaultLock = HashPassword(s.DefaultPassword)
}
// Allow iframe/scripts in markup? // Allow iframe/scripts in markup?
allowInsecureHtml = s.AllowInsecure allowInsecureHtml = s.AllowInsecure
return router return router
@ -389,9 +389,9 @@ func (s Site) handlePageRequest(c *gin.Context) {
} }
// use the default lock // use the default lock
if defaultLock != "" && p.IsNew() { if s.defaultLock() != "" && p.IsNew() {
p.IsLocked = true p.IsLocked = true
p.PassphraseToUnlock = defaultLock p.PassphraseToUnlock = s.defaultLock()
} }
version := c.DefaultQuery("version", "ajksldfjl") version := c.DefaultQuery("version", "ajksldfjl")
@ -657,7 +657,7 @@ func handlePrime(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": true, "message": "Primed"}) c.JSON(http.StatusOK, gin.H{"success": true, "message": "Primed"})
} }
func handleLock(c *gin.Context) { func (s Site) handleLock(c *gin.Context) {
type QueryJSON struct { type QueryJSON struct {
Page string `json:"page"` Page string `json:"page"`
Passphrase string `json:"passphrase"` Passphrase string `json:"passphrase"`
@ -669,9 +669,9 @@ func handleLock(c *gin.Context) {
return return
} }
p := Open(json.Page) p := Open(json.Page)
if defaultLock != "" && p.IsNew() { if s.defaultLock() != "" && p.IsNew() {
p.IsLocked = true // IsLocked was replaced by variable wrt Context p.IsLocked = true // IsLocked was replaced by variable wrt Context
p.PassphraseToUnlock = defaultLock p.PassphraseToUnlock = s.defaultLock()
} }
if p.IsEncrypted { if p.IsEncrypted {