all repos — legit @ a87f88a57c68627a1f63f1551fcef2c1f1ec7036

web frontend for git, written in go

routes: add raw file view
Anirudh Oppiliappan x@icyphox.sh
Sun, 25 Feb 2024 23:15:21 +0200
commit

a87f88a57c68627a1f63f1551fcef2c1f1ec7036

parent

bdfc973207a67a3b217c130520d53373d088763c

3 files changed, 19 insertions(+), 2 deletions(-)

jump to
M routes/routes.goroutes/routes.go

@@ -8,6 +8,7 @@ "net/http"

"os" "path/filepath" "sort" + "strconv" "time" "git.icyphox.sh/legit/config"

@@ -199,6 +200,11 @@ return

} func (d *deps) FileContent(w http.ResponseWriter, r *http.Request) { + var raw bool + if rawParam, err := strconv.ParseBool(r.URL.Query().Get("raw")); err == nil { + raw = rawParam + } + name := flow.Param(r.Context(), "name") if d.isIgnored(name) { d.Write404(w)

@@ -222,7 +228,11 @@ data["ref"] = ref

data["desc"] = getDescription(path) data["path"] = treePath - d.showFile(contents, data, w) + if raw { + d.showRaw(contents, w) + } else { + d.showFile(contents, data, w) + } return }
M routes/template.goroutes/template.go

@@ -95,3 +95,10 @@ log.Println(err)

return } } + +func (d *deps) showRaw(content string, w http.ResponseWriter) { + w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "text/plain") + w.Write([]byte(content)) + return +}
M templates/file.htmltemplates/file.html

@@ -5,7 +5,7 @@ {{ template "repoheader" . }}

<body> {{ template "nav" . }} <main> - <p>{{ .path }}</p> + <p>{{ .path }} (<a style="color: gray" href="?raw=true">view raw</a>)</p> <div class="file-wrapper"> <table > <tbody><tr>