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