Author | Jakob Wakeling <[email protected]> |
Date | 2023-11-30 10:38:18 |
Commit | db4ceebc97457e4d81187c42f32caae1c6e15278 |
Parent | 86e8cb8468a5da794f253effe57277f54e9bd1a0 |
Add line count to file view
Diffstat
M | res/repo/file.html | | | 2 | +- |
M | src/admin/users.go | | | 2 | +- |
M | src/repo/file.go | | | 9 | ++++----- |
3 files changed, 6 insertions, 7 deletions
diff --git a/res/repo/file.html b/res/repo/file.html index ea7a677..cfa6f52 100644 --- a/res/repo/file.html +++ b/res/repo/file.html @@ -3,7 +3,7 @@ <body> <header> {{template "repo/header" .}}<hr> - {{.HtmlPath}} ({{.Size}}) {{.Mode}} <a href="/{{.Name}}/download/{{.Path}}">download</a> + {{.HtmlPath}} ({{.LineC}}, {{.Size}}) {{.Mode}} <a href="/{{.Name}}/download/{{.Path}}">download</a> </header><hr> <main> <table> diff --git a/src/admin/users.go b/src/admin/users.go index 5d1a674..67a855c 100644 --- a/src/admin/users.go +++ b/src/admin/users.go @@ -175,7 +175,7 @@ func HandleUserEdit(w http.ResponseWriter, r *http.Request) { if data.Form.Name == "" { data.Message = "Username cannot be empty" - } else if slices.Contains(goit.Reserved, data.Form.Name) { + } else if slices.Contains(goit.Reserved, data.Form.Name) && user.Id != 0 { data.Message = "Username \"" + data.Form.Name + "\" is reserved" } else if exists, err := goit.UserExists(data.Form.Name); err != nil { log.Println("[/admin/user/edit]", err.Error()) diff --git a/src/repo/file.go b/src/repo/file.go index d0f451c..a7ffe9e 100644 --- a/src/repo/file.go +++ b/src/repo/file.go @@ -2,6 +2,7 @@ package repo import ( "errors" + "fmt" "html/template" "io" "log" @@ -26,10 +27,6 @@ func HandleFile(w http.ResponseWriter, r *http.Request) { } treepath := mux.Vars(r)["path"] - // if treepath == "" { - // goit.HttpError(w, http.StatusNotFound) - // return - // } repo, err := goit.GetRepoByName(mux.Vars(r)["repo"]) if err != nil { @@ -43,7 +40,7 @@ func HandleFile(w http.ResponseWriter, r *http.Request) { data := struct { Title, Name, Description, Url string Readme, Licence string - Path, Size, Mode string + Path, LineC, Size, Mode string Lines []string Body string Editable bool @@ -139,6 +136,8 @@ func HandleFile(w http.ResponseWriter, r *http.Request) { rc.Close() } + data.LineC = fmt.Sprint(len(data.Lines), " lines") + if err := goit.Tmpl.ExecuteTemplate(w, "repo/file", data); err != nil { log.Println("[/repo/file]", err.Error()) }