Monorepo for Tangled tangled.org

appview: allows a default knot to be configured #991

open opened by willdot.net targeting master from willdot.net/tangled-fork: default-knot

This follows on from the work carried out in #836

I've added a select box in the Knots settings page which pulls in the users knots and also adds in knot1.tangled.sh. When the user selects one of these options, it will save to their profile in the database. NOTE: I haven't yet implemented adding that to the AT record because I'm not sure on how the lexicon setup works yet!

Then when users go to create a new repo / fork, if there is a value in their profile for the default knot, then that will pre select the knot to use for the new repo / fork.

This is a duplicate of https://tangled.org/tangled.org/core/pulls/858/ which had to be closed because there were merge conflicts which couldn't be resolved due to the origin fork being deleted ๐Ÿ™ˆ

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:dadhhalkfcq3gucaq25hjqon/sh.tangled.repo.pull/3mcrzfonnxs22
+129 -227
Interdiff #2 โ†’ #3
appview/db/db.go

This file has not been changed.

appview/db/profile.go

This patch was likely rebased, as context lines do not match.

+13 -5
appview/knots/knots.go
··· 81 return 82 } 83 84 defaultKnot := "" 85 profile, err := db.GetProfile(k.Db, user.Did()) 86 if err != nil { ··· 91 } 92 93 k.Pages.Knots(w, pages.KnotsParams{ 94 - LoggedInUser: user, 95 - Registrations: registrations, 96 - Tabs: knotsTabs, 97 - Tab: "knots", 98 - DefaultKnot: defaultKnot, 99 }) 100 } 101
··· 81 return 82 } 83 84 + availableKnots, err := k.Enforcer.GetKnotsForUser(user.Did()) 85 + if err != nil { 86 + k.Logger.Error("failed to fetch available knots for user", "err", err) 87 + w.WriteHeader(http.StatusInternalServerError) 88 + return 89 + } 90 + 91 defaultKnot := "" 92 profile, err := db.GetProfile(k.Db, user.Did()) 93 if err != nil { ··· 98 } 99 100 k.Pages.Knots(w, pages.KnotsParams{ 101 + LoggedInUser: user, 102 + Registrations: registrations, 103 + Tabs: knotsTabs, 104 + Tab: "knots", 105 + AvailableKnots: availableKnots, 106 + DefaultKnot: defaultKnot, 107 }) 108 } 109
appview/models/profile.go

This file has not been changed.

+6 -5
appview/pages/pages.go
··· 417 } 418 419 type KnotsParams struct { 420 - LoggedInUser *oauth.MultiAccountUser 421 - Registrations []models.Registration 422 - Tabs []map[string]any 423 - Tab string 424 - DefaultKnot string 425 } 426 427 func (p *Pages) Knots(w io.Writer, params KnotsParams) error {
··· 417 } 418 419 type KnotsParams struct { 420 + LoggedInUser *oauth.MultiAccountUser 421 + Registrations []models.Registration 422 + Tabs []map[string]any 423 + Tab string 424 + AvailableKnots []string 425 + DefaultKnot string 426 } 427 428 func (p *Pages) Knots(w io.Writer, params KnotsParams) error {
+21 -17
appview/pages/templates/knots/index.html
··· 64 {{ end }} 65 66 {{ define "default-knot" }} 67 - <section class="rounded w-full flex flex-col gap-2"> 68 - <h2 class="text-sm font-bold py-2 uppercase dark:text-gray-300">default knot</h2> 69 - <select id="default-knot" name="default-knot" 70 - class="p-1 max-w-64 border border-gray-200 bg-white dark:bg-gray-800 dark:text-white dark:border-gray-700" 71 - hx-post="/profile/default-knot" 72 - hx-swap="none" 73 - name="default-knot"> 74 - <option value="" > 75 - Choose a default Knot 76 - </option> 77 - <option value="knot1.tangled.sh" {{if eq $.DefaultKnot "knot1.tangled.sh"}}selected{{end}} > 78 - knot1.tangled.sh 79 - </option> 80 - {{ range $registration := .Registrations }} 81 - <option value="{{ .Domain }}" class="py-1" {{if eq $.DefaultKnot .Domain}}selected{{end}}> 82 - {{ .Domain }} 83 </option> 84 {{ end }} 85 </select> 86 - </section> 87 {{ end }} 88 89 {{ define "register" }}
··· 64 {{ end }} 65 66 {{ define "default-knot" }} 67 + <section class="rounded w-full flex flex-col gap-2"> 68 + <h2 class="text-sm font-bold py-2 uppercase dark:text-gray-300">default knot</h2> 69 + <form hx-post="/profile/default-knot" class="col-span-1 md:col-span-1 md:justify-self-end group flex gap-2 items-stretch"> 70 + <select 71 + id="default-knot" 72 + name="default-knot" 73 + required 74 + class="p-1 max-w-64 border border-gray-200 bg-white dark:bg-gray-800 dark:text-white dark:border-gray-700"> 75 + {{/* For some reason, we can't use an empty string in a <select> in all scenarios unless it is preceded by a disabled select?? No idea, could just be a Firefox thing? */}} 76 + <option value="[[none]]" class="py-1" {{ if not $.DefaultKnot }}selected{{ end }}> 77 + Choose a default knot 78 + </option> 79 + {{ range $.AvailableKnots }} 80 + <option value="{{ . }}" class="py-1" {{ if eq . $.DefaultKnot }}selected{{ end }}> 81 + {{ . }} 82 </option> 83 {{ end }} 84 </select> 85 + <button class="btn flex gap-2 items-center" type="submit"> 86 + {{ i "check" "size-4" }} 87 + {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }} 88 + </button> 89 + </form> 90 + </section> 91 {{ end }} 92 93 {{ define "register" }}
appview/pages/templates/repo/fork.html

This file has not been changed.

appview/pages/templates/repo/new.html

This file has not been changed.

appview/repo/repo.go

This file has not been changed.

+31 -12
appview/state/profile.go
··· 162 l.Error("failed to create timeline", "err", err) 163 } 164 165 s.pages.ProfileOverview(w, pages.ProfileOverviewParams{ 166 LoggedInUser: s.oauth.GetMultiAccountUser(r), 167 Card: profile, ··· 605 s.updateProfile(profile, w, r) 606 } 607 608 - func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r *http.Request) { 609 - 610 - 611 - 612 - 613 - 614 - 615 - 616 - s.updateProfile(profile, w, r) 617 - } 618 - 619 func (s *State) UpdateProfileDefaultKnot(w http.ResponseWriter, r *http.Request) { 620 err := r.ParseForm() 621 if err != nil { ··· 633 return 634 } 635 636 - profile.DefaultKnot = r.Form.Get("default-knot") 637 638 tx, err := s.db.BeginTx(r.Context(), nil) 639 if err != nil { ··· 646 log.Println("failed to update profile", err) 647 return 648 } 649 } 650 651 func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r *http.Request) {
··· 162 l.Error("failed to create timeline", "err", err) 163 } 164 165 + // populate commit counts in the timeline, using the punchcard 166 + now := time.Now() 167 + for _, p := range profile.Punchcard.Punches { 168 + years := now.Year() - p.Date.Year() 169 + months := int(now.Month() - p.Date.Month()) 170 + monthsAgo := years*12 + months 171 + if monthsAgo >= 0 && monthsAgo < len(timeline.ByMonth) { 172 + timeline.ByMonth[monthsAgo].Commits += p.Count 173 + } 174 + } 175 + 176 s.pages.ProfileOverview(w, pages.ProfileOverviewParams{ 177 LoggedInUser: s.oauth.GetMultiAccountUser(r), 178 Card: profile, ··· 616 s.updateProfile(profile, w, r) 617 } 618 619 func (s *State) UpdateProfileDefaultKnot(w http.ResponseWriter, r *http.Request) { 620 err := r.ParseForm() 621 if err != nil { ··· 633 return 634 } 635 636 + defaultKnot := r.Form.Get("default-knot") 637 + 638 + if defaultKnot == "[[none]]" { // see pages/templates/knots/index.html for more info on why we use this value 639 + defaultKnot = "" 640 + } 641 + 642 + profile.DefaultKnot = defaultKnot 643 644 tx, err := s.db.BeginTx(r.Context(), nil) 645 if err != nil { ··· 652 log.Println("failed to update profile", err) 653 return 654 } 655 + 656 + s.pages.HxRefresh(w) 657 + } 658 + 659 + func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r *http.Request) { 660 + 661 + 662 + 663 + 664 + 665 + 666 + 667 + s.updateProfile(profile, w, r) 668 } 669 670 func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r *http.Request) {
appview/state/router.go

This file has not been changed.

appview/state/state.go

This file has not been changed.

+28 -35
appview/pages/templates/layouts/fragments/topbar.html
··· 53 /> 54 <span class="hidden md:inline">{{ $user | resolve | truncateAt30 }}</span> 55 </summary> 56 - <div class="absolute right-0 mt-4 rounded bg-white dark:bg-gray-800 dark:text-white border border-gray-200 dark:border-gray-700 shadow-lg z-50 text-sm" style="width: 14rem;"> 57 {{ $active := .Active.Did }} 58 - {{ $linkStyle := "flex items-center gap-3 px-4 py-2 hover:no-underline hover:bg-gray-50 hover:dark:bg-gray-700/50" }} 59 60 {{ $others := .Accounts | otherAccounts $active }} 61 {{ if $others }} 62 - <div class="text-sm text-gray-500 dark:text-gray-400 px-3 py-1 pt-2">switch account</div> 63 - {{ range $others }} 64 <button 65 type="button" 66 hx-post="/account/switch" 67 hx-vals='{"did": "{{ .Did }}"}' 68 hx-swap="none" 69 - class="{{$linkStyle}} w-full text-left pl-3" 70 > 71 - <img src="{{ tinyAvatar .Did }}" alt="" class="rounded-full size-6 flex-shrink-0 border border-gray-300 dark:border-gray-700" /> 72 - <span class="truncate flex-1">{{ .Did | resolve }}</span> 73 </button> 74 - {{ end }} 75 {{ end }} 76 77 - <a href="/login?mode=add_account" class="{{$linkStyle}} pl-3"> 78 - <div class="size-6 rounded-full bg-gray-100 dark:bg-gray-700 flex items-center justify-center"> 79 - {{ i "plus" "size-3" }} 80 - </div> 81 - 82 - <div class="text-left flex-1 min-w-0 block truncate"> 83 - add account 84 - </div> 85 </a> 86 87 - <div class="border-t border-gray-200 dark:border-gray-700"> 88 - <a href="/{{ $active }}" class="{{$linkStyle}}"> 89 - {{ i "user" "size-4" }} 90 - profile 91 - </a> 92 - <a href="/{{ $active }}?tab=repos" class="{{$linkStyle}}"> 93 - {{ i "book-marked" "size-4" }} 94 - repositories 95 - </a> 96 - <a href="/{{ $active }}?tab=strings" class="{{$linkStyle}}"> 97 - {{ i "line-squiggle" "size-4" }} 98 - strings 99 - </a> 100 - <a href="/settings" class="{{$linkStyle}}"> 101 - {{ i "cog" "size-4" }} 102 - settings 103 - </a> 104 <a href="#" 105 hx-post="/logout" 106 hx-swap="none" 107 - class="{{$linkStyle}} text-red-400 hover:text-red-400 hover:bg-red-100 dark:hover:bg-red-700/20 pb-2"> 108 - {{ i "log-out" "size-4" }} 109 logout 110 </a> 111 </div>
··· 53 /> 54 <span class="hidden md:inline">{{ $user | resolve | truncateAt30 }}</span> 55 </summary> 56 + <div class="absolute right-0 mt-4 p-4 rounded bg-white dark:bg-gray-800 dark:text-white border border-gray-200 dark:border-gray-700 shadow-lg z-50" style="width: 14rem;"> 57 {{ $active := .Active.Did }} 58 + 59 + <div class="pb-2 mb-2 border-b border-gray-200 dark:border-gray-700"> 60 + <div class="flex items-center gap-2"> 61 + <img src="{{ tinyAvatar $active }}" alt="" class="rounded-full h-8 w-8 flex-shrink-0 border border-gray-300 dark:border-gray-700" /> 62 + <div class="flex-1 overflow-hidden"> 63 + <p class="font-medium text-sm truncate">{{ $active | resolve }}</p> 64 + <p class="text-xs text-green-600 dark:text-green-400">active</p> 65 + </div> 66 + </div> 67 + </div> 68 69 {{ $others := .Accounts | otherAccounts $active }} 70 {{ if $others }} 71 + <div class="pb-2 mb-2 border-b border-gray-200 dark:border-gray-700"> 72 + <p class="text-xs text-gray-500 dark:text-gray-400 uppercase tracking-wide mb-1">Switch Account</p> 73 + {{ range $others }} 74 <button 75 type="button" 76 hx-post="/account/switch" 77 hx-vals='{"did": "{{ .Did }}"}' 78 hx-swap="none" 79 + class="flex items-center gap-2 w-full py-1.5 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-left" 80 > 81 + <img src="{{ tinyAvatar .Did }}" alt="" class="rounded-full h-6 w-6 flex-shrink-0 border border-gray-300 dark:border-gray-700" /> 82 + <span class="text-sm truncate flex-1">{{ .Did | resolve }}</span> 83 </button> 84 + {{ end }} 85 + </div> 86 {{ end }} 87 88 + <a href="/login?mode=add_account" class="flex items-center gap-2 py-1 text-sm"> 89 + {{ i "plus" "w-4 h-4 flex-shrink-0" }} 90 + <span>Add another account</span> 91 </a> 92 93 + <div class="pt-2 mt-2 border-t border-gray-200 dark:border-gray-700 space-y-1"> 94 + <a href="/{{ $active }}" class="block py-1 text-sm">profile</a> 95 + <a href="/{{ $active }}?tab=repos" class="block py-1 text-sm">repositories</a> 96 + <a href="/{{ $active }}?tab=strings" class="block py-1 text-sm">strings</a> 97 + <a href="/settings" class="block py-1 text-sm">settings</a> 98 <a href="#" 99 hx-post="/logout" 100 hx-swap="none" 101 + class="block py-1 text-sm text-red-400 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300"> 102 logout 103 </a> 104 </div>
+5 -3
appview/pages/templates/repo/fragments/diff.html
··· 23 {{ block "subsCheckbox" $ }} {{ end }} 24 25 <!-- top bar --> 26 - <div class="sticky top-0 z-30 bg-slate-100 dark:bg-gray-900 flex items-center gap-2 col-span-full h-12 p-2 {{ if $root }}mt-4{{ end }}"> 27 <!-- left panel toggle --> 28 {{ template "filesToggle" . }} 29 ··· 31 {{ $stat := $diff.Stats }} 32 {{ $count := len $diff.ChangedFiles }} 33 {{ template "repo/fragments/diffStatPill" $stat }} 34 - <span class="text-xs text-gray-600 dark:text-gray-400 hidden md:inline-flex">{{ $count }} changed file{{ if ne $count 1 }}s{{ end }}</span> 35 36 {{ if $root }} 37 {{ if $root.IsInterdiff }} ··· 70 {{ template "collapseToggle" }} 71 72 <!-- diff options --> 73 - {{ template "repo/fragments/diffOpts" $opts }} 74 75 <!-- right panel toggle --> 76 {{ block "subsToggle" $ }} {{ end }}
··· 23 {{ block "subsCheckbox" $ }} {{ end }} 24 25 <!-- top bar --> 26 + <div class="sticky top-0 z-30 flex items-center gap-2 col-span-full h-12 p-2 {{ if $root }}mt-4{{ end }}"> 27 <!-- left panel toggle --> 28 {{ template "filesToggle" . }} 29 ··· 31 {{ $stat := $diff.Stats }} 32 {{ $count := len $diff.ChangedFiles }} 33 {{ template "repo/fragments/diffStatPill" $stat }} 34 + <span class="text-xs text-gray-600 dark:text-gray-400">{{ $count }} changed file{{ if ne $count 1 }}s{{ end }}</span> 35 36 {{ if $root }} 37 {{ if $root.IsInterdiff }} ··· 70 {{ template "collapseToggle" }} 71 72 <!-- diff options --> 73 + <div class="hidden md:block"> 74 + {{ template "repo/fragments/diffOpts" $opts }} 75 + </div> 76 77 <!-- right panel toggle --> 78 {{ block "subsToggle" $ }} {{ end }}
+4 -12
appview/pages/templates/repo/pulls/pull.html
··· 8 9 {{ define "mainLayout" }} 10 <div class="px-1 flex-grow flex flex-col gap-4"> 11 - <div class="max-w-full md:max-w-screen-lg mx-auto"> 12 {{ block "contentLayout" . }} 13 {{ block "content" . }}{{ end }} 14 {{ end }} ··· 51 {{ end }} 52 53 {{ define "repoContentLayout" }} 54 - <div class="grid grid-cols-1 md:grid-cols-10 gap-4 w-full"> 55 <section class="bg-white col-span-1 md:col-span-8 dark:bg-gray-800 p-6 rounded relative w-full mx-auto dark:text-white h-full flex-shrink"> 56 {{ block "repoContent" . }}{{ end }} 57 </section> ··· 246 {{ $lastIdx := index . 2 }} 247 {{ $root := index . 3 }} 248 {{ $round := $item.RoundNumber }} 249 - <div class=" 250 - {{ if eq $round 0 }}rounded-b{{ else }}rounded{{ end }} 251 - px-6 py-4 pr-2 pt-2 252 - {{ if eq $root.ActiveRound $round }} 253 - bg-blue-100 dark:bg-blue-900 border-b border-blue-200 dark:border-blue-700 254 - {{ else }} 255 - bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700 256 - {{ end }} 257 - flex gap-2 sticky top-0 z-20"> 258 <!-- left column: just profile picture --> 259 <div class="flex-shrink-0 pt-2"> 260 <img ··· 294 <div class="flex gap-2 items-center"> 295 {{ if ne $root.ActiveRound $round }} 296 <a class="btn-flat flex items-center gap-2 no-underline hover:no-underline text-sm" 297 - href="/{{ $root.RepoInfo.FullName }}/pulls/{{ $root.Pull.PullId }}/round/{{ $round }}?{{ safeUrl $root.DiffOpts.Encode }}#round-#{{ $round }}"> 298 {{ i "diff" "w-4 h-4" }} 299 diff 300 </a>
··· 8 9 {{ define "mainLayout" }} 10 <div class="px-1 flex-grow flex flex-col gap-4"> 11 + <div class="max-w-screen-lg mx-auto"> 12 {{ block "contentLayout" . }} 13 {{ block "content" . }}{{ end }} 14 {{ end }} ··· 51 {{ end }} 52 53 {{ define "repoContentLayout" }} 54 + <div class="grid grid-cols-1 md:grid-cols-10 gap-4"> 55 <section class="bg-white col-span-1 md:col-span-8 dark:bg-gray-800 p-6 rounded relative w-full mx-auto dark:text-white h-full flex-shrink"> 56 {{ block "repoContent" . }}{{ end }} 57 </section> ··· 246 {{ $lastIdx := index . 2 }} 247 {{ $root := index . 3 }} 248 {{ $round := $item.RoundNumber }} 249 + <div class="{{ if eq $round 0 }}rounded-b{{ else }}rounded{{ end }} px-6 py-4 pr-2 pt-2 {{ if eq $root.ActiveRound $round }}bg-blue-100 dark:bg-blue-900/50 border-b border-blue-200 dark:border-blue-700{{ else }}bg-white dark:bg-gray-800 border-b border-gray-200 dark:border-gray-700{{ end }} flex gap-2 sticky top-0 z-20"> 250 <!-- left column: just profile picture --> 251 <div class="flex-shrink-0 pt-2"> 252 <img ··· 286 <div class="flex gap-2 items-center"> 287 {{ if ne $root.ActiveRound $round }} 288 <a class="btn-flat flex items-center gap-2 no-underline hover:no-underline text-sm" 289 + href="/{{ $root.RepoInfo.FullName }}/pulls/{{ $root.Pull.PullId }}/round/{{ $round }}?{{ safeUrl $root.DiffOpts.Encode }}"> 290 {{ i "diff" "w-4 h-4" }} 291 diff 292 </a>
+1 -1
appview/pulls/opengraph.go
··· 199 currentX += commentTextWidth + 40 200 201 // Draw files changed 202 - err = statusStatsArea.DrawLucideIcon("file-diff", currentX, statsY+iconBaselineOffset-iconSize/2+5, iconSize, iconColor) 203 if err != nil { 204 log.Printf("failed to draw file diff icon: %v", err) 205 }
··· 199 currentX += commentTextWidth + 40 200 201 // Draw files changed 202 + err = statusStatsArea.DrawLucideIcon("static/icons/file-diff", currentX, statsY+iconBaselineOffset-iconSize/2+5, iconSize, iconColor) 203 if err != nil { 204 log.Printf("failed to draw file diff icon: %v", err) 205 }
+1 -1
appview/pulls/pulls.go
··· 228 reactionMap, err := db.GetReactionMap(s.db, 20, pull.AtUri()) 229 if err != nil { 230 log.Println("failed to get pull reactions") 231 } 232 233 userReactions := map[models.ReactionKind]bool{} ··· 1874 record := pull.AsRecord() 1875 record.PatchBlob = blob.Blob 1876 record.CreatedAt = time.Now().Format(time.RFC3339) 1877 - record.Source.Sha = newSourceRev 1878 1879 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1880 Collection: tangled.RepoPullNSID,
··· 228 reactionMap, err := db.GetReactionMap(s.db, 20, pull.AtUri()) 229 if err != nil { 230 log.Println("failed to get pull reactions") 231 + s.pages.Notice(w, "pulls", "Failed to load pull. Try again later.") 232 } 233 234 userReactions := map[models.ReactionKind]bool{} ··· 1875 record := pull.AsRecord() 1876 record.PatchBlob = blob.Blob 1877 record.CreatedAt = time.Now().Format(time.RFC3339) 1878 1879 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 1880 Collection: tangled.RepoPullNSID,
+19 -64
appview/repo/archive.go
··· 2 3 import ( 4 "fmt" 5 - "io" 6 "net/http" 7 "net/url" 8 "strings" 9 10 "github.com/go-chi/chi/v5" 11 ) 12 13 func (rp *Repo) DownloadArchive(w http.ResponseWriter, r *http.Request) { ··· 25 scheme = "https" 26 } 27 host := fmt.Sprintf("%s://%s", scheme, f.Knot) 28 didSlashRepo := f.DidSlashRepo() 29 - 30 - // build the xrpc url 31 - u, err := url.Parse(host) 32 - if err != nil { 33 - l.Error("failed to parse host URL", "err", err) 34 rp.pages.Error503(w) 35 return 36 } 37 - 38 - u.Path = "/xrpc/sh.tangled.repo.archive" 39 - query := url.Values{} 40 - query.Set("format", "tar.gz") 41 - query.Set("prefix", r.URL.Query().Get("prefix")) 42 - query.Set("ref", ref) 43 - query.Set("repo", didSlashRepo) 44 - u.RawQuery = query.Encode() 45 - 46 - xrpcURL := u.String() 47 - 48 - // make the get request 49 - resp, err := http.Get(xrpcURL) 50 - if err != nil { 51 - l.Error("failed to call XRPC repo.archive", "err", err) 52 - rp.pages.Error503(w) 53 - return 54 - } 55 - 56 - // pass through headers from upstream response 57 - if contentDisposition := resp.Header.Get("Content-Disposition"); contentDisposition != "" { 58 - w.Header().Set("Content-Disposition", contentDisposition) 59 - } 60 - if contentType := resp.Header.Get("Content-Type"); contentType != "" { 61 - w.Header().Set("Content-Type", contentType) 62 - } 63 - if contentLength := resp.Header.Get("Content-Length"); contentLength != "" { 64 - w.Header().Set("Content-Length", contentLength) 65 - } 66 - if link := resp.Header.Get("Link"); link != "" { 67 - if resolvedRef, err := extractImmutableLink(link); err == nil { 68 - newLink := fmt.Sprintf("<%s/%s/archive/%s.tar.gz>; rel=\"immutable\"", 69 - rp.config.Core.AppviewHost, f.DidSlashRepo(), resolvedRef) 70 - w.Header().Set("Link", newLink) 71 - } 72 - } 73 - 74 - // stream the archive data directly 75 - if _, err := io.Copy(w, resp.Body); err != nil { 76 - l.Error("failed to write response", "err", err) 77 - } 78 - } 79 - 80 - func extractImmutableLink(linkHeader string) (string, error) { 81 - trimmed := strings.TrimPrefix(linkHeader, "<") 82 - trimmed = strings.TrimSuffix(trimmed, ">; rel=\"immutable\"") 83 - 84 - parsedLink, err := url.Parse(trimmed) 85 - if err != nil { 86 - return "", err 87 - } 88 - 89 - resolvedRef := parsedLink.Query().Get("ref") 90 - if resolvedRef == "" { 91 - return "", fmt.Errorf("no ref found in link header") 92 - } 93 - 94 - return resolvedRef, nil 95 }
··· 2 3 import ( 4 "fmt" 5 "net/http" 6 "net/url" 7 "strings" 8 9 + "tangled.org/core/api/tangled" 10 + xrpcclient "tangled.org/core/appview/xrpcclient" 11 + 12 + indigoxrpc "github.com/bluesky-social/indigo/xrpc" 13 "github.com/go-chi/chi/v5" 14 + "github.com/go-git/go-git/v5/plumbing" 15 ) 16 17 func (rp *Repo) DownloadArchive(w http.ResponseWriter, r *http.Request) { ··· 29 scheme = "https" 30 } 31 host := fmt.Sprintf("%s://%s", scheme, f.Knot) 32 + xrpcc := &indigoxrpc.Client{ 33 + Host: host, 34 + } 35 didSlashRepo := f.DidSlashRepo() 36 + archiveBytes, err := tangled.RepoArchive(r.Context(), xrpcc, "tar.gz", "", ref, didSlashRepo) 37 + if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil { 38 + l.Error("failed to call XRPC repo.archive", "err", xrpcerr) 39 rp.pages.Error503(w) 40 return 41 } 42 + // Set headers for file download, just pass along whatever the knot specifies 43 + safeRefFilename := strings.ReplaceAll(plumbing.ReferenceName(ref).Short(), "/", "-") 44 + filename := fmt.Sprintf("%s-%s.tar.gz", f.Name, safeRefFilename) 45 + w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename)) 46 + w.Header().Set("Content-Type", "application/gzip") 47 + w.Header().Set("Content-Length", fmt.Sprintf("%d", len(archiveBytes))) 48 + // Write the archive data directly 49 + w.Write(archiveBytes) 50 }
-33
docs/DOCS.md
··· 693 MY_ENV_VAR: "MY_ENV_VALUE" 694 ``` 695 696 - By default, the following environment variables set: 697 - 698 - - `CI` - Always set to `true` to indicate a CI environment 699 - - `TANGLED_PIPELINE_ID` - The AT URI of the current pipeline 700 - - `TANGLED_REPO_KNOT` - The repository's knot hostname 701 - - `TANGLED_REPO_DID` - The DID of the repository owner 702 - - `TANGLED_REPO_NAME` - The name of the repository 703 - - `TANGLED_REPO_DEFAULT_BRANCH` - The default branch of the 704 - repository 705 - - `TANGLED_REPO_URL` - The full URL to the repository 706 - 707 - These variables are only available when the pipeline is 708 - triggered by a push: 709 - 710 - - `TANGLED_REF` - The full git reference (e.g., 711 - `refs/heads/main` or `refs/tags/v1.0.0`) 712 - - `TANGLED_REF_NAME` - The short name of the reference 713 - (e.g., `main` or `v1.0.0`) 714 - - `TANGLED_REF_TYPE` - The type of reference, either 715 - `branch` or `tag` 716 - - `TANGLED_SHA` - The commit SHA that triggered the pipeline 717 - - `TANGLED_COMMIT_SHA` - Alias for `TANGLED_SHA` 718 - 719 - These variables are only available when the pipeline is 720 - triggered by a pull request: 721 - 722 - - `TANGLED_PR_SOURCE_BRANCH` - The source branch of the pull 723 - request 724 - - `TANGLED_PR_TARGET_BRANCH` - The target branch of the pull 725 - request 726 - - `TANGLED_PR_SOURCE_SHA` - The commit SHA of the source 727 - branch 728 - 729 ### Steps 730 731 The `steps` field allows you to define what steps should run
··· 693 MY_ENV_VAR: "MY_ENV_VALUE" 694 ``` 695 696 ### Steps 697 698 The `steps` field allows you to define what steps should run
-4
knotserver/git/git.go
··· 76 return &g, nil 77 } 78 79 - func (g *GitRepo) Hash() plumbing.Hash { 80 - return g.h 81 - } 82 - 83 // re-open a repository and update references 84 func (g *GitRepo) Refresh() error { 85 refreshed, err := PlainOpen(g.path)
··· 76 return &g, nil 77 } 78 79 // re-open a repository and update references 80 func (g *GitRepo) Refresh() error { 81 refreshed, err := PlainOpen(g.path)
-35
knotserver/xrpc/repo_archive.go
··· 4 "compress/gzip" 5 "fmt" 6 "net/http" 7 - "net/url" 8 "strings" 9 10 "github.com/go-git/go-git/v5/plumbing" 11 12 - "tangled.org/core/api/tangled" 13 "tangled.org/core/knotserver/git" 14 xrpcerr "tangled.org/core/xrpc/errors" 15 ) ··· 49 repoParts := strings.Split(repo, "/") 50 repoName := repoParts[len(repoParts)-1] 51 52 - immutableLink, err := x.buildImmutableLink(repo, format, gr.Hash().String(), prefix) 53 - if err != nil { 54 - x.Logger.Error( 55 - "failed to build immutable link", 56 - "err", err.Error(), 57 - "repo", repo, 58 - "format", format, 59 - "ref", gr.Hash().String(), 60 - "prefix", prefix, 61 - ) 62 - } 63 - 64 safeRefFilename := strings.ReplaceAll(plumbing.ReferenceName(ref).Short(), "/", "-") 65 66 var archivePrefix string ··· 73 filename := fmt.Sprintf("%s-%s.tar.gz", repoName, safeRefFilename) 74 w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename)) 75 w.Header().Set("Content-Type", "application/gzip") 76 - w.Header().Set("Link", fmt.Sprintf("<%s>; rel=\"immutable\"", immutableLink)) 77 78 gw := gzip.NewWriter(w) 79 defer gw.Close() ··· 94 return 95 } 96 } 97 - 98 - func (x *Xrpc) buildImmutableLink(repo string, format string, ref string, prefix string) (string, error) { 99 - scheme := "https" 100 - if x.Config.Server.Dev { 101 - scheme = "http" 102 - } 103 - 104 - u, err := url.Parse(scheme + "://" + x.Config.Server.Hostname + "/xrpc/" + tangled.RepoArchiveNSID) 105 - if err != nil { 106 - return "", err 107 - } 108 - 109 - params := url.Values{} 110 - params.Set("repo", repo) 111 - params.Set("format", format) 112 - params.Set("ref", ref) 113 - params.Set("prefix", prefix) 114 - 115 - return fmt.Sprintf("%s?%s", u.String(), params.Encode()), nil 116 - }
··· 4 "compress/gzip" 5 "fmt" 6 "net/http" 7 "strings" 8 9 "github.com/go-git/go-git/v5/plumbing" 10 11 "tangled.org/core/knotserver/git" 12 xrpcerr "tangled.org/core/xrpc/errors" 13 ) ··· 47 repoParts := strings.Split(repo, "/") 48 repoName := repoParts[len(repoParts)-1] 49 50 safeRefFilename := strings.ReplaceAll(plumbing.ReferenceName(ref).Short(), "/", "-") 51 52 var archivePrefix string ··· 59 filename := fmt.Sprintf("%s-%s.tar.gz", repoName, safeRefFilename) 60 w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename)) 61 w.Header().Set("Content-Type", "application/gzip") 62 63 gw := gzip.NewWriter(w) 64 defer gw.Close() ··· 79 return 80 } 81 }

History

8 rounds 9 comments
sign up or login to add to the discussion
1 commit
expand
appview: allow default knot to be saved as a preference and then used when creating a new repo
no conflicts, ready to merge
expand 0 comments
1 commit
expand
appview: allow default knot to be saved as a preference and then used when creating a new repo
expand 0 comments
1 commit
expand
appview: allow default knot to be saved as a preference and then used when creating a new repo
expand 0 comments
1 commit
expand
appview: allows a default knot to be selected from knots available to the user
expand 5 comments

@oppi.li While attempting to implement something else related to profiles, I've noticed that UpsertProfile(...) herehttps://tangled.org/tangled.org/core/blob/master/appview/db/profile.go#L133 also gets called as part of a JS ingester here https://tangled.org/tangled.org/core/blob/master/appview/ingester.go#L352 which means the DefaultKnot field will be overwritten with an empty string when a profile event is ingested. Am I understanding that correctly?

So instead I should probably not use the UpsertProfile(...) but use a smaller scoped function that just sets the Default Knot field?

ah that is correct, the default knot will be overwritten by that call. i suppose that is one of the drawbacks of overloading models.Profile! instead of cloning UpsertProfile to add this as an exception, perhaps this is an indication that we need to avoid using the profile table/model for this. what do you think about creating a preferences table for stuff like this? we already have notification_preferences, we could do something similar for knots.

i see you have a PR open for punchcard work as well, which would fit quite well in a punchcard_preferences table.

Yh I'm 100% down for using that approach. While I was implementing the punchcard PR I had this nagging feeling in me that this and other things belonged in some sort of separate "preferences" table so splitting them out into things like knot_preferences or punchcard_preferences is the right answer for me.

I'll redo that for this PR and then do the same of the other PR and hopefully it will prevent the merge conflicts I was dreading ๐Ÿ™ˆ

yeah! knot_preferences and punchcard_preferences seems okay for now. thanks for keeping at this by the way, and sorry for the slow review cycle!

No worries! I don't expect immediate reviews ๐Ÿ˜

I've refactored to use a new knot_preferences table for this PR. I had some merge conflicts with master though, so rebased that although took me a couple attempts to get everything nice and neat, hence so many rounds ๐Ÿ™ˆ

2 commits
expand
appview: allows a default knot to be configured
appview: allows a default knot to be selected from knots available to the user
expand 0 comments
1 commit
expand
appview: allows a default knot to be configured
expand 2 comments

the code itself works pretty nicely now. so i've noticed a couple issues (apologies for not looking more closely earlier!):

  • the default-knot selector only iterates over knots that the user is an admin of, whereas they should be able to choose any knot that they are a member of as the default. you can use s.enforcer.GetKnotsForUser(...) to get a list of knots that a user has access to
  • the HTML change adds knot1.tangled.sh as an explicit case, this is not necessary if the above is implemented
  • the HTML template currently triggers a request when the select changes, could we make this more like how the spindle selector works? a form with a button to submit.

I was looking for ages trying to find somewhere that did something similar. I don't use spindles so never saw that ๐Ÿ™ˆ A much better approach.

Also good shout on the knots for a user. Reading the code now, I understand what the registrations are now.

Anyhow, I've updated the PR and squashed everything so it should be good to test now.

Please note, that I have yet to figure out how to get multiple Knots running locally, and since I don't get knot1.tangled.sh locally I had to hard code some things in to test it worked, which is less than ideal.

1 commit
expand
appview: allows a default knot to be configured
expand 0 comments
1 commit
expand
appview: allows a default knot to be configured
expand 2 comments

i get this error at runtime:

2026/01/20 04:58:12 profile err 5 values for 6 columns
2026/01/20 04:58:12 failed to update profile 5 values for 6 columns

this sql query is incorrect:

		`insert or replace into profile (
			did,
			description,
			include_bluesky,
			location,
			pronouns,
			default_knot
		)
		values (?, ?, ?, ?, ?)`,

there should be 6 ? placeholders!

Ah crap, someone needs to create a lint tool that detects that ๐Ÿคฆโ€โ™‚๏ธ

Fixed.