A vibe coded tangled fork which supports pijul.
1package models
2
3import (
4 "fmt"
5 "strings"
6 "time"
7
8 "github.com/bluesky-social/indigo/atproto/syntax"
9 securejoin "github.com/cyphar/filepath-securejoin"
10 "tangled.org/core/api/tangled"
11)
12
13type Repo struct {
14 Id int64
15 Did string
16 Name string
17 Knot string
18 Rkey string
19 Created time.Time
20 Description string
21 Website string
22 Topics []string
23 Spindle string
24 Labels []string
25
26 // optionally, populate this when querying for reverse mappings
27 RepoStats *RepoStats
28
29 // optional
30 Source string
31}
32
33func RepoFromRecord(did syntax.DID, rkey syntax.RecordKey, record tangled.Repo) (Repo, error) {
34 panic("unimplemented")
35}
36
37func (r *Repo) AsRecord() tangled.Repo {
38 var source, spindle, description, website *string
39
40 if r.Source != "" {
41 source = &r.Source
42 }
43
44 if r.Spindle != "" {
45 spindle = &r.Spindle
46 }
47
48 if r.Description != "" {
49 description = &r.Description
50 }
51
52 if r.Website != "" {
53 website = &r.Website
54 }
55
56 return tangled.Repo{
57 Knot: r.Knot,
58 Name: r.Name,
59 Description: description,
60 Website: website,
61 Topics: r.Topics,
62 CreatedAt: r.Created.Format(time.RFC3339),
63 Source: source,
64 Spindle: spindle,
65 Labels: r.Labels,
66 }
67}
68
69func (r Repo) RepoAt() syntax.ATURI {
70 return syntax.ATURI(fmt.Sprintf("at://%s/%s/%s", r.Did, tangled.RepoNSID, r.Rkey))
71}
72
73func (r Repo) DidSlashRepo() string {
74 p, _ := securejoin.SecureJoin(r.Did, r.Name)
75 return p
76}
77
78func (r Repo) TopicStr() string {
79 return strings.Join(r.Topics, " ")
80}
81
82type RepoStats struct {
83 Language string
84 StarCount int
85 IssueCount IssueCount
86 PullCount PullCount
87}
88
89type IssueCount struct {
90 Open int
91 Closed int
92}
93
94type PullCount struct {
95 Open int
96 Merged int
97 Closed int
98 Deleted int
99}
100
101type RepoLabel struct {
102 Id int64
103 RepoAt syntax.ATURI
104 LabelAt syntax.ATURI
105}
106
107type RepoGroup struct {
108 Repo *Repo
109 Issues []Issue
110}
111
112type BlobContentType int
113
114const (
115 BlobContentTypeCode BlobContentType = iota
116 BlobContentTypeMarkup
117 BlobContentTypeImage
118 BlobContentTypeSvg
119 BlobContentTypeVideo
120 BlobContentTypeSubmodule
121)
122
123func (ty BlobContentType) IsCode() bool { return ty == BlobContentTypeCode }
124func (ty BlobContentType) IsMarkup() bool { return ty == BlobContentTypeMarkup }
125func (ty BlobContentType) IsImage() bool { return ty == BlobContentTypeImage }
126func (ty BlobContentType) IsSvg() bool { return ty == BlobContentTypeSvg }
127func (ty BlobContentType) IsVideo() bool { return ty == BlobContentTypeVideo }
128func (ty BlobContentType) IsSubmodule() bool { return ty == BlobContentTypeSubmodule }
129
130type BlobView struct {
131 HasTextView bool // can show as code/text
132 HasRenderedView bool // can show rendered (markup/image/video/submodule)
133 HasRawView bool // can download raw (everything except submodule)
134
135 // current display mode
136 ShowingRendered bool // currently in rendered mode
137
138 // content type flags
139 ContentType BlobContentType
140
141 // Content data
142 Contents string
143 ContentSrc string // URL for media files
144 Lines int
145 SizeHint uint64
146}
147
148// if both views are available, then show a toggle between them
149func (b BlobView) ShowToggle() bool {
150 return b.HasTextView && b.HasRenderedView
151}
152
153func (b BlobView) IsUnsupported() bool {
154 // no view available, only raw
155 return !(b.HasRenderedView || b.HasTextView)
156}
157
158func (b BlobView) ShowingText() bool {
159 return !b.ShowingRendered
160}