-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.go
143 lines (123 loc) · 3.56 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"encoding/xml"
"io"
"net/http"
"os"
)
type FollowListAction int
const (
Sync FollowListAction = iota
Add
Delete
)
type FollowManagment struct {
Action FollowListAction
FollowEntity Entity
}
type ImportProgressStruct struct {
entryIndex int
totalEntries int
}
type Entity struct {
PubKey string
PrivateKey string
URL string
ImageURL string
LastPostTime int64
AvgPostTime int64
LastCheckedTime int64
}
type GUIEntry struct {
BookmarkEntity Entity
NPubKey string
Error bool
ErrorMessage string
ErrorCode int
}
// Nostr Kind-0
type KindProfileMetadata struct {
About string
Picture string
Name string
}
// OpmlOutline holds all information about an outline.
type OpmlOutline struct {
Outlines []OpmlOutline `xml:"outline"`
Text string `xml:"text,attr"`
Type string `xml:"type,attr,omitempty"`
IsComment string `xml:"isComment,attr,omitempty"`
IsBreakpoint string `xml:"isBreakpoint,attr,omitempty"`
Created string `xml:"created,attr,omitempty"`
Category string `xml:"category,attr,omitempty"`
XMLURL string `xml:"xmlUrl,attr,omitempty"`
HTMLURL string `xml:"htmlUrl,attr,omitempty"`
URL string `xml:"url,attr,omitempty"`
Language string `xml:"language,attr,omitempty"`
Title string `xml:"title,attr,omitempty"`
Version string `xml:"version,attr,omitempty"`
Description string `xml:"description,attr,omitempty"`
}
// OpmlBody is the parent structure of all outlines.
type OpmlBody struct {
Outlines []OpmlOutline `xml:"outline"`
}
// OpmlHead holds some meta information about the document.
type OpmlHead struct {
Title string `xml:"title"`
DateCreated string `xml:"dateCreated,omitempty"`
DateModified string `xml:"dateModified,omitempty"`
OwnerName string `xml:"ownerName,omitempty"`
OwnerEmail string `xml:"ownerEmail,omitempty"`
OwnerID string `xml:"ownerId,omitempty"`
Docs string `xml:"docs,omitempty"`
ExpansionState string `xml:"expansionState,omitempty"`
VertScrollState string `xml:"vertScrollState,omitempty"`
WindowTop string `xml:"windowTop,omitempty"`
WindowBottom string `xml:"windowBottom,omitempty"`
WindowLeft string `xml:"windowLeft,omitempty"`
WindowRight string `xml:"windowRight,omitempty"`
}
// OPML is the root node of an OPML document. It only has a single required
// attribute: the version.
type OPML struct {
XMLName xml.Name `xml:"opml"`
Version string `xml:"version,attr"`
Head OpmlHead `xml:"head"`
Body OpmlBody `xml:"body"`
}
// XML exports the OPML document to a XML string.
func (doc OPML) XML() (string, error) {
b, err := xml.MarshalIndent(doc, "", "\t")
return xml.Header + string(b), err
}
// NewOPML creates a new OPML structure from a slice of bytes.
func NewOPML(b []byte) (*OPML, error) {
var root OPML
err := xml.Unmarshal(b, &root)
if err != nil {
return nil, err
}
return &root, nil
}
// NewOPMLFromURL creates a new OPML structure from an URL.
func NewOPMLFromURL(url string) (*OPML, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return NewOPML(b)
}
// NewOPMLFromFile creates a new OPML structure from a file.
func NewOPMLFromFile(filePath string) (*OPML, error) {
b, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
return NewOPML(b)
}