diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index cc5c82bc..d28e2614 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -236,6 +236,9 @@ func (p *Pages) funcMap() template.FuncMap { }, "cssContentHash": CssContentHash, "fileTree": filetree.FileTree, + "pathEscape": func(s string) string { + return url.PathEscape(s) + }, "pathUnescape": func(s string) string { u, _ := url.PathUnescape(s) return u diff --git a/appview/pages/templates/repo/tags.html b/appview/pages/templates/repo/tags.html index 2fe3fa1f..8d1ab91a 100644 --- a/appview/pages/templates/repo/tags.html +++ b/appview/pages/templates/repo/tags.html @@ -97,18 +97,24 @@ {{ $isPushAllowed := $root.RepoInfo.Roles.IsPushAllowed }} {{ $artifacts := index $root.ArtifactMap $tag.Tag.Hash }} - {{ if or (gt (len $artifacts) 0) $isPushAllowed }}

artifacts

{{ range $artifact := $artifacts }} {{ $args := dict "LoggedInUser" $root.LoggedInUser "RepoInfo" $root.RepoInfo "Artifact" $artifact }} {{ template "repo/fragments/artifact" $args }} {{ end }} +
+
+ {{ i "archive" "w-4 h-4" }} + + Source code (.tar.gz) + +
+
{{ if $isPushAllowed }} {{ block "uploadArtifact" (list $root $tag) }} {{ end }} {{ end }}
- {{ end }} {{ end }} {{ define "uploadArtifact" }} diff --git a/appview/repo/repo.go b/appview/repo/repo.go index 093bd248..cd6475a7 100644 --- a/appview/repo/repo.go +++ b/appview/repo/repo.go @@ -81,6 +81,25 @@ func New( } } +func (rp *Repo) DownloadArchive(w http.ResponseWriter, r *http.Request) { + refParam := chi.URLParam(r, "ref") + f, err := rp.repoResolver.Resolve(r) + if err != nil { + log.Println("failed to get repo and knot", err) + return + } + + var uri string + if rp.config.Core.Dev { + uri = "http" + } else { + uri = "https" + } + url := fmt.Sprintf("%s://%s/%s/%s/archive/%s.tar.gz", uri, f.Knot, f.OwnerDid(), f.RepoName, url.PathEscape(refParam)) + + http.Redirect(w, r, url, http.StatusFound) +} + func (rp *Repo) RepoLog(w http.ResponseWriter, r *http.Request) { f, err := rp.repoResolver.Resolve(r) if err != nil { diff --git a/appview/repo/router.go b/appview/repo/router.go index 16e0af43..0a0f80de 100644 --- a/appview/repo/router.go +++ b/appview/repo/router.go @@ -38,6 +38,10 @@ func (rp *Repo) Router(mw *middleware.Middleware) http.Handler { r.Get("/blob/{ref}/*", rp.RepoBlob) r.Get("/raw/{ref}/*", rp.RepoBlobRaw) + // intentionally doesn't use /* as this isn't + // a file path + r.Get("/archive/{ref}", rp.DownloadArchive) + r.Route("/fork", func(r chi.Router) { r.Use(middleware.AuthMiddleware(rp.oauth)) r.Get("/", rp.ForkRepo)