This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / appview / pages / pages.go
47 kB 1759 lines
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.TimelineEvent 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 := 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 := 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 RepoNewPullParams struct { 1282 LoggedInUser *oauth.MultiAccountUser 1283 RepoInfo repoinfo.RepoInfo 1284 Branches []types.Branch 1285 Strategy string 1286 SourceBranch string 1287 TargetBranch string 1288 Title string 1289 Body string 1290 Active string 1291} 1292 1293func (p *Pages) RepoNewPull(w io.Writer, params RepoNewPullParams) error { 1294 params.Active = "pulls" 1295 return p.executeRepo("repo/pulls/new", w, params) 1296} 1297 1298type RepoPullsParams struct { 1299 LoggedInUser *oauth.MultiAccountUser 1300 RepoInfo repoinfo.RepoInfo 1301 Pulls []*models.Pull 1302 Active string 1303 FilterState string 1304 FilterQuery string 1305 Stacks []models.Stack 1306 Pipelines map[string]models.Pipeline 1307 LabelDefs map[string]*models.LabelDefinition 1308 Page pagination.Page 1309 PullCount int 1310 VouchRelationships map[syntax.DID]*models.VouchRelationship 1311} 1312 1313func (p *Pages) RepoPulls(w io.Writer, params RepoPullsParams) error { 1314 params.Active = "pulls" 1315 return p.executeRepo("repo/pulls/pulls", w, params) 1316} 1317 1318type ResubmitResult uint64 1319 1320const ( 1321 ShouldResubmit ResubmitResult = iota 1322 ShouldNotResubmit 1323 Unknown 1324) 1325 1326func (r ResubmitResult) Yes() bool { 1327 return r == ShouldResubmit 1328} 1329func (r ResubmitResult) No() bool { 1330 return r == ShouldNotResubmit 1331} 1332func (r ResubmitResult) Unknown() bool { 1333 return r == Unknown 1334} 1335 1336type RepoSinglePullParams struct { 1337 LoggedInUser *oauth.MultiAccountUser 1338 RepoInfo repoinfo.RepoInfo 1339 Active string 1340 Pull *models.Pull 1341 Stack models.Stack 1342 Backlinks []models.RichReferenceLink 1343 BranchDeleteStatus *models.BranchDeleteStatus 1344 MergeCheck types.MergeCheckResponse 1345 ResubmitCheck ResubmitResult 1346 Pipelines map[string]models.Pipeline 1347 Diff types.DiffRenderer 1348 DiffOpts types.DiffOpts 1349 ActiveRound int 1350 IsInterdiff bool 1351 1352 Reactions map[models.ReactionKind]models.ReactionDisplayData 1353 UserReacted map[models.ReactionKind]bool 1354 1355 LabelDefs map[string]*models.LabelDefinition 1356 VouchRelationships map[syntax.DID]*models.VouchRelationship 1357} 1358 1359func (p *Pages) RepoSinglePull(w io.Writer, params RepoSinglePullParams) error { 1360 params.Active = "pulls" 1361 return p.executeRepo("repo/pulls/pull", w, params) 1362} 1363 1364type RepoPullPatchParams struct { 1365 LoggedInUser *oauth.MultiAccountUser 1366 RepoInfo repoinfo.RepoInfo 1367 Pull *models.Pull 1368 Stack models.Stack 1369 Diff *types.NiceDiff 1370 Round int 1371 Submission *models.PullSubmission 1372 DiffOpts types.DiffOpts 1373} 1374 1375// this name is a mouthful 1376func (p *Pages) RepoPullPatchPage(w io.Writer, params RepoPullPatchParams) error { 1377 return p.execute("repo/pulls/patch", w, params) 1378} 1379 1380type RepoPullInterdiffParams struct { 1381 LoggedInUser *oauth.MultiAccountUser 1382 RepoInfo repoinfo.RepoInfo 1383 Pull *models.Pull 1384 Round int 1385 Interdiff *patchutil.InterdiffResult 1386 DiffOpts types.DiffOpts 1387} 1388 1389// this name is a mouthful 1390func (p *Pages) RepoPullInterdiffPage(w io.Writer, params RepoPullInterdiffParams) error { 1391 return p.execute("repo/pulls/interdiff", w, params) 1392} 1393 1394type PullPatchUploadParams struct { 1395 RepoInfo repoinfo.RepoInfo 1396} 1397 1398func (p *Pages) PullPatchUploadFragment(w io.Writer, params PullPatchUploadParams) error { 1399 return p.executePlain("repo/pulls/fragments/pullPatchUpload", w, params) 1400} 1401 1402type PullCompareBranchesParams struct { 1403 RepoInfo repoinfo.RepoInfo 1404 Branches []types.Branch 1405 SourceBranch string 1406} 1407 1408func (p *Pages) PullCompareBranchesFragment(w io.Writer, params PullCompareBranchesParams) error { 1409 return p.executePlain("repo/pulls/fragments/pullCompareBranches", w, params) 1410} 1411 1412type PullCompareForkParams struct { 1413 RepoInfo repoinfo.RepoInfo 1414 Forks []models.Repo 1415 Selected string 1416} 1417 1418func (p *Pages) PullCompareForkFragment(w io.Writer, params PullCompareForkParams) error { 1419 return p.executePlain("repo/pulls/fragments/pullCompareForks", w, params) 1420} 1421 1422type PullCompareForkBranchesParams struct { 1423 RepoInfo repoinfo.RepoInfo 1424 SourceBranches []types.Branch 1425 TargetBranches []types.Branch 1426} 1427 1428func (p *Pages) PullCompareForkBranchesFragment(w io.Writer, params PullCompareForkBranchesParams) error { 1429 return p.executePlain("repo/pulls/fragments/pullCompareForksBranches", w, params) 1430} 1431 1432type PullResubmitParams struct { 1433 LoggedInUser *oauth.MultiAccountUser 1434 RepoInfo repoinfo.RepoInfo 1435 Pull *models.Pull 1436 SubmissionId int 1437} 1438 1439func (p *Pages) PullResubmitFragment(w io.Writer, params PullResubmitParams) error { 1440 return p.executePlain("repo/pulls/fragments/pullResubmit", w, params) 1441} 1442 1443type PullActionsParams struct { 1444 LoggedInUser *oauth.MultiAccountUser 1445 RepoInfo repoinfo.RepoInfo 1446 Pull *models.Pull 1447 RoundNumber int 1448 MergeCheck types.MergeCheckResponse 1449 ResubmitCheck ResubmitResult 1450 BranchDeleteStatus *models.BranchDeleteStatus 1451 Stack models.Stack 1452} 1453 1454func (p *Pages) PullActionsFragment(w io.Writer, params PullActionsParams) error { 1455 return p.executePlain("repo/pulls/fragments/pullActions", w, params) 1456} 1457 1458type PullNewCommentParams struct { 1459 LoggedInUser *oauth.MultiAccountUser 1460 RepoInfo repoinfo.RepoInfo 1461 Pull *models.Pull 1462 RoundNumber int 1463} 1464 1465func (p *Pages) PullNewCommentFragment(w io.Writer, params PullNewCommentParams) error { 1466 return p.executePlain("repo/pulls/fragments/pullNewComment", w, params) 1467} 1468 1469type RepoCompareParams struct { 1470 LoggedInUser *oauth.MultiAccountUser 1471 RepoInfo repoinfo.RepoInfo 1472 Forks []models.Repo 1473 Branches []types.Branch 1474 Tags []*types.TagReference 1475 Base string 1476 Head string 1477 Diff *types.NiceDiff 1478 DiffOpts types.DiffOpts 1479 1480 Active string 1481} 1482 1483func (p *Pages) RepoCompare(w io.Writer, params RepoCompareParams) error { 1484 params.Active = "overview" 1485 return p.executeRepo("repo/compare/compare", w, params) 1486} 1487 1488type RepoCompareNewParams struct { 1489 LoggedInUser *oauth.MultiAccountUser 1490 RepoInfo repoinfo.RepoInfo 1491 Forks []models.Repo 1492 Branches []types.Branch 1493 Tags []*types.TagReference 1494 Base string 1495 Head string 1496 1497 Active string 1498} 1499 1500func (p *Pages) RepoCompareNew(w io.Writer, params RepoCompareNewParams) error { 1501 params.Active = "overview" 1502 return p.executeRepo("repo/compare/new", w, params) 1503} 1504 1505type RepoCompareAllowPullParams struct { 1506 LoggedInUser *oauth.MultiAccountUser 1507 RepoInfo repoinfo.RepoInfo 1508 Base string 1509 Head string 1510} 1511 1512func (p *Pages) RepoCompareAllowPullFragment(w io.Writer, params RepoCompareAllowPullParams) error { 1513 return p.executePlain("repo/fragments/compareAllowPull", w, params) 1514} 1515 1516type RepoCompareDiffFragmentParams struct { 1517 Diff types.NiceDiff 1518 DiffOpts types.DiffOpts 1519} 1520 1521func (p *Pages) RepoCompareDiffFragment(w io.Writer, params RepoCompareDiffFragmentParams) error { 1522 return p.executePlain("repo/fragments/diff", w, []any{&params.Diff, &params.DiffOpts}) 1523} 1524 1525type LabelPanelParams struct { 1526 LoggedInUser *oauth.MultiAccountUser 1527 RepoInfo repoinfo.RepoInfo 1528 Defs map[string]*models.LabelDefinition 1529 Subject string 1530 State models.LabelState 1531} 1532 1533func (p *Pages) LabelPanel(w io.Writer, params LabelPanelParams) error { 1534 return p.executePlain("repo/fragments/labelPanel", w, params) 1535} 1536 1537type EditLabelPanelParams struct { 1538 LoggedInUser *oauth.MultiAccountUser 1539 RepoInfo repoinfo.RepoInfo 1540 Defs map[string]*models.LabelDefinition 1541 Subject string 1542 State models.LabelState 1543} 1544 1545func (p *Pages) EditLabelPanel(w io.Writer, params EditLabelPanelParams) error { 1546 return p.executePlain("repo/fragments/editLabelPanel", w, params) 1547} 1548 1549type RepoStarsParams struct { 1550 LoggedInUser *oauth.MultiAccountUser 1551 RepoInfo repoinfo.RepoInfo 1552 Active string 1553 Starrers []models.Star 1554 Page pagination.Page 1555 TotalCount int 1556} 1557 1558func (p *Pages) RepoStars(w io.Writer, params RepoStarsParams) error { 1559 params.Active = "overview" 1560 return p.executeRepo("repo/stars", w, params) 1561} 1562 1563type PipelinesParams struct { 1564 LoggedInUser *oauth.MultiAccountUser 1565 RepoInfo repoinfo.RepoInfo 1566 Pipelines []models.Pipeline 1567 Active string 1568 FilterKind string 1569 Total int64 1570} 1571 1572func (p *Pages) Pipelines(w io.Writer, params PipelinesParams) error { 1573 params.Active = "pipelines" 1574 return p.executeRepo("repo/pipelines/pipelines", w, params) 1575} 1576 1577type LogBlockParams struct { 1578 Id int 1579 Name string 1580 Command string 1581 Collapsed bool 1582 StartTime time.Time 1583} 1584 1585func (p *Pages) LogBlock(w io.Writer, params LogBlockParams) error { 1586 return p.executePlain("repo/pipelines/fragments/logBlock", w, params) 1587} 1588 1589type LogBlockEndParams struct { 1590 Id int 1591 StartTime time.Time 1592 EndTime time.Time 1593} 1594 1595func (p *Pages) LogBlockEnd(w io.Writer, params LogBlockEndParams) error { 1596 return p.executePlain("repo/pipelines/fragments/logBlockEnd", w, params) 1597} 1598 1599type LogLineParams struct { 1600 Id int 1601 Content string 1602} 1603 1604func (p *Pages) LogLine(w io.Writer, params LogLineParams) error { 1605 return p.executePlain("repo/pipelines/fragments/logLine", w, params) 1606} 1607 1608type WorkflowParams struct { 1609 LoggedInUser *oauth.MultiAccountUser 1610 RepoInfo repoinfo.RepoInfo 1611 Pipeline models.Pipeline 1612 Workflow string 1613 LogUrl string 1614 Active string 1615} 1616 1617func (p *Pages) Workflow(w io.Writer, params WorkflowParams) error { 1618 params.Active = "pipelines" 1619 return p.executeRepo("repo/pipelines/workflow", w, params) 1620} 1621 1622type PutStringParams struct { 1623 LoggedInUser *oauth.MultiAccountUser 1624 Action string 1625 1626 // this is supplied in the case of editing an existing string 1627 String models.String 1628} 1629 1630func (p *Pages) PutString(w io.Writer, params PutStringParams) error { 1631 return p.execute("strings/put", w, params) 1632} 1633 1634type StringsDashboardParams struct { 1635 LoggedInUser *oauth.MultiAccountUser 1636 Card ProfileCard 1637 Strings []models.String 1638} 1639 1640func (p *Pages) StringsDashboard(w io.Writer, params StringsDashboardParams) error { 1641 return p.execute("strings/dashboard", w, params) 1642} 1643 1644type StringTimelineParams struct { 1645 LoggedInUser *oauth.MultiAccountUser 1646 Strings []models.String 1647} 1648 1649func (p *Pages) StringsTimeline(w io.Writer, params StringTimelineParams) error { 1650 return p.execute("strings/timeline", w, params) 1651} 1652 1653type SingleStringParams struct { 1654 LoggedInUser *oauth.MultiAccountUser 1655 ShowRendered bool 1656 RenderToggle bool 1657 RenderedContents template.HTML 1658 String *models.String 1659 Stats models.StringStats 1660 IsStarred bool 1661 StarCount int 1662 Owner identity.Identity 1663} 1664 1665func (p *Pages) SingleString(w io.Writer, params SingleStringParams) error { 1666 return p.execute("strings/string", w, params) 1667} 1668 1669type SearchReposParams struct { 1670 LoggedInUser *oauth.MultiAccountUser 1671 Repos []models.Repo 1672 Page pagination.Page 1673 ResultCount int 1674 FilterQuery string 1675 SortParam string 1676 TimeTaken time.Duration 1677 DocCount int64 1678} 1679 1680func (p *Pages) SearchRepos(w io.Writer, params SearchReposParams) error { 1681 return p.execute("search/search", w, params) 1682} 1683 1684func (p *Pages) Home(w io.Writer, params TimelineParams) error { 1685 return p.execute("timeline/home", w, params) 1686} 1687 1688func (p *Pages) Static() http.Handler { 1689 if p.dev { 1690 return http.StripPrefix("/static/", http.FileServer(http.Dir("appview/pages/static"))) 1691 } 1692 1693 sub, err := fs.Sub(p.embedFS, "static") 1694 if err != nil { 1695 p.logger.Error("no static dir found? that's crazy", "err", err) 1696 panic(err) 1697 } 1698 // Custom handler to apply Cache-Control headers for font files 1699 return Cache(http.StripPrefix("/static/", http.FileServer(http.FS(sub)))) 1700} 1701 1702func Cache(h http.Handler) http.Handler { 1703 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 1704 path := strings.Split(r.URL.Path, "?")[0] 1705 1706 if strings.HasSuffix(path, ".css") { 1707 // on day for css files 1708 w.Header().Set("Cache-Control", "public, max-age=86400") 1709 } else { 1710 w.Header().Set("Cache-Control", "public, max-age=31536000, immutable") 1711 } 1712 h.ServeHTTP(w, r) 1713 }) 1714} 1715 1716func (p *Pages) CssContentHash() string { 1717 cssFile, err := p.embedFS.Open("static/tw.css") 1718 if err != nil { 1719 slog.Debug("Error opening CSS file", "err", err) 1720 return "" 1721 } 1722 defer cssFile.Close() 1723 1724 hasher := sha256.New() 1725 if _, err := io.Copy(hasher, cssFile); err != nil { 1726 slog.Debug("Error hashing CSS file", "err", err) 1727 return "" 1728 } 1729 1730 return hex.EncodeToString(hasher.Sum(nil))[:8] // Use first 8 chars of hash 1731} 1732 1733func (p *Pages) DangerPasswordTokenStep(w io.Writer) error { 1734 return p.executePlain("user/settings/fragments/dangerPasswordToken", w, nil) 1735} 1736 1737func (p *Pages) DangerPasswordSuccess(w io.Writer) error { 1738 return p.executePlain("user/settings/fragments/dangerPasswordSuccess", w, nil) 1739} 1740 1741func (p *Pages) DangerDeleteTokenStep(w io.Writer) error { 1742 return p.executePlain("user/settings/fragments/dangerDeleteToken", w, nil) 1743} 1744 1745func (p *Pages) Error500(w io.Writer) error { 1746 return p.execute("errors/500", w, nil) 1747} 1748 1749func (p *Pages) Error404(w io.Writer) error { 1750 return p.execute("errors/404", w, nil) 1751} 1752 1753func (p *Pages) ErrorKnot404(w io.Writer) error { 1754 return p.execute("errors/knot404", w, nil) 1755} 1756 1757func (p *Pages) Error503(w io.Writer) error { 1758 return p.execute("errors/503", w, nil) 1759}