-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshimmie.go
207 lines (185 loc) · 4.34 KB
/
shimmie.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package shimmie
import (
"errors"
"strings"
"time"
)
const (
imageRatingSafe = "Safe"
imageRatingQuestionable = "Questionable"
imageRatingExplicit = "Explicit"
)
// Errors returned by Verify.
var (
ErrWrongCredentials = errors.New("wrong username or password")
ErrNotFound = errors.New("entry not found")
)
// ImageRating converts rating letters to full words.
//
// s -> Safe
// q -> Questionable
// e -> Explicit
//
// If another value except (s, q, e) is given, then it returns that value as it
// is.
func ImageRating(rating string) string {
switch rating {
case "s":
return imageRatingSafe
case "q":
return imageRatingQuestionable
case "e":
return imageRatingExplicit
}
return rating
}
// UserGetter represents a type that can get users from the db.
type UserGetter interface {
GetUserByName(username string) (*User, error)
}
// Shimmie represents an installed shimmie2 project.
type Shimmie struct {
ImagePath string
ThumbPath string
User UserGetter
}
// SCoreLog represents a log message in the shimmie log that is stored in the
// table "score_log".
type SCoreLog struct {
ID int64
DateSent *time.Time
Section string
Username string
Address string
Priority int
Message string
}
// RatedImage represents a shimmie image that also carries information about
// who rated it and when.
type RatedImage struct {
Image
Rater string
RaterIP string
RateDate *time.Time
}
// RateDateFormat returns the RateDate as UTC with Mon 02 Jan 2006 15:04:05 MST
// format.
func (ri RatedImage) RateDateFormat() string {
return ri.RateDate.UTC().Format("Mon 02 Jan 2006 15:04:05 MST")
}
// Image represents a shimmie image.
type Image struct {
ID int64
OwnerID int64
OwnerIP string
Filename string
Filesize int
Hash string
Ext string
Source string
Width int
Height int
Posted *time.Time
Locked string
NumericScore int
Rating string
Favorites int
ParentID int64
HasChildren bool
Author string
Notes int
}
// User represents a shimmie user.
type User struct {
ID int64
Name string
Pass string
JoinDate *time.Time
Admin string
Email string
Class string
}
// Common holds common configuration values.
type Common struct {
Title string
AnalyticsID string
Description string
Keywords string
}
// SiteTitle returns the Title capitalized.
func (c Common) SiteTitle() string {
return strings.Title(c.Title)
}
// TagHistory holds previous tags for an image.
type TagHistory struct {
ID int64
ImageID int64
UserID int64
UserIP string
Tags string
DateSet *time.Time
// Name of the user who did the edit.
Name string
}
// ContributedTagHistory holds previous tags for an image that were set by
// contributors.
type ContributedTagHistory struct {
ID int
ImageID int
OwnerID int
OwnerName string
TaggerID int
TaggerName string
TaggerIP string
Tags string
DateSet *time.Time
}
// Alias is an alias of an old tag to a new tag.
type Alias struct {
OldTag string
NewTag string
}
// Tag is an image's tag.
type Tag struct {
ID int
Tag string
Count int
}
// Autocomplete is the result of searching into tags and tag alias to give
// autocomplete suggestions.
type Autocomplete struct {
Old string `json:"old"`
Name string `json:"name"`
Count int `json:"count"`
}
// PMChoice allows to choose between read and unread private messages.
type PMChoice int
// Possible private message choices.
const (
PMAny PMChoice = iota
PMRead
PMUnread
)
// PM is a private message exchanged between users.
type PM struct {
FromUser string `json:"from_user"`
ToUser string `json:"to_user"`
ID int64 `json:"id"`
FromID int64 `json:"from_id"`
FromIP string `json:"from_ip"`
ToID int64 `json:"to_id"`
SentDate time.Time `json:"sent_date"`
Subject string `json:"subject"`
Message string `json:"message"`
IsRead bool `json:"is_read"`
}
// UserScore can be used to hold user scores like who has uploaded the most
// images and who has edited the most tags.
type UserScore struct {
Score int `json:"score"`
ID int64 `json:"id"`
Name string `json:"name"`
JoinDate *time.Time `json:"join_date"`
Email string `json:"email"`
Class string `json:"class"`
}