forked from tangled.org/core
Monorepo for Tangled

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

Signed-off-by: Winter <winter@winter.cafe>

authored by winter.bsky.social and committed by Tangled e8162bb3 9ff4785b

Changed files
+34 -2
appview
pages
templates
repo
repo
+3
appview/pages/funcmap.go
··· 236 236 }, 237 237 "cssContentHash": CssContentHash, 238 238 "fileTree": filetree.FileTree, 239 + "pathEscape": func(s string) string { 240 + return url.PathEscape(s) 241 + }, 239 242 "pathUnescape": func(s string) string { 240 243 u, _ := url.PathUnescape(s) 241 244 return u
+8 -2
appview/pages/templates/repo/tags.html
··· 97 97 {{ $isPushAllowed := $root.RepoInfo.Roles.IsPushAllowed }} 98 98 {{ $artifacts := index $root.ArtifactMap $tag.Tag.Hash }} 99 99 100 - {{ if or (gt (len $artifacts) 0) $isPushAllowed }} 101 100 <h2 class="my-4 text-sm text-left text-gray-700 dark:text-gray-300 uppercase font-bold">artifacts</h2> 102 101 <div class="flex flex-col rounded border border-gray-200 dark:border-gray-700"> 103 102 {{ range $artifact := $artifacts }} 104 103 {{ $args := dict "LoggedInUser" $root.LoggedInUser "RepoInfo" $root.RepoInfo "Artifact" $artifact }} 105 104 {{ template "repo/fragments/artifact" $args }} 106 105 {{ end }} 106 + <div id="artifact-git-source" class="flex items-center justify-between p-2 border-b border-gray-200 dark:border-gray-700"> 107 + <div id="left-side" class="flex items-center gap-2 min-w-0 max-w-[60%]"> 108 + {{ i "archive" "w-4 h-4" }} 109 + <a href="/{{ $root.RepoInfo.FullName }}/archive/{{ pathEscape (print "refs/tags/" $tag.Name) }}" class="no-underline hover:no-underline"> 110 + Source code (.tar.gz) 111 + </a> 112 + </div> 113 + </div> 107 114 {{ if $isPushAllowed }} 108 115 {{ block "uploadArtifact" (list $root $tag) }} {{ end }} 109 116 {{ end }} 110 117 </div> 111 - {{ end }} 112 118 {{ end }} 113 119 114 120 {{ define "uploadArtifact" }}
+19
appview/repo/repo.go
··· 81 81 } 82 82 } 83 83 84 + func (rp *Repo) DownloadArchive(w http.ResponseWriter, r *http.Request) { 85 + refParam := chi.URLParam(r, "ref") 86 + f, err := rp.repoResolver.Resolve(r) 87 + if err != nil { 88 + log.Println("failed to get repo and knot", err) 89 + return 90 + } 91 + 92 + var uri string 93 + if rp.config.Core.Dev { 94 + uri = "http" 95 + } else { 96 + uri = "https" 97 + } 98 + url := fmt.Sprintf("%s://%s/%s/%s/archive/%s.tar.gz", uri, f.Knot, f.OwnerDid(), f.RepoName, url.PathEscape(refParam)) 99 + 100 + http.Redirect(w, r, url, http.StatusFound) 101 + } 102 + 84 103 func (rp *Repo) RepoLog(w http.ResponseWriter, r *http.Request) { 85 104 f, err := rp.repoResolver.Resolve(r) 86 105 if err != nil {
+4
appview/repo/router.go
··· 38 38 r.Get("/blob/{ref}/*", rp.RepoBlob) 39 39 r.Get("/raw/{ref}/*", rp.RepoBlobRaw) 40 40 41 + // intentionally doesn't use /* as this isn't 42 + // a file path 43 + r.Get("/archive/{ref}", rp.DownloadArchive) 44 + 41 45 r.Route("/fork", func(r chi.Router) { 42 46 r.Use(middleware.AuthMiddleware(rp.oauth)) 43 47 r.Get("/", rp.ForkRepo)