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

Killing globals

This commit is contained in:
Daniel Heath 2018-04-28 12:13:19 +10:00
parent 2e80633cd4
commit c2cd54a12d

View File

@ -25,7 +25,6 @@ import (
const minutesToUnlock = 10.0 const minutesToUnlock = 10.0
var defaultLock string var defaultLock string
var allowFileUploads bool
var needSitemapUpdate = true var needSitemapUpdate = true
var pathToData string var pathToData string
var log *lumber.ConsoleLogger var log *lumber.ConsoleLogger
@ -103,7 +102,6 @@ func Serve(
func (s Site) Router() *gin.Engine { func (s Site) Router() *gin.Engine {
pathToData = s.PathToData pathToData = s.PathToData
allowFileUploads = s.Fileuploads
log = s.Logger log = s.Logger
if log == nil { if log == nil {
@ -162,7 +160,7 @@ func (s Site) Router() *gin.Engine {
} }
}) })
router.POST("/uploads", handleUpload) router.POST("/uploads", s.handleUpload)
router.GET("/:page", func(c *gin.Context) { router.GET("/:page", func(c *gin.Context) {
page := c.Param("page") page := c.Param("page")
@ -351,7 +349,7 @@ func (s Site) handlePageRequest(c *gin.Context) {
return return
} else if page == "uploads" { } else if page == "uploads" {
if len(command) == 0 || command == "/" || command == "/edit" { if len(command) == 0 || command == "/" || command == "/edit" {
if !allowFileUploads { if !s.Fileuploads {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("Uploads are disabled on this server")) c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("Uploads are disabled on this server"))
return return
} }
@ -517,7 +515,7 @@ func (s Site) handlePageRequest(c *gin.Context) {
"Date": time.Now().Format("2006-01-02"), "Date": time.Now().Format("2006-01-02"),
"UnixTime": time.Now().Unix(), "UnixTime": time.Now().Unix(),
"ChildPageNames": p.ChildPageNames(), "ChildPageNames": p.ChildPageNames(),
"AllowFileUploads": allowFileUploads, "AllowFileUploads": s.Fileuploads,
"MaxUploadMB": s.MaxUploadSize, "MaxUploadMB": s.MaxUploadSize,
}) })
} }
@ -737,8 +735,8 @@ func handlePublish(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": true, "message": message}) c.JSON(http.StatusOK, gin.H{"success": true, "message": message})
} }
func handleUpload(c *gin.Context) { func (s Site) handleUpload(c *gin.Context) {
if !allowFileUploads { if !s.Fileuploads {
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("Uploads are disabled on this server")) c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("Uploads are disabled on this server"))
return return
} }