This repository has no description
1package pages
2
3import (
4 "crypto/sha256"
5 "embed"
6 "encoding/hex"
7 "fmt"
8 "html/template"
9 "io"
10 "io/fs"
11 "log/slog"
12 "net/http"
13 "os"
14 "path/filepath"
15 "strings"
16 "sync"
17 "time"
18
19 "tangled.org/core/api/tangled"
20 "tangled.org/core/appview/cache"
21 "tangled.org/core/appview/commitverify"
22 "tangled.org/core/appview/config"
23 "tangled.org/core/appview/db"
24 "tangled.org/core/appview/models"
25 "tangled.org/core/appview/oauth"
26 "tangled.org/core/appview/pages/markup"
27 "tangled.org/core/appview/pages/repoinfo"
28 "tangled.org/core/appview/pagination"
29 "tangled.org/core/idresolver"
30 "tangled.org/core/patchutil"
31 "tangled.org/core/types"
32
33 "github.com/bluesky-social/indigo/atproto/identity"
34 "github.com/bluesky-social/indigo/atproto/syntax"
35 "github.com/go-git/go-git/v5/plumbing"
36)
37
38//go:embed templates/* static legal
39var Files embed.FS
40
41type Pages struct {
42 mu sync.RWMutex
43 cache *TmplCache[string, *template.Template]
44
45 avatar config.AvatarConfig
46 pdsCfg config.PdsConfig
47 resolver *idresolver.Resolver
48 db *db.DB
49 rdb *cache.Cache
50 dev bool
51 embedFS fs.FS
52 templateDir string // Path to templates on disk for dev mode
53 rctx *markup.RenderContext
54 logger *slog.Logger
55}
56
57func NewPages(config *config.Config, res *idresolver.Resolver, database *db.DB, rdb *cache.Cache, logger *slog.Logger) *Pages {
58 // initialized with safe defaults, can be overridden per use
59 rctx := &markup.RenderContext{
60 IsDev: config.Core.Dev,
61 Hostname: config.Core.AppviewHost,
62 CamoUrl: config.Camo.Host,
63 CamoSecret: config.Camo.SharedSecret,
64 Sanitizer: markup.NewSanitizer(),
65 Files: Files,
66 }
67
68 p := &Pages{
69 mu: sync.RWMutex{},
70 cache: NewTmplCache[string, *template.Template](),
71 dev: config.Core.Dev,
72 avatar: config.Avatar,
73 pdsCfg: config.Pds,
74 rctx: rctx,
75 resolver: res,
76 db: database,
77 rdb: rdb,
78 templateDir: "appview/pages",
79 logger: logger,
80 }
81
82 if p.dev {
83 p.embedFS = os.DirFS(p.templateDir)
84 } else {
85 p.embedFS = Files
86 }
87
88 return p
89}
90
91// reverse of pathToName
92func (p *Pages) nameToPath(s string) string {
93 return "templates/" + s + ".html"
94}
95
96// FuncMap returns the template function map for use by external template consumers.
97func (p *Pages) FuncMap() template.FuncMap {
98 return p.funcMap()
99}
100
101// FragmentPaths returns all fragment template paths from the embedded FS.
102func (p *Pages) FragmentPaths() ([]string, error) {
103 return p.fragmentPaths()
104}
105
106// EmbedFS returns the embedded filesystem containing templates and static assets.
107func (p *Pages) EmbedFS() fs.FS {
108 return p.embedFS
109}
110
111// ParseWith parses the base layout together with all appview fragments and
112// an additional template from extraFS identified by extraPath (relative to
113// extraFS root). The returned template is ready to ExecuteTemplate with
114// "layouts/base" -- primarily for use with the blog.
115func (p *Pages) ParseWith(extraFS fs.FS, extraPath string) (*template.Template, error) {
116 fragmentPaths, err := p.fragmentPaths()
117 if err != nil {
118 return nil, err
119 }
120
121 funcs := p.funcMap()
122 tpl, err := template.New("layouts/base").
123 Funcs(funcs).
124 ParseFS(p.embedFS, append(fragmentPaths, p.nameToPath("layouts/base"))...)
125 if err != nil {
126 return nil, err
127 }
128
129 err = fs.WalkDir(extraFS, ".", func(path string, d fs.DirEntry, err error) error {
130 if err != nil {
131 return err
132 }
133 if d.IsDir() || !strings.HasSuffix(path, ".html") {
134 return nil
135 }
136 if path != extraPath && !strings.Contains(path, "fragments/") {
137 return nil
138 }
139 data, err := fs.ReadFile(extraFS, path)
140 if err != nil {
141 return err
142 }
143 if _, err = tpl.New(path).Parse(string(data)); err != nil {
144 return err
145 }
146 return nil
147 })
148 if err != nil {
149 return nil, err
150 }
151
152 return tpl, nil
153}
154
155func (p *Pages) fragmentPaths() ([]string, error) {
156 var fragmentPaths []string
157 err := fs.WalkDir(p.embedFS, "templates", func(path string, d fs.DirEntry, err error) error {
158 if err != nil {
159 return err
160 }
161 if d.IsDir() {
162 return nil
163 }
164 if !strings.HasSuffix(path, ".html") {
165 return nil
166 }
167 if !strings.Contains(path, "fragments/") {
168 return nil
169 }
170 fragmentPaths = append(fragmentPaths, path)
171 return nil
172 })
173 if err != nil {
174 return nil, err
175 }
176
177 return fragmentPaths, nil
178}
179
180// parse without memoization
181func (p *Pages) rawParse(stack ...string) (*template.Template, error) {
182 paths, err := p.fragmentPaths()
183 if err != nil {
184 return nil, err
185 }
186 for _, s := range stack {
187 paths = append(paths, p.nameToPath(s))
188 }
189
190 funcs := p.funcMap()
191 top := stack[len(stack)-1]
192 parsed, err := template.New(top).
193 Funcs(funcs).
194 ParseFS(p.embedFS, paths...)
195 if err != nil {
196 return nil, err
197 }
198
199 return parsed, nil
200}
201
202func (p *Pages) parse(stack ...string) (*template.Template, error) {
203 key := strings.Join(stack, "|")
204
205 // never cache in dev mode
206 if cached, exists := p.cache.Get(key); !p.dev && exists {
207 return cached, nil
208 }
209
210 result, err := p.rawParse(stack...)
211 if err != nil {
212 return nil, err
213 }
214
215 p.cache.Set(key, result)
216 return result, nil
217}
218
219func (p *Pages) parseBase(top string) (*template.Template, error) {
220 stack := []string{
221 "layouts/base",
222 top,
223 }
224 return p.parse(stack...)
225}
226
227func (p *Pages) parseRepoBase(top string) (*template.Template, error) {
228 stack := []string{
229 "layouts/base",
230 "layouts/repobase",
231 top,
232 }
233 return p.parse(stack...)
234}
235
236func (p *Pages) parseProfileBase(top string) (*template.Template, error) {
237 stack := []string{
238 "layouts/base",
239 "layouts/profilebase",
240 top,
241 }
242 return p.parse(stack...)
243}
244
245func (p *Pages) parseLoginBase(top string) (*template.Template, error) {
246 stack := []string{
247 "layouts/base",
248 "layouts/loginbase",
249 top,
250 }
251 return p.parse(stack...)
252}
253
254func (p *Pages) executePlain(name string, w io.Writer, params any) error {
255 tpl, err := p.parse(name)
256 if err != nil {
257 return err
258 }
259
260 return tpl.Execute(w, params)
261}
262
263func (p *Pages) executeLogin(name string, w io.Writer, params any) error {
264 tpl, err := p.parseLoginBase(name)
265 if err != nil {
266 return err
267 }
268
269 return tpl.ExecuteTemplate(w, "layouts/base", params)
270}
271
272func (p *Pages) execute(name string, w io.Writer, params any) error {
273 tpl, err := p.parseBase(name)
274 if err != nil {
275 return err
276 }
277
278 return tpl.ExecuteTemplate(w, "layouts/base", params)
279}
280
281func (p *Pages) executeRepo(name string, w io.Writer, params any) error {
282 tpl, err := p.parseRepoBase(name)
283 if err != nil {
284 return err
285 }
286
287 return tpl.ExecuteTemplate(w, "layouts/base", params)
288}
289
290func (p *Pages) executeProfile(name string, w io.Writer, params any) error {
291 tpl, err := p.parseProfileBase(name)
292 if err != nil {
293 return err
294 }
295
296 return tpl.ExecuteTemplate(w, "layouts/base", params)
297}
298
299type DollyParams struct {
300 Classes string
301 FillColor string
302}
303
304func (p *Pages) Dolly(w io.Writer, params DollyParams) error {
305 return p.executePlain("fragments/dolly/logo", w, params)
306}
307
308func (p *Pages) Favicon(w io.Writer) error {
309 return p.Dolly(w, DollyParams{
310 Classes: "text-black dark:text-white",
311 })
312}
313
314type LoginParams struct {
315 ReturnUrl string
316 ErrorCode string
317 AddAccount bool
318 Accounts []oauth.AccountInfo
319}
320
321func (p *Pages) Login(w io.Writer, params LoginParams) error {
322 return p.executeLogin("user/login", w, params)
323}
324
325type SignupParams struct {
326 CloudflareSiteKey string
327 EmailId string
328}
329
330func (p *Pages) Signup(w io.Writer, params SignupParams) error {
331 return p.executeLogin("user/signup", w, params)
332}
333
334func (p *Pages) CompleteSignup(w io.Writer) error {
335 return p.executeLogin("user/completeSignup", w, nil)
336}
337
338type TermsOfServiceParams struct {
339 LoggedInUser *oauth.MultiAccountUser
340 Content template.HTML
341}
342
343func (p *Pages) TermsOfService(w io.Writer, params TermsOfServiceParams) error {
344 filename := "terms.md"
345 filePath := filepath.Join("legal", filename)
346
347 file, err := p.embedFS.Open(filePath)
348 if err != nil {
349 return fmt.Errorf("failed to read %s: %w", filename, err)
350 }
351 defer file.Close()
352
353 markdownBytes, err := io.ReadAll(file)
354 if err != nil {
355 return fmt.Errorf("failed to read %s: %w", filename, err)
356 }
357
358 rctx := p.rctx.Clone()
359 rctx.RendererType = markup.RendererTypeDefault
360 htmlString := rctx.RenderMarkdown(string(markdownBytes))
361 sanitized := rctx.SanitizeDefault(htmlString)
362 params.Content = template.HTML(sanitized)
363
364 return p.execute("legal/terms", w, params)
365}
366
367type PrivacyPolicyParams struct {
368 LoggedInUser *oauth.MultiAccountUser
369 Content template.HTML
370}
371
372func (p *Pages) PrivacyPolicy(w io.Writer, params PrivacyPolicyParams) error {
373 filename := "privacy.md"
374 filePath := filepath.Join("legal", filename)
375
376 file, err := p.embedFS.Open(filePath)
377 if err != nil {
378 return fmt.Errorf("failed to read %s: %w", filename, err)
379 }
380 defer file.Close()
381
382 markdownBytes, err := io.ReadAll(file)
383 if err != nil {
384 return fmt.Errorf("failed to read %s: %w", filename, err)
385 }
386
387 rctx := p.rctx.Clone()
388 rctx.RendererType = markup.RendererTypeDefault
389 htmlString := rctx.RenderMarkdown(string(markdownBytes))
390 sanitized := rctx.SanitizeDefault(htmlString)
391 params.Content = template.HTML(sanitized)
392
393 return p.execute("legal/privacy", w, params)
394}
395
396type BrandParams struct {
397 LoggedInUser *oauth.MultiAccountUser
398}
399
400func (p *Pages) Brand(w io.Writer, params BrandParams) error {
401 return p.execute("brand/brand", w, params)
402}
403
404type TimelineParams struct {
405 LoggedInUser *oauth.MultiAccountUser
406 Timeline []models.TimelineGroup
407 Repos []models.Repo
408 GfiLabel *models.LabelDefinition
409 BlueskyPosts []models.BskyPost
410 VouchSuggestions []models.VouchSuggestion
411 // ShowNewsletter controls whether the newsletter widget/CTA is rendered.
412 // For logged-in users it reflects their newsletter_preferences row; for
413 // anonymous visitors it is always true (dismissal falls back to
414 // localStorage on the client).
415 ShowNewsletter bool
416}
417
418func (p *Pages) Timeline(w io.Writer, params TimelineParams) error {
419 return p.execute("timeline/timeline", w, params)
420}
421
422type GoodFirstIssuesParams struct {
423 LoggedInUser *oauth.MultiAccountUser
424 Issues []models.Issue
425 RepoGroups []*models.RepoGroup
426 LabelDefs map[string]*models.LabelDefinition
427 GfiLabel *models.LabelDefinition
428 Page pagination.Page
429}
430
431func (p *Pages) GoodFirstIssues(w io.Writer, params GoodFirstIssuesParams) error {
432 return p.execute("goodfirstissues/index", w, params)
433}
434
435type UserProfileSettingsParams struct {
436 LoggedInUser *oauth.MultiAccountUser
437 Tab string
438 PunchcardPreference models.PunchcardPreference
439 IsTnglSh bool
440 IsDeactivated bool
441 HandleOpen bool
442}
443
444func (p *Pages) UserProfileSettings(w io.Writer, params UserProfileSettingsParams) error {
445 params.Tab = "profile"
446 return p.execute("user/settings/profile", w, params)
447}
448
449type NotificationsParams struct {
450 LoggedInUser *oauth.MultiAccountUser
451 Notifications []*models.NotificationWithEntity
452 UnreadCount int
453 Page pagination.Page
454 Total int64
455}
456
457func (p *Pages) Notifications(w io.Writer, params NotificationsParams) error {
458 return p.execute("notifications/list", w, params)
459}
460
461type NotificationItemParams struct {
462 Notification *models.Notification
463}
464
465func (p *Pages) NotificationItem(w io.Writer, params NotificationItemParams) error {
466 return p.executePlain("notifications/fragments/item", w, params)
467}
468
469type NotificationCountParams struct {
470 Count int64
471}
472
473func (p *Pages) NotificationCount(w io.Writer, params NotificationCountParams) error {
474 return p.executePlain("notifications/fragments/count", w, params)
475}
476
477type UserKeysSettingsParams struct {
478 LoggedInUser *oauth.MultiAccountUser
479 PubKeys []models.PublicKey
480 Tab string
481}
482
483func (p *Pages) UserKeysSettings(w io.Writer, params UserKeysSettingsParams) error {
484 params.Tab = "keys"
485 return p.execute("user/settings/keys", w, params)
486}
487
488type UserEmailsSettingsParams struct {
489 LoggedInUser *oauth.MultiAccountUser
490 Emails []models.Email
491 Tab string
492}
493
494func (p *Pages) UserEmailsSettings(w io.Writer, params UserEmailsSettingsParams) error {
495 params.Tab = "emails"
496 return p.execute("user/settings/emails", w, params)
497}
498
499type UserNotificationSettingsParams struct {
500 LoggedInUser *oauth.MultiAccountUser
501 Preferences *models.NotificationPreferences
502 Tab string
503}
504
505func (p *Pages) UserNotificationSettings(w io.Writer, params UserNotificationSettingsParams) error {
506 params.Tab = "notifications"
507 return p.execute("user/settings/notifications", w, params)
508}
509
510type UserSiteSettingsParams struct {
511 LoggedInUser *oauth.MultiAccountUser
512 Claim *models.DomainClaim
513 SitesDomain string
514 IsTnglHandle bool
515 Tab string
516}
517
518func (p *Pages) UserSiteSettings(w io.Writer, params UserSiteSettingsParams) error {
519 params.Tab = "sites"
520 return p.execute("user/settings/sites", w, params)
521}
522
523type UpgradeBannerParams struct {
524 Registrations []models.Registration
525 Spindles []models.Spindle
526}
527
528func (p *Pages) UpgradeBanner(w io.Writer, params UpgradeBannerParams) error {
529 return p.executePlain("banner", w, params)
530}
531
532type NewsletterResponseParams struct {
533 // Id identifies the calling form instance; the response span's id will
534 // be "newsletter-msg-<Id>" so it round-trips with the form's hx-target.
535 Id string
536 // Error, when non-empty, switches the template to the error variant.
537 Error string
538}
539
540func (p *Pages) NewsletterResponse(w io.Writer, params NewsletterResponseParams) error {
541 return p.executePlain("timeline/fragments/newsletterResponse", w, params)
542}
543
544type KnotsParams struct {
545 LoggedInUser *oauth.MultiAccountUser
546 Registrations []models.Registration
547 Tab string
548}
549
550func (p *Pages) Knots(w io.Writer, params KnotsParams) error {
551 params.Tab = "knots"
552 return p.execute("knots/index", w, params)
553}
554
555type KnotParams struct {
556 LoggedInUser *oauth.MultiAccountUser
557 Registration *models.Registration
558 Members []string
559 Repos map[string][]models.Repo
560 IsOwner bool
561 Tab string
562}
563
564func (p *Pages) Knot(w io.Writer, params KnotParams) error {
565 return p.execute("knots/dashboard", w, params)
566}
567
568type KnotListingParams struct {
569 *models.Registration
570}
571
572func (p *Pages) KnotListing(w io.Writer, params KnotListingParams) error {
573 return p.executePlain("knots/fragments/knotListing", w, params)
574}
575
576type SpindlesParams struct {
577 LoggedInUser *oauth.MultiAccountUser
578 Spindles []models.Spindle
579 Tab string
580}
581
582func (p *Pages) Spindles(w io.Writer, params SpindlesParams) error {
583 params.Tab = "spindles"
584 return p.execute("spindles/index", w, params)
585}
586
587type SpindleListingParams struct {
588 models.Spindle
589 Tab string
590}
591
592func (p *Pages) SpindleListing(w io.Writer, params SpindleListingParams) error {
593 return p.executePlain("spindles/fragments/spindleListing", w, params)
594}
595
596type SpindleDashboardParams struct {
597 LoggedInUser *oauth.MultiAccountUser
598 Spindle models.Spindle
599 Members []string
600 Repos map[string][]models.Repo
601 Tab string
602}
603
604func (p *Pages) SpindleDashboard(w io.Writer, params SpindleDashboardParams) error {
605 return p.execute("spindles/dashboard", w, params)
606}
607
608type NewRepoParams struct {
609 LoggedInUser *oauth.MultiAccountUser
610 Knots []string
611}
612
613func (p *Pages) NewRepo(w io.Writer, params NewRepoParams) error {
614 return p.execute("repo/new", w, params)
615}
616
617type ForkRepoParams struct {
618 LoggedInUser *oauth.MultiAccountUser
619 Knots []string
620 RepoInfo repoinfo.RepoInfo
621}
622
623func (p *Pages) ForkRepo(w io.Writer, params ForkRepoParams) error {
624 return p.execute("repo/fork", w, params)
625}
626
627type ProfileCard struct {
628 UserDid string
629 HasProfile bool
630 FollowStatus models.FollowStatus
631 VouchRelationship *models.VouchRelationship
632 Punchcard *models.Punchcard
633 Profile *models.Profile
634 Stats ProfileStats
635 Active string
636}
637
638type ProfileStats struct {
639 RepoCount int64
640 StarredCount int64
641 StringCount int64
642 FollowersCount int64
643 FollowingCount int64
644}
645
646func (p *ProfileCard) GetTabs() [][]any {
647 tabs := [][]any{
648 {"overview", "overview", "square-chart-gantt", nil},
649 {"repos", "repos", "book-marked", p.Stats.RepoCount},
650 {"starred", "starred", "star", p.Stats.StarredCount},
651 {"strings", "strings", "line-squiggle", p.Stats.StringCount},
652 {"vouches", "vouches", "shield", nil},
653 }
654
655 return tabs
656}
657
658type ProfileOverviewParams struct {
659 LoggedInUser *oauth.MultiAccountUser
660 Repos []models.Repo
661 CollaboratingRepos []models.Repo
662 ProfileTimeline *models.ProfileTimeline
663 Card *ProfileCard
664 Active string
665 ShowPunchcard bool
666}
667
668func (p *Pages) ProfileOverview(w io.Writer, params ProfileOverviewParams) error {
669 params.Active = "overview"
670 return p.executeProfile("user/overview", w, params)
671}
672
673type ProfileReposParams struct {
674 LoggedInUser *oauth.MultiAccountUser
675 Repos []models.Repo
676 Card *ProfileCard
677 Active string
678 Page pagination.Page
679 RepoCount int
680 FilterQuery string
681}
682
683func (p *Pages) ProfileRepos(w io.Writer, params ProfileReposParams) error {
684 params.Active = "repos"
685 return p.executeProfile("user/repos", w, params)
686}
687
688type ProfileStarredParams struct {
689 LoggedInUser *oauth.MultiAccountUser
690 Repos []models.Repo
691 Card *ProfileCard
692 Page pagination.Page
693 Total int
694 Active string
695}
696
697func (p *Pages) ProfileStarred(w io.Writer, params ProfileStarredParams) error {
698 params.Active = "starred"
699 return p.executeProfile("user/starred", w, params)
700}
701
702type ProfileStringsParams struct {
703 LoggedInUser *oauth.MultiAccountUser
704 Strings []models.String
705 Card *ProfileCard
706 Active string
707}
708
709func (p *Pages) ProfileStrings(w io.Writer, params ProfileStringsParams) error {
710 params.Active = "strings"
711 return p.executeProfile("user/strings", w, params)
712}
713
714type ProfileVouchesParams struct {
715 LoggedInUser *oauth.MultiAccountUser
716 Vouches []models.Vouch
717 Suggestions []models.VouchSuggestion
718 Card *ProfileCard
719 Page pagination.Page
720 Active string
721}
722
723func (p *Pages) ProfileVouches(w io.Writer, params ProfileVouchesParams) error {
724 params.Active = "vouches"
725 return p.executeProfile("user/vouches", w, params)
726}
727
728type FollowCard struct {
729 UserDid string
730 LoggedInUser *oauth.MultiAccountUser
731 FollowStatus models.FollowStatus
732 FollowersCount int64
733 FollowingCount int64
734 Profile *models.Profile
735}
736
737type ProfileFollowersParams struct {
738 LoggedInUser *oauth.MultiAccountUser
739 Followers []FollowCard
740 Card *ProfileCard
741 Active string
742}
743
744func (p *Pages) ProfileFollowers(w io.Writer, params ProfileFollowersParams) error {
745 params.Active = "overview"
746 return p.executeProfile("user/followers", w, params)
747}
748
749type ProfileFollowingParams struct {
750 LoggedInUser *oauth.MultiAccountUser
751 Following []FollowCard
752 Card *ProfileCard
753 Active string
754}
755
756func (p *Pages) ProfileFollowing(w io.Writer, params ProfileFollowingParams) error {
757 params.Active = "overview"
758 return p.executeProfile("user/following", w, params)
759}
760
761type FollowFragmentParams struct {
762 UserDid string
763 FollowStatus models.FollowStatus
764 FollowersCount int64
765}
766
767func (p *Pages) FollowFragment(w io.Writer, params FollowFragmentParams) error {
768 return p.executePlain("user/fragments/follow-oob", w, params)
769}
770
771type ProfilePopoverParams struct {
772 LoggedInUser *oauth.MultiAccountUser
773 UserDid string
774 Profile *models.Profile
775 FollowStatus models.FollowStatus
776 VouchRelationship *models.VouchRelationship
777 Stats ProfilePopoverStats
778}
779
780type ProfilePopoverStats struct {
781 FollowersCount int64
782 FollowingCount int64
783}
784
785func (p *Pages) ProfilePopoverFragment(w io.Writer, params ProfilePopoverParams) error {
786 return p.executePlain("user/fragments/profilePopover", w, params)
787}
788
789type EditBioParams struct {
790 LoggedInUser *oauth.MultiAccountUser
791 Profile *models.Profile
792 AlsoKnownAs []string
793}
794
795func (p *Pages) EditBioFragment(w io.Writer, params EditBioParams) error {
796 return p.executePlain("user/fragments/editBio", w, params)
797}
798
799type EditPinsParams struct {
800 LoggedInUser *oauth.MultiAccountUser
801 Profile *models.Profile
802 AllRepos []PinnedRepo
803}
804
805type PinnedRepo struct {
806 IsPinned bool
807 models.Repo
808}
809
810func (p *Pages) EditPinsFragment(w io.Writer, params EditPinsParams) error {
811 return p.executePlain("user/fragments/editPins", w, params)
812}
813
814type StarBtnFragmentParams struct {
815 IsStarred bool
816 SubjectAt syntax.ATURI
817 StarCount int
818 RepoName string
819 HxSwapOob bool
820}
821
822func (p *Pages) StarBtnFragment(w io.Writer, params StarBtnFragmentParams) error {
823 params.HxSwapOob = true
824 return p.executePlain("fragments/starBtn", w, params)
825}
826
827type RepoIndexParams struct {
828 LoggedInUser *oauth.MultiAccountUser
829 RepoInfo repoinfo.RepoInfo
830 Active string
831 TagMap map[string][]string
832 CommitsTrunc []types.Commit
833 TagsTrunc []*types.TagReference
834 BranchesTrunc []types.Branch
835 // ForkInfo *types.ForkInfo
836 HTMLReadme template.HTML
837 Raw bool
838 EmailToDid map[string]string
839 VerifiedCommits commitverify.VerifiedCommits
840 Languages []types.RepoLanguageDetails
841 Pipelines map[string]models.Pipeline
842 NeedsKnotUpgrade bool
843 KnotUnreachable bool
844 types.RepoIndexResponse
845}
846
847func (p *Pages) RepoIndexPage(w io.Writer, params RepoIndexParams) error {
848 params.Active = "overview"
849 if params.IsEmpty {
850 return p.executeRepo("repo/empty", w, params)
851 }
852
853 if params.NeedsKnotUpgrade {
854 return p.executeRepo("repo/needsUpgrade", w, params)
855 }
856
857 if params.KnotUnreachable {
858 return p.executeRepo("repo/knotUnreachable", w, params)
859 }
860
861 rctx := p.rctx.Clone()
862 rctx.RepoInfo = params.RepoInfo
863 rctx.RepoInfo.Ref = params.Ref
864 rctx.RendererType = markup.RendererTypeRepoMarkdown
865
866 if params.ReadmeFileName != "" {
867 ext := strings.ToLower(filepath.Ext(params.ReadmeFileName))
868 switch ext {
869 case ".md", ".markdown", ".mdown", ".mkdn", ".mkd":
870 params.Raw = false
871 htmlString := rctx.RenderMarkdown(params.Readme)
872 sanitized := rctx.SanitizeDefault(htmlString)
873 params.HTMLReadme = template.HTML(sanitized)
874 default:
875 params.Raw = true
876 }
877 }
878
879 return p.executeRepo("repo/index", w, params)
880}
881
882type RepoLogParams struct {
883 LoggedInUser *oauth.MultiAccountUser
884 RepoInfo repoinfo.RepoInfo
885 TagMap map[string][]string
886 Active string
887 EmailToDid map[string]string
888 VerifiedCommits commitverify.VerifiedCommits
889 Pipelines map[string]models.Pipeline
890
891 types.RepoLogResponse
892}
893
894func (p *Pages) RepoLog(w io.Writer, params RepoLogParams) error {
895 params.Active = "overview"
896 return p.executeRepo("repo/log", w, params)
897}
898
899type RepoCommitParams struct {
900 LoggedInUser *oauth.MultiAccountUser
901 RepoInfo repoinfo.RepoInfo
902 Active string
903 EmailToDid map[string]string
904 Pipeline *models.Pipeline
905 DiffOpts types.DiffOpts
906
907 // singular because it's always going to be just one
908 VerifiedCommit commitverify.VerifiedCommits
909
910 types.RepoCommitResponse
911}
912
913func (p *Pages) RepoCommit(w io.Writer, params RepoCommitParams) error {
914 params.Active = "overview"
915 return p.executeRepo("repo/commit", w, params)
916}
917
918type RepoTreeParams struct {
919 LoggedInUser *oauth.MultiAccountUser
920 RepoInfo repoinfo.RepoInfo
921 Active string
922 BreadCrumbs [][]string
923 Path string
924 Raw bool
925 HTMLReadme template.HTML
926 EmailToDid map[string]string
927 LastCommitInfo *types.LastCommitInfo
928 types.RepoTreeResponse
929}
930
931type RepoTreeStats struct {
932 NumFolders uint64
933 NumFiles uint64
934}
935
936func (r RepoTreeParams) TreeStats() RepoTreeStats {
937 numFolders, numFiles := 0, 0
938 for _, f := range r.Files {
939 if !f.IsFile() {
940 numFolders += 1
941 } else if f.IsFile() {
942 numFiles += 1
943 }
944 }
945
946 return RepoTreeStats{
947 NumFolders: uint64(numFolders),
948 NumFiles: uint64(numFiles),
949 }
950}
951
952func (p *Pages) RepoTree(w io.Writer, params RepoTreeParams) error {
953 params.Active = "overview"
954
955 rctx := p.rctx.Clone()
956 rctx.RepoInfo = params.RepoInfo
957 rctx.RepoInfo.Ref = params.Ref
958 rctx.RendererType = markup.RendererTypeRepoMarkdown
959
960 if params.ReadmeFileName != "" {
961 ext := strings.ToLower(filepath.Ext(params.ReadmeFileName))
962 switch ext {
963 case ".md", ".markdown", ".mdown", ".mkdn", ".mkd":
964 params.Raw = false
965 htmlString := rctx.RenderMarkdown(params.Readme)
966 sanitized := rctx.SanitizeDefault(htmlString)
967 params.HTMLReadme = template.HTML(sanitized)
968 default:
969 params.Raw = true
970 }
971 }
972
973 return p.executeRepo("repo/tree", w, params)
974}
975
976type RepoBranchesParams struct {
977 LoggedInUser *oauth.MultiAccountUser
978 RepoInfo repoinfo.RepoInfo
979 Active string
980 types.RepoBranchesResponse
981}
982
983func (p *Pages) RepoBranches(w io.Writer, params RepoBranchesParams) error {
984 params.Active = "overview"
985 return p.executeRepo("repo/branches", w, params)
986}
987
988type RepoTagsParams struct {
989 LoggedInUser *oauth.MultiAccountUser
990 RepoInfo repoinfo.RepoInfo
991 Active string
992 types.RepoTagsResponse
993 ArtifactMap map[plumbing.Hash][]models.Artifact
994 DanglingArtifacts []models.Artifact
995}
996
997func (p *Pages) RepoTags(w io.Writer, params RepoTagsParams) error {
998 params.Active = "overview"
999 return p.executeRepo("repo/tags", w, params)
1000}
1001
1002type RepoTagParams struct {
1003 LoggedInUser *oauth.MultiAccountUser
1004 RepoInfo repoinfo.RepoInfo
1005 Active string
1006 types.RepoTagResponse
1007 ArtifactMap map[plumbing.Hash][]models.Artifact
1008 DanglingArtifacts []models.Artifact
1009}
1010
1011func (p *Pages) RepoTag(w io.Writer, params RepoTagParams) error {
1012 params.Active = "overview"
1013 return p.executeRepo("repo/tag", w, params)
1014}
1015
1016type RepoArtifactParams struct {
1017 LoggedInUser *oauth.MultiAccountUser
1018 RepoInfo repoinfo.RepoInfo
1019 Artifact models.Artifact
1020}
1021
1022func (p *Pages) RepoArtifactFragment(w io.Writer, params RepoArtifactParams) error {
1023 return p.executePlain("repo/fragments/artifact", w, params)
1024}
1025
1026type RepoBlobParams struct {
1027 LoggedInUser *oauth.MultiAccountUser
1028 RepoInfo repoinfo.RepoInfo
1029 Active string
1030 BreadCrumbs [][]string
1031 BlobView models.BlobView
1032 EmailToDid map[string]string
1033 LastCommitInfo *types.LastCommitInfo
1034 *tangled.RepoBlob_Output
1035}
1036
1037func (p *Pages) RepoBlob(w io.Writer, params RepoBlobParams) error {
1038 params.Active = "overview"
1039 return p.executeRepo("repo/blob", w, params)
1040}
1041
1042type Collaborator struct {
1043 Did string
1044 Role string
1045}
1046
1047type RepoSettingsParams struct {
1048 LoggedInUser *oauth.MultiAccountUser
1049 RepoInfo repoinfo.RepoInfo
1050 Collaborators []Collaborator
1051 Active string
1052 Branches []types.Branch
1053 Spindles []string
1054 CurrentSpindle string
1055 Secrets []*tangled.RepoListSecrets_Secret
1056
1057 // TODO: use repoinfo.roles
1058 IsCollaboratorInviteAllowed bool
1059}
1060
1061func (p *Pages) RepoSettings(w io.Writer, params RepoSettingsParams) error {
1062 params.Active = "settings"
1063 return p.executeRepo("repo/settings", w, params)
1064}
1065
1066type RepoGeneralSettingsParams struct {
1067 LoggedInUser *oauth.MultiAccountUser
1068 RepoInfo repoinfo.RepoInfo
1069 Labels []models.LabelDefinition
1070 DefaultLabels []models.LabelDefinition
1071 SubscribedLabels map[string]struct{}
1072 ShouldSubscribeAll bool
1073 Active string
1074 Tab string
1075 Branches []types.Branch
1076}
1077
1078func (p *Pages) RepoGeneralSettings(w io.Writer, params RepoGeneralSettingsParams) error {
1079 params.Active = "settings"
1080 params.Tab = "general"
1081 return p.executeRepo("repo/settings/general", w, params)
1082}
1083
1084type RepoAccessSettingsParams struct {
1085 LoggedInUser *oauth.MultiAccountUser
1086 RepoInfo repoinfo.RepoInfo
1087 Active string
1088 Tab string
1089 Collaborators []Collaborator
1090}
1091
1092func (p *Pages) RepoAccessSettings(w io.Writer, params RepoAccessSettingsParams) error {
1093 params.Active = "settings"
1094 params.Tab = "access"
1095 return p.executeRepo("repo/settings/access", w, params)
1096}
1097
1098type RepoPipelineSettingsParams struct {
1099 LoggedInUser *oauth.MultiAccountUser
1100 RepoInfo repoinfo.RepoInfo
1101 Active string
1102 Tab string
1103 Spindles []string
1104 CurrentSpindle string
1105 Secrets []map[string]any
1106}
1107
1108func (p *Pages) RepoPipelineSettings(w io.Writer, params RepoPipelineSettingsParams) error {
1109 params.Active = "settings"
1110 params.Tab = "pipelines"
1111 return p.executeRepo("repo/settings/pipelines", w, params)
1112}
1113
1114type RepoWebhooksSettingsParams struct {
1115 LoggedInUser *oauth.MultiAccountUser
1116 RepoInfo repoinfo.RepoInfo
1117 Active string
1118 Tab string
1119 Webhooks []models.Webhook
1120 WebhookDeliveries map[int64][]models.WebhookDelivery
1121}
1122
1123func (p *Pages) RepoWebhooksSettings(w io.Writer, params RepoWebhooksSettingsParams) error {
1124 params.Active = "settings"
1125 params.Tab = "hooks"
1126 return p.executeRepo("repo/settings/hooks", w, params)
1127}
1128
1129type WebhookDeliveriesListParams struct {
1130 LoggedInUser *oauth.MultiAccountUser
1131 RepoInfo repoinfo.RepoInfo
1132 Webhook *models.Webhook
1133 Deliveries []models.WebhookDelivery
1134}
1135
1136func (p *Pages) WebhookDeliveriesList(w io.Writer, params WebhookDeliveriesListParams) error {
1137 tpl, err := p.parse("repo/settings/fragments/webhookDeliveries")
1138 if err != nil {
1139 return err
1140 }
1141 return tpl.ExecuteTemplate(w, "repo/settings/fragments/webhookDeliveries", params)
1142}
1143
1144type RepoSiteSettingsParams struct {
1145 LoggedInUser *oauth.MultiAccountUser
1146 RepoInfo repoinfo.RepoInfo
1147 Active string
1148 Tab string
1149 Branches []types.Branch
1150 SiteConfig *models.RepoSite
1151 OwnerClaim *models.DomainClaim
1152 Deploys []models.SiteDeploy
1153 IndexSiteTakenBy string // repo_at of another repo that already holds is_index, or ""
1154}
1155
1156func (p *Pages) RepoSiteSettings(w io.Writer, params RepoSiteSettingsParams) error {
1157 params.Active = "settings"
1158 params.Tab = "sites"
1159 return p.executeRepo("repo/settings/sites", w, params)
1160}
1161
1162type RepoIssuesParams struct {
1163 LoggedInUser *oauth.MultiAccountUser
1164 RepoInfo repoinfo.RepoInfo
1165 Active string
1166 Issues []models.Issue
1167 IssueCount int
1168 LabelDefs map[string]*models.LabelDefinition
1169 Page pagination.Page
1170 FilterState string
1171 FilterQuery string
1172 VouchRelationships map[syntax.DID]*models.VouchRelationship
1173}
1174
1175func (p *Pages) RepoIssues(w io.Writer, params RepoIssuesParams) error {
1176 params.Active = "issues"
1177 return p.executeRepo("repo/issues/issues", w, params)
1178}
1179
1180type RepoSingleIssueParams struct {
1181 LoggedInUser *oauth.MultiAccountUser
1182 RepoInfo repoinfo.RepoInfo
1183 Active string
1184 Issue *models.Issue
1185 CommentList []models.CommentListItem
1186 Backlinks []models.RichReferenceLink
1187 LabelDefs map[string]*models.LabelDefinition
1188
1189 Reactions map[models.ReactionKind]models.ReactionDisplayData
1190 UserReacted map[models.ReactionKind]bool
1191 VouchRelationships map[syntax.DID]*models.VouchRelationship
1192}
1193
1194func (p *Pages) RepoSingleIssue(w io.Writer, params RepoSingleIssueParams) error {
1195 params.Active = "issues"
1196 return p.executeRepo("repo/issues/issue", w, params)
1197}
1198
1199type EditIssueParams struct {
1200 LoggedInUser *oauth.MultiAccountUser
1201 RepoInfo repoinfo.RepoInfo
1202 Issue *models.Issue
1203 Action string
1204}
1205
1206func (p *Pages) EditIssueFragment(w io.Writer, params EditIssueParams) error {
1207 params.Action = "edit"
1208 return p.executePlain("repo/issues/fragments/putIssue", w, params)
1209}
1210
1211type ThreadReactionFragmentParams struct {
1212 ThreadAt syntax.ATURI
1213 Kind models.ReactionKind
1214 Count int
1215 Users []string
1216 IsReacted bool
1217}
1218
1219func (p *Pages) ThreadReactionFragment(w io.Writer, params ThreadReactionFragmentParams) error {
1220 return p.executePlain("repo/fragments/reaction", w, params)
1221}
1222
1223type RepoNewIssueParams struct {
1224 LoggedInUser *oauth.MultiAccountUser
1225 RepoInfo repoinfo.RepoInfo
1226 Issue *models.Issue // existing issue if any -- passed when editing
1227 Active string
1228 Action string
1229}
1230
1231func (p *Pages) RepoNewIssue(w io.Writer, params RepoNewIssueParams) error {
1232 params.Active = "issues"
1233 params.Action = "create"
1234 return p.executeRepo("repo/issues/new", w, params)
1235}
1236
1237type EditIssueCommentParams struct {
1238 LoggedInUser *oauth.MultiAccountUser
1239 RepoInfo repoinfo.RepoInfo
1240 Issue *models.Issue
1241 Comment *models.IssueComment
1242}
1243
1244func (p *Pages) EditIssueCommentFragment(w io.Writer, params EditIssueCommentParams) error {
1245 return p.executePlain("repo/issues/fragments/editIssueComment", w, params)
1246}
1247
1248type ReplyIssueCommentPlaceholderParams struct {
1249 LoggedInUser *oauth.MultiAccountUser
1250 RepoInfo repoinfo.RepoInfo
1251 Issue *models.Issue
1252 Comment *models.IssueComment
1253}
1254
1255func (p *Pages) ReplyIssueCommentPlaceholderFragment(w io.Writer, params ReplyIssueCommentPlaceholderParams) error {
1256 return p.executePlain("repo/issues/fragments/replyIssueCommentPlaceholder", w, params)
1257}
1258
1259type ReplyIssueCommentParams struct {
1260 LoggedInUser *oauth.MultiAccountUser
1261 RepoInfo repoinfo.RepoInfo
1262 Issue *models.Issue
1263 Comment *models.IssueComment
1264}
1265
1266func (p *Pages) ReplyIssueCommentFragment(w io.Writer, params ReplyIssueCommentParams) error {
1267 return p.executePlain("repo/issues/fragments/replyComment", w, params)
1268}
1269
1270type IssueCommentBodyParams struct {
1271 LoggedInUser *oauth.MultiAccountUser
1272 RepoInfo repoinfo.RepoInfo
1273 Issue *models.Issue
1274 Comment *models.IssueComment
1275}
1276
1277func (p *Pages) IssueCommentBodyFragment(w io.Writer, params IssueCommentBodyParams) error {
1278 return p.executePlain("repo/issues/fragments/issueCommentBody", w, params)
1279}
1280
1281type StackedDiff struct {
1282 Diff *types.NiceDiff
1283 Opts types.DiffOpts
1284}
1285
1286type RepoNewPullParams struct {
1287 LoggedInUser *oauth.MultiAccountUser
1288 RepoInfo repoinfo.RepoInfo
1289 Branches []types.Branch
1290 SourceBranches []types.Branch
1291 ForkBranches []types.Branch
1292 Forks []models.Repo
1293 Source Source
1294 SourceBranch string
1295 TargetBranch string
1296 Fork string
1297 Patch string
1298 Title string
1299 Body string
1300 IsStacked bool
1301 Comparison *types.RepoFormatPatchResponse
1302 Diff *types.NiceDiff
1303 DiffOpts types.DiffOpts
1304 StackedDiffs []StackedDiff
1305 MergeCheck *types.MergeCheckResponse
1306 StackTitles map[string]string
1307 StackBodies map[string]string
1308 PrefillError string
1309 Active string
1310 LabelDefs map[string]*models.LabelDefinition
1311 LabelState models.LabelState
1312 StackLabelStates map[string]models.LabelState
1313}
1314
1315func (p *Pages) RepoNewPull(w io.Writer, params RepoNewPullParams) error {
1316 params.Active = "pulls"
1317 return p.executeRepo("repo/pulls/new", w, params)
1318}
1319
1320func (p *Pages) PullComposeHostFragment(w io.Writer, params RepoNewPullParams) error {
1321 return p.executePlain("repo/pulls/fragments/pullComposeHost", w, params)
1322}
1323
1324func (p *Pages) MarkdownPreviewFragment(w io.Writer, body string) error {
1325 return p.executePlain("fragments/markdownPreview", w, body)
1326}
1327
1328type RepoPullsParams struct {
1329 LoggedInUser *oauth.MultiAccountUser
1330 RepoInfo repoinfo.RepoInfo
1331 Pulls []*models.Pull
1332 Active string
1333 FilterState string
1334 FilterQuery string
1335 Stacks []models.Stack
1336 Pipelines map[string]models.Pipeline
1337 LabelDefs map[string]*models.LabelDefinition
1338 Page pagination.Page
1339 PullCount int
1340 VouchRelationships map[syntax.DID]*models.VouchRelationship
1341}
1342
1343func (p *Pages) RepoPulls(w io.Writer, params RepoPullsParams) error {
1344 params.Active = "pulls"
1345 return p.executeRepo("repo/pulls/pulls", w, params)
1346}
1347
1348type ResubmitResult uint64
1349
1350const (
1351 ShouldResubmit ResubmitResult = iota
1352 ShouldNotResubmit
1353 Unknown
1354)
1355
1356func (r ResubmitResult) Yes() bool {
1357 return r == ShouldResubmit
1358}
1359func (r ResubmitResult) No() bool {
1360 return r == ShouldNotResubmit
1361}
1362func (r ResubmitResult) Unknown() bool {
1363 return r == Unknown
1364}
1365
1366type RepoSinglePullParams struct {
1367 LoggedInUser *oauth.MultiAccountUser
1368 RepoInfo repoinfo.RepoInfo
1369 Active string
1370 Pull *models.Pull
1371 Stack models.Stack
1372 Backlinks []models.RichReferenceLink
1373 BranchDeleteStatus *models.BranchDeleteStatus
1374 MergeCheck types.MergeCheckResponse
1375 ResubmitCheck ResubmitResult
1376 Pipelines map[string]models.Pipeline
1377 Diff types.DiffRenderer
1378 DiffOpts types.DiffOpts
1379 ActiveRound int
1380 IsInterdiff bool
1381
1382 Reactions map[models.ReactionKind]models.ReactionDisplayData
1383 UserReacted map[models.ReactionKind]bool
1384
1385 LabelDefs map[string]*models.LabelDefinition
1386 VouchRelationships map[syntax.DID]*models.VouchRelationship
1387}
1388
1389func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error {
1390 params.Active = "pulls"
1391 return p.executeRepo("repo/pulls/pull", w, params)
1392}
1393
1394type RepoPullPatchParams struct {
1395 LoggedInUser *oauth.MultiAccountUser
1396 RepoInfo repoinfo.RepoInfo
1397 Pull *models.Pull
1398 Stack models.Stack
1399 Diff *types.NiceDiff
1400 Round int
1401 Submission *models.PullSubmission
1402 DiffOpts types.DiffOpts
1403}
1404
1405// this name is a mouthful
1406func (p *Pages) RepoPullPatchPage(w io.Writer, params RepoPullPatchParams) error {
1407 return p.execute("repo/pulls/patch", w, params)
1408}
1409
1410type RepoPullInterdiffParams struct {
1411 LoggedInUser *oauth.MultiAccountUser
1412 RepoInfo repoinfo.RepoInfo
1413 Pull *models.Pull
1414 Round int
1415 Interdiff *patchutil.InterdiffResult
1416 DiffOpts types.DiffOpts
1417}
1418
1419// this name is a mouthful
1420func (p *Pages) RepoPullInterdiffPage(w io.Writer, params RepoPullInterdiffParams) error {
1421 return p.execute("repo/pulls/interdiff", w, params)
1422}
1423
1424type PullResubmitParams struct {
1425 LoggedInUser *oauth.MultiAccountUser
1426 RepoInfo repoinfo.RepoInfo
1427 Pull *models.Pull
1428 SubmissionId int
1429}
1430
1431func (p *Pages) PullResubmitFragment(w io.Writer, params PullResubmitParams) error {
1432 return p.executePlain("repo/pulls/fragments/pullResubmit", w, params)
1433}
1434
1435type PullActionsParams struct {
1436 LoggedInUser *oauth.MultiAccountUser
1437 RepoInfo repoinfo.RepoInfo
1438 Pull *models.Pull
1439 RoundNumber int
1440 MergeCheck types.MergeCheckResponse
1441 ResubmitCheck ResubmitResult
1442 BranchDeleteStatus *models.BranchDeleteStatus
1443 Stack models.Stack
1444}
1445
1446func (p *Pages) PullActionsFragment(w io.Writer, params PullActionsParams) error {
1447 return p.executePlain("repo/pulls/fragments/pullActions", w, params)
1448}
1449
1450type PullNewCommentParams struct {
1451 LoggedInUser *oauth.MultiAccountUser
1452 RepoInfo repoinfo.RepoInfo
1453 Pull *models.Pull
1454 RoundNumber int
1455}
1456
1457func (p *Pages) PullNewCommentFragment(w io.Writer, params PullNewCommentParams) error {
1458 return p.executePlain("repo/pulls/fragments/pullNewComment", w, params)
1459}
1460
1461type RepoCompareParams struct {
1462 LoggedInUser *oauth.MultiAccountUser
1463 RepoInfo repoinfo.RepoInfo
1464 Forks []models.Repo
1465 Branches []types.Branch
1466 Tags []*types.TagReference
1467 Base string
1468 Head string
1469 Diff *types.NiceDiff
1470 DiffOpts types.DiffOpts
1471
1472 Active string
1473}
1474
1475func (p *Pages) RepoCompare(w io.Writer, params RepoCompareParams) error {
1476 params.Active = "overview"
1477 return p.executeRepo("repo/compare/compare", w, params)
1478}
1479
1480type RepoCompareNewParams struct {
1481 LoggedInUser *oauth.MultiAccountUser
1482 RepoInfo repoinfo.RepoInfo
1483 Forks []models.Repo
1484 Branches []types.Branch
1485 Tags []*types.TagReference
1486 Base string
1487 Head string
1488
1489 Active string
1490}
1491
1492func (p *Pages) RepoCompareNew(w io.Writer, params RepoCompareNewParams) error {
1493 params.Active = "overview"
1494 return p.executeRepo("repo/compare/new", w, params)
1495}
1496
1497type RepoCompareAllowPullParams struct {
1498 LoggedInUser *oauth.MultiAccountUser
1499 RepoInfo repoinfo.RepoInfo
1500 Base string
1501 Head string
1502}
1503
1504func (p *Pages) RepoCompareAllowPullFragment(w io.Writer, params RepoCompareAllowPullParams) error {
1505 return p.executePlain("repo/fragments/compareAllowPull", w, params)
1506}
1507
1508type RepoCompareDiffFragmentParams struct {
1509 Diff types.NiceDiff
1510 DiffOpts types.DiffOpts
1511}
1512
1513func (p *Pages) RepoCompareDiffFragment(w io.Writer, params RepoCompareDiffFragmentParams) error {
1514 return p.executePlain("repo/fragments/diff", w, []any{¶ms.Diff, ¶ms.DiffOpts})
1515}
1516
1517type LabelPanelParams struct {
1518 LoggedInUser *oauth.MultiAccountUser
1519 RepoInfo repoinfo.RepoInfo
1520 Defs map[string]*models.LabelDefinition
1521 Subject string
1522 State models.LabelState
1523}
1524
1525func (p *Pages) LabelPanel(w io.Writer, params LabelPanelParams) error {
1526 return p.executePlain("repo/fragments/labelPanel", w, params)
1527}
1528
1529type EditLabelPanelParams struct {
1530 LoggedInUser *oauth.MultiAccountUser
1531 RepoInfo repoinfo.RepoInfo
1532 Defs map[string]*models.LabelDefinition
1533 Subject string
1534 State models.LabelState
1535 Prefix string
1536}
1537
1538func (p *Pages) EditLabelPanel(w io.Writer, params EditLabelPanelParams) error {
1539 return p.executePlain("repo/fragments/editLabelPanel", w, params)
1540}
1541
1542type RepoStarsParams struct {
1543 LoggedInUser *oauth.MultiAccountUser
1544 RepoInfo repoinfo.RepoInfo
1545 Active string
1546 Starrers []models.Star
1547 Page pagination.Page
1548 TotalCount int
1549}
1550
1551func (p *Pages) RepoStars(w io.Writer, params RepoStarsParams) error {
1552 params.Active = "overview"
1553 return p.executeRepo("repo/stars", w, params)
1554}
1555
1556type PipelinesParams struct {
1557 LoggedInUser *oauth.MultiAccountUser
1558 RepoInfo repoinfo.RepoInfo
1559 Pipelines []models.Pipeline
1560 Active string
1561 FilterKind string
1562 Total int64
1563}
1564
1565func (p *Pages) Pipelines(w io.Writer, params PipelinesParams) error {
1566 params.Active = "pipelines"
1567 return p.executeRepo("repo/pipelines/pipelines", w, params)
1568}
1569
1570type LogBlockParams struct {
1571 Id int
1572 Name string
1573 Command string
1574 Collapsed bool
1575 StartTime time.Time
1576}
1577
1578func (p *Pages) LogBlock(w io.Writer, params LogBlockParams) error {
1579 return p.executePlain("repo/pipelines/fragments/logBlock", w, params)
1580}
1581
1582type LogBlockEndParams struct {
1583 Id int
1584 StartTime time.Time
1585 EndTime time.Time
1586}
1587
1588func (p *Pages) LogBlockEnd(w io.Writer, params LogBlockEndParams) error {
1589 return p.executePlain("repo/pipelines/fragments/logBlockEnd", w, params)
1590}
1591
1592type LogLineParams struct {
1593 Id int
1594 Content string
1595}
1596
1597func (p *Pages) LogLine(w io.Writer, params LogLineParams) error {
1598 return p.executePlain("repo/pipelines/fragments/logLine", w, params)
1599}
1600
1601type WorkflowParams struct {
1602 LoggedInUser *oauth.MultiAccountUser
1603 RepoInfo repoinfo.RepoInfo
1604 Pipeline models.Pipeline
1605 Workflow string
1606 LogUrl string
1607 Active string
1608}
1609
1610func (p *Pages) Workflow(w io.Writer, params WorkflowParams) error {
1611 params.Active = "pipelines"
1612 return p.executeRepo("repo/pipelines/workflow", w, params)
1613}
1614
1615type PutStringParams struct {
1616 LoggedInUser *oauth.MultiAccountUser
1617 Action string
1618
1619 // this is supplied in the case of editing an existing string
1620 String models.String
1621}
1622
1623func (p *Pages) PutString(w io.Writer, params PutStringParams) error {
1624 return p.execute("strings/put", w, params)
1625}
1626
1627type StringsDashboardParams struct {
1628 LoggedInUser *oauth.MultiAccountUser
1629 Card ProfileCard
1630 Strings []models.String
1631}
1632
1633func (p *Pages) StringsDashboard(w io.Writer, params StringsDashboardParams) error {
1634 return p.execute("strings/dashboard", w, params)
1635}
1636
1637type StringTimelineParams struct {
1638 LoggedInUser *oauth.MultiAccountUser
1639 Strings []models.String
1640}
1641
1642func (p *Pages) StringsTimeline(w io.Writer, params StringTimelineParams) error {
1643 return p.execute("strings/timeline", w, params)
1644}
1645
1646type SingleStringParams struct {
1647 LoggedInUser *oauth.MultiAccountUser
1648 ShowRendered bool
1649 RenderToggle bool
1650 RenderedContents template.HTML
1651 String *models.String
1652 Stats models.StringStats
1653 IsStarred bool
1654 StarCount int
1655 Owner identity.Identity
1656}
1657
1658func (p *Pages) SingleString(w io.Writer, params SingleStringParams) error {
1659 return p.execute("strings/string", w, params)
1660}
1661
1662type SearchReposParams struct {
1663 LoggedInUser *oauth.MultiAccountUser
1664 Repos []models.Repo
1665 Page pagination.Page
1666 ResultCount int
1667 FilterQuery string
1668 SortParam string
1669 TimeTaken time.Duration
1670 DocCount int64
1671}
1672
1673func (p *Pages) SearchRepos(w io.Writer, params SearchReposParams) error {
1674 return p.execute("search/search", w, params)
1675}
1676
1677func (p *Pages) Home(w io.Writer, params TimelineParams) error {
1678 return p.execute("timeline/home", w, params)
1679}
1680
1681func (p *Pages) Static() http.Handler {
1682 if p.dev {
1683 return http.StripPrefix("/static/", http.FileServer(http.Dir("appview/pages/static")))
1684 }
1685
1686 sub, err := fs.Sub(p.embedFS, "static")
1687 if err != nil {
1688 p.logger.Error("no static dir found? that's crazy", "err", err)
1689 panic(err)
1690 }
1691 // Custom handler to apply Cache-Control headers for font files
1692 return Cache(http.StripPrefix("/static/", http.FileServer(http.FS(sub))))
1693}
1694
1695func Cache(h http.Handler) http.Handler {
1696 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1697 path := strings.Split(r.URL.Path, "?")[0]
1698
1699 if strings.HasSuffix(path, ".css") {
1700 // on day for css files
1701 w.Header().Set("Cache-Control", "public, max-age=86400")
1702 } else {
1703 w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
1704 }
1705 h.ServeHTTP(w, r)
1706 })
1707}
1708
1709func (p *Pages) CssContentHash() string {
1710 cssFile, err := p.embedFS.Open("static/tw.css")
1711 if err != nil {
1712 slog.Debug("Error opening CSS file", "err", err)
1713 return ""
1714 }
1715 defer cssFile.Close()
1716
1717 hasher := sha256.New()
1718 if _, err := io.Copy(hasher, cssFile); err != nil {
1719 slog.Debug("Error hashing CSS file", "err", err)
1720 return ""
1721 }
1722
1723 return hex.EncodeToString(hasher.Sum(nil))[:8] // Use first 8 chars of hash
1724}
1725
1726func (p *Pages) DangerPasswordTokenStep(w io.Writer) error {
1727 return p.executePlain("user/settings/fragments/dangerPasswordToken", w, nil)
1728}
1729
1730func (p *Pages) DangerPasswordSuccess(w io.Writer) error {
1731 return p.executePlain("user/settings/fragments/dangerPasswordSuccess", w, nil)
1732}
1733
1734func (p *Pages) DangerDeleteTokenStep(w io.Writer) error {
1735 return p.executePlain("user/settings/fragments/dangerDeleteToken", w, nil)
1736}
1737
1738func (p *Pages) Error500(w io.Writer) error {
1739 return p.execute("errors/500", w, nil)
1740}
1741
1742func (p *Pages) Error404(w io.Writer) error {
1743 return p.execute("errors/404", w, nil)
1744}
1745
1746func (p *Pages) ErrorKnot404(w io.Writer) error {
1747 return p.execute("errors/knot404", w, nil)
1748}
1749
1750func (p *Pages) Error503(w io.Writer) error {
1751 return p.execute("errors/503", w, nil)
1752}