From 3a04f7e80a3fb7298c7b2198bc04a0f50ff1da50 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Fri, 17 Jul 2020 20:18:03 +0500 Subject: [PATCH] Several improvements --- cfg/config.go | 20 +++++++++++++------- fs/html.go | 1 + fs/hypha.go | 3 ++- main.go | 11 +---------- wiki/config.json | 2 ++ 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index ed03401..fbe0107 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -28,13 +28,15 @@ var ( configJsonPath string // Default values that can be overriden in config.json - Address = "0.0.0.0:80" - TitleEditTemplate = `Edit %s` - TitleTemplate = `%s` - GenericErrorMsg = `Sorry, something went wrong` - SiteTitle = `MycorrhizaWiki` - Theme = `default-light` - Mycelia = []MyceliumConfig{ + Address = "0.0.0.0:80" + TitleEditTemplate = `Edit %s` + TitleTemplate = `%s` + GenericErrorMsg = `Sorry, something went wrong` + SiteTitle = `MycorrhizaWiki` + Theme = `default-light` + HomePage = `/Home` + BinaryLimit int64 = 10 << 20 + Mycelia = []MyceliumConfig{ {[]string{"main"}, "main"}, {[]string{"sys", "system"}, "system"}, } @@ -64,6 +66,8 @@ func readConfig() bool { Address string `json:"address"` Theme string `json:"theme"` SiteTitle string `json:"site-title"` + HomePage string `json:"home-page"` + BinaryLimitMB int64 `json:"binary-limit-mb"` Mycelia []MyceliumConfig `json:"mycelia"` TitleTemplates struct { EditHypha string `json:"edit-hypha"` @@ -82,6 +86,8 @@ func readConfig() bool { SiteTitle = cfg.SiteTitle TitleEditTemplate = cfg.TitleTemplates.EditHypha TitleTemplate = cfg.TitleTemplates.ViewHypha + HomePage = "/" + cfg.HomePage + BinaryLimit = 1024 * cfg.BinaryLimitMB Mycelia = cfg.Mycelia return true diff --git a/fs/html.go b/fs/html.go index 63eed74..cae647c 100644 --- a/fs/html.go +++ b/fs/html.go @@ -15,6 +15,7 @@ func (h *Hypha) asHtml() (string, error) {

` + rev.FullName + `

` // What about using
? + // TODO: support other things if h.hasBinaryData() { ret += fmt.Sprintf(``, util.DisplayToCanonical(rev.FullName), rev.Id) } diff --git a/fs/hypha.go b/fs/hypha.go index 4d2a974..589c100 100644 --- a/fs/hypha.go +++ b/fs/hypha.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/mycelium" "github.com/bouncepaw/mycorrhiza/util" ) @@ -275,7 +276,7 @@ func (h *Hypha) WriteBinaryFileFromHttpData(rq *http.Request) *Hypha { return h } // 10 MB file size limit - rq.ParseMultipartForm(10 << 20) + rq.ParseMultipartForm(cfg.BinaryLimit) // Read file file, handler, err := rq.FormFile("binary") if file != nil { diff --git a/main.go b/main.go index ea108dc..dbd2fe1 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "net/http" "os" @@ -82,16 +81,8 @@ func main() { r.HandleFunc(cfg.MyceliumUrl+cfg.HyphaUrl, HandlerView) r.HandleFunc(cfg.HyphaUrl, HandlerView) - // Debug page that renders all hyphae. - // TODO: make it redirect to home page. - // TODO: make a home page. r.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) { - w.Header().Set("Content-Type", "text/html; charset=utf-8") - w.WriteHeader(http.StatusOK) - fmt.Fprintln(w, ` -

Check out Fruit maybe.

-

TODO: make this page usable

- `) + http.Redirect(w, rq, cfg.HomePage, http.StatusSeeOther) }) http.Handle("/", r) diff --git a/wiki/config.json b/wiki/config.json index 5e49f42..3d41bce 100644 --- a/wiki/config.json +++ b/wiki/config.json @@ -2,6 +2,8 @@ "address": "0.0.0.0:1737", "theme": "default-light", "site-title": "🍄 MycorrhizaWiki", + "home-page": "Home", + "binary-limit-mb": 10, "title-templates": { "edit-hypha": "Edit %s at MycorrhizaWiki", "view-hypha": "%s at MycorrhizaWiki"