alpha
Login
or
Join now
tangled.org
/
core
Star
12
Fork
68
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Monorepo for Tangled
tangled.org
Star
12
Fork
68
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
16
Pulls
28
Pipelines
begin work on user/ pages
author
Akshay
date
1 year ago
(Feb 5, 2025, 1:59 PM UTC)
commit
95df0d12
95df0d129469a88bf0cba996f053cb9852d3dacf
parent
8cb05b36
8cb05b36579a44308d4431ae8c44673c9dc45502
+95
4 changed files
Expand all
Collapse all
Unified
Split
appview
pages
pages.go
profile.html
state
middleware.go
state.go
+11
appview/pages/pages.go
Reviewed
···
85
85
func NewRepo(w io.Writer, p NewRepoParams) error {
86
86
return parse("new-repo.html").Execute(w, p)
87
87
}
88
88
+
89
89
+
type ProfilePageParams struct {
90
90
+
LoggedInUser *auth.User
91
91
+
UserDid string
92
92
+
UserHandle string
93
93
+
Repos []db.Repo
94
94
+
}
95
95
+
96
96
+
func ProfilePage(w io.Writer, p ProfilePageParams) error {
97
97
+
return parse("profile.html").Execute(w, p)
98
98
+
}
+18
appview/pages/profile.html
Reviewed
···
1
1
+
{{define "title"}}{{ or .UserHandle .UserDid }}{{end}}
2
2
+
3
3
+
{{define "content"}}
4
4
+
<a href="/">back to timeline</a>
5
5
+
<h1>{{ or .UserHandle .UserDid }} profile</h1>
6
6
+
7
7
+
<h3>repos</h3>
8
8
+
<ul id="my-knots">
9
9
+
{{range .Repos}}
10
10
+
<li>
11
11
+
<code>name: {{.Name}}</code><br>
12
12
+
<code>knot: {{.Knot}}</code><br>
13
13
+
</li>
14
14
+
{{else}}
15
15
+
<p>you don't have any knots yet</p>
16
16
+
{{end}}
17
17
+
</ul>
18
18
+
{{end}}
+11
appview/state/middleware.go
Reviewed
···
3
3
import (
4
4
"log"
5
5
"net/http"
6
6
+
"strings"
6
7
"time"
7
8
8
9
comatproto "github.com/bluesky-social/indigo/api/atproto"
···
99
100
})
100
101
}
101
102
}
103
103
+
104
104
+
func StripLeadingAt(next http.Handler) http.Handler {
105
105
+
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
106
106
+
path := req.URL.Path
107
107
+
if strings.HasPrefix(path, "/@") {
108
108
+
req.URL.Path = "/" + strings.TrimPrefix(path, "/@")
109
109
+
}
110
110
+
next.ServeHTTP(w, req)
111
111
+
})
112
112
+
}
+55
appview/state/state.go
Reviewed
···
538
538
}
539
539
}
540
540
541
541
+
func (s *State) ProfilePage(w http.ResponseWriter, r *http.Request) {
542
542
+
didOrHandle := chi.URLParam(r, "user")
543
543
+
if didOrHandle == "" {
544
544
+
http.Error(w, "Bad request", http.StatusBadRequest)
545
545
+
return
546
546
+
}
547
547
+
548
548
+
ident, err := auth.ResolveIdent(r.Context(), didOrHandle)
549
549
+
if err != nil {
550
550
+
log.Printf("resolving identity: %s", err)
551
551
+
w.WriteHeader(http.StatusNotFound)
552
552
+
return
553
553
+
}
554
554
+
555
555
+
repos, err := s.db.GetAllReposByDid(ident.DID.String())
556
556
+
if err != nil {
557
557
+
log.Printf("getting repos for %s: %s", ident.DID.String(), err)
558
558
+
}
559
559
+
560
560
+
pages.ProfilePage(w, pages.ProfilePageParams{
561
561
+
LoggedInUser: s.auth.GetUser(r),
562
562
+
UserDid: ident.DID.String(),
563
563
+
UserHandle: ident.Handle.String(),
564
564
+
Repos: repos,
565
565
+
})
566
566
+
}
567
567
+
541
568
func (s *State) Router() http.Handler {
569
569
+
router := chi.NewRouter()
570
570
+
571
571
+
router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
572
572
+
pat := chi.URLParam(r, "*")
573
573
+
if strings.HasPrefix(pat, "did:") || strings.HasPrefix(pat, "@") {
574
574
+
s.UserRouter().ServeHTTP(w, r)
575
575
+
} else {
576
576
+
s.StandardRouter().ServeHTTP(w, r)
577
577
+
}
578
578
+
})
579
579
+
580
580
+
return router
581
581
+
}
582
582
+
583
583
+
func (s *State) UserRouter() http.Handler {
584
584
+
r := chi.NewRouter()
585
585
+
586
586
+
// strip @ from user
587
587
+
r.Use(StripLeadingAt)
588
588
+
589
589
+
r.Route("/{user}", func(r chi.Router) {
590
590
+
r.Get("/", s.ProfilePage)
591
591
+
})
592
592
+
593
593
+
return r
594
594
+
}
595
595
+
596
596
+
func (s *State) StandardRouter() http.Handler {
542
597
r := chi.NewRouter()
543
598
544
599
r.Get("/", s.Timeline)