A vibe coded tangled fork which supports pijul.
1package models
2
3import (
4 "fmt"
5
6 "github.com/bluesky-social/indigo/atproto/syntax"
7 "tangled.org/core/api/tangled"
8)
9
10type Repo struct {
11 Did syntax.DID
12 Rkey syntax.RecordKey
13 Cid *syntax.CID
14 // content of tangled.Repo
15 Name string
16 KnotDomain string
17
18 GitRev syntax.TID // last processed git.refUpdate revision
19 RepoSha string // sha256 sum of git refs (to avoid no-op git fetch)
20 State RepoState
21 ErrorMsg string
22 RetryCount int
23 RetryAfter int64 // Unix timestamp (seconds)
24}
25
26func (r *Repo) AtUri() syntax.ATURI {
27 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", r.Did, tangled.RepoNSID, r.Rkey))
28}
29
30func (r *Repo) DidSlashRepo() string {
31 return fmt.Sprintf("%s/%s", r.Did, r.Name)
32}
33
34type RepoState string
35
36const (
37 RepoStatePending RepoState = "pending"
38 RepoStateDesynchronized RepoState = "desynchronized"
39 RepoStateResyncing RepoState = "resyncing"
40 RepoStateActive RepoState = "active"
41 RepoStateSuspended RepoState = "suspended"
42 RepoStateError RepoState = "error"
43)
44
45var AllRepoStates = []RepoState{
46 RepoStatePending,
47 RepoStateDesynchronized,
48 RepoStateResyncing,
49 RepoStateActive,
50 RepoStateSuspended,
51 RepoStateError,
52}
53
54func (s RepoState) AllStates() []RepoState {
55 return []RepoState{
56 RepoStatePending,
57 RepoStateDesynchronized,
58 RepoStateResyncing,
59 RepoStateActive,
60 RepoStateSuspended,
61 RepoStateError,
62 }
63}
64
65func (s RepoState) IsResyncing() bool {
66 return s == RepoStateResyncing
67}
68
69type HostCursor struct {
70 Hostname string
71 LastSeq int64
72}
73
74type Host struct {
75 Hostname string
76 NoSSL bool
77 Status HostStatus
78 LastSeq int64
79}
80
81type HostStatus string
82
83const (
84 HostStatusActive HostStatus = "active"
85 HostStatusIdle HostStatus = "idle"
86 HostStatusOffline HostStatus = "offline"
87 HostStatusThrottled HostStatus = "throttled"
88 HostStatusBanned HostStatus = "banned"
89)
90
91var AllHostStatuses = []HostStatus{
92 HostStatusActive,
93 HostStatusIdle,
94 HostStatusOffline,
95 HostStatusThrottled,
96 HostStatusBanned,
97}
98
99// func (h *Host) SubscribeGitRefsURL(cursor int64) string {
100// scheme := "wss"
101// if h.NoSSL {
102// scheme = "ws"
103// }
104// u := fmt.Sprintf("%s://%s/xrpc/%s", scheme, h.Hostname, tangled.SubscribeGitRefsNSID)
105// if cursor > 0 {
106// u = fmt.Sprintf("%s?cursor=%d", u, h.LastSeq)
107// }
108// return u
109// }
110
111func (h *Host) LegacyEventsURL(cursor int64) string {
112 scheme := "wss"
113 if h.NoSSL {
114 scheme = "ws"
115 }
116 u := fmt.Sprintf("%s://%s/events", scheme, h.Hostname)
117 if cursor > 0 {
118 u = fmt.Sprintf("%s?cursor=%d", u, cursor)
119 }
120 return u
121}