appview/repo/tags: add link to auto-generated source archive #442

merged
opened by winter.bsky.social targeting master from winter.bsky.social/core: push-vtrouwuvwzqv
Changed files
+34 -2
appview
pages
templates
repo
repo
+3
appview/pages/funcmap.go
···
},
"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
+8 -2
appview/pages/templates/repo/tags.html
···
{{ $isPushAllowed := $root.RepoInfo.Roles.IsPushAllowed }}
{{ $artifacts := index $root.ArtifactMap $tag.Tag.Hash }}
-
{{ if or (gt (len $artifacts) 0) $isPushAllowed }}
<h2 class="my-4 text-sm text-left text-gray-700 dark:text-gray-300 uppercase font-bold">artifacts</h2>
<div class="flex flex-col rounded border border-gray-200 dark:border-gray-700">
{{ range $artifact := $artifacts }}
{{ $args := dict "LoggedInUser" $root.LoggedInUser "RepoInfo" $root.RepoInfo "Artifact" $artifact }}
{{ template "repo/fragments/artifact" $args }}
{{ end }}
+
<div id="artifact-git-source" class="flex items-center justify-between p-2 border-b border-gray-200 dark:border-gray-700">
+
<div id="left-side" class="flex items-center gap-2 min-w-0 max-w-[60%]">
+
{{ i "archive" "w-4 h-4" }}
+
<a href="/{{ $root.RepoInfo.FullName }}/archive/{{ pathEscape (print "refs/tags/" $tag.Name) }}" class="no-underline hover:no-underline">
+
Source code (.tar.gz)
+
</a>
+
</div>
+
</div>
{{ if $isPushAllowed }}
{{ block "uploadArtifact" (list $root $tag) }} {{ end }}
{{ end }}
</div>
-
{{ end }}
{{ end }}
{{ define "uploadArtifact" }}
+19
appview/repo/repo.go
···
}
}
+
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 {
+4
appview/repo/router.go
···
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)