From e3d89c1b9936a32a1064dc7bb7ea6caf52fc1637 Mon Sep 17 00:00:00 2001 From: Winter Date: Sat, 9 Aug 2025 22:02:31 -0400 Subject: [PATCH] appview/repo/tags: add link to auto-generated source archive Change-Id: vtrouwuvwzqvrzkwzrwwoxtvmkmrzlxv Signed-off-by: Winter --- appview/pages/funcmap.go | 3 +++ appview/pages/templates/repo/tags.html | 10 ++++++++-- appview/repo/repo.go | 19 +++++++++++++++++++ appview/repo/router.go | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index cc5c82b..d28e261 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 2fe3fa1..8d1ab91 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 9e9433d..8c50aee 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 16e0af4..0a0f80d 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) -- 2.43.0