Monorepo for Tangled
at master 110 lines 2.4 kB view raw
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) IsResyncing() bool { 55 return s == RepoStateResyncing 56} 57 58type HostCursor struct { 59 Hostname string 60 LastSeq int64 61} 62 63type Host struct { 64 Hostname string 65 NoSSL bool 66 Status HostStatus 67 LastSeq int64 68} 69 70type HostStatus string 71 72const ( 73 HostStatusActive HostStatus = "active" 74 HostStatusIdle HostStatus = "idle" 75 HostStatusOffline HostStatus = "offline" 76 HostStatusThrottled HostStatus = "throttled" 77 HostStatusBanned HostStatus = "banned" 78) 79 80var AllHostStatuses = []HostStatus{ 81 HostStatusActive, 82 HostStatusIdle, 83 HostStatusOffline, 84 HostStatusThrottled, 85 HostStatusBanned, 86} 87 88// func (h *Host) SubscribeGitRefsURL(cursor int64) string { 89// scheme := "wss" 90// if h.NoSSL { 91// scheme = "ws" 92// } 93// u := fmt.Sprintf("%s://%s/xrpc/%s", scheme, h.Hostname, tangled.SubscribeGitRefsNSID) 94// if cursor > 0 { 95// u = fmt.Sprintf("%s?cursor=%d", u, h.LastSeq) 96// } 97// return u 98// } 99 100func (h *Host) LegacyEventsURL(cursor int64) string { 101 scheme := "wss" 102 if h.NoSSL { 103 scheme = "ws" 104 } 105 u := fmt.Sprintf("%s://%s/events", scheme, h.Hostname) 106 if cursor > 0 { 107 u = fmt.Sprintf("%s?cursor=%d", u, cursor) 108 } 109 return u 110}