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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
package app
import (
"regexp"
"strconv"
"strings"
"time"
"github.com/krazywarez/devianter"
"golang.org/x/net/html"
)
// GRUser renders a group or user page: the about tab, the gallery, or favourites,
// selected by the request's type argument.
func (s skunkyart) GRUser() {
if len(s.Query) < 1 {
s.ReturnHTTPError(400)
return
}
var g devianter.Group
var daError devianter.Error
g.Name = s.Query
var err error
s.Templates.GroupUser.GR, daError, err = g.Get()
try(err)
if daError.RAW != nil {
s.Error(daError)
return
}
group := &s.Templates.GroupUser
switch s.Type {
case 'a':
g := group.GR
s.Atom = false
for _, x := range g.Gruser.Page.Modules {
switch x.Name {
case "about", "group_about":
if g.Owner.Group {
var about = &x.ModuleData.GroupAbout
group.Group = true
group.CreationDate = x.ModuleData.GroupAbout.FoundatedAt.UTC().String()
group.About.DescriptionFormatted = ParseDescription(s.Host, about.Description)
} else if false {
group.About.A = x.ModuleData.About
var about = &group.About.A
group.CreationDate = time.Unix(time.Now().Unix()-x.ModuleData.About.RegDate, 0).UTC().String()
group.About.DescriptionFormatted = ParseDescription(s.Host, about.Description)
for _, val := range x.ModuleData.About.SocialLinks {
var social strings.Builder
social.WriteString(`<a target="_blank" href="`)
social.WriteString(val.Value)
social.WriteString(`">`)
social.WriteString(val.Value)
social.WriteString("</a><br>")
group.About.Social += social.String()
}
for _, val := range x.ModuleData.About.Interests {
var interest strings.Builder
interest.WriteString(val.Label)
interest.WriteString(": <b>")
interest.WriteString(val.Value)
interest.WriteString("</b><br>")
group.About.Interests += interest.String()
}
}
group.About.Comments = s.ParseComments(devianter.GetComments(strconv.Itoa(group.GR.Gruser.ID), "", s.Page, 4))
case "cover_deviation":
group.About.BGMeta = x.ModuleData.CoverDeviation.Deviation
group.About.BGMeta.Url = ConvertDeviantArtURLToSkunkyArt(s.Host, group.About.BGMeta.Url)
group.About.BG = ParseMedia(s.Host, group.About.BGMeta.Media)
case "group_admins":
var htm strings.Builder
for _, z := range x.ModuleData.GroupAdmins.Results {
htm.WriteString(BuildUserPlate(s.Host, z.User.Username))
}
group.Admins += htm.String()
}
}
case 'g', 'f':
var all bool
var content devianter.Group
folderid, _ := strconv.Atoi(s.Args.Get("folder"))
if a := s.Args.Get("all"); a == "true" {
all = true
}
if s.Page == 0 {
s.Page++
}
if s.Type == 'f' {
content, daError = g.Favourites(s.Page, all, folderid)
} else {
content, daError, err = g.Gallery(s.Page, folderid)
try(err)
}
if daError.RAW != nil {
s.Error(daError)
return
}
if folderid > 0 || (s.Type == 'f' && all) {
group.Gallery.List = s.DeviationList(content.Content.Results, true, DeviationList{
More: content.Content.HasMore,
})
} else {
for _, x := range content.Content.Gruser.Page.Modules {
if l := len(x.ModuleData.Folders.Results); l != 0 {
var folders strings.Builder
folders.WriteString(`<h1 id="folders"><a href="#folder">#</a> Folders</h1><div class="folders"><br>`)
for _, x := range x.ModuleData.Folders.Results {
if x.FolderId != -1 && x.Size != 0 {
folders.WriteString(`<div class="block folder-item">`)
if !x.Thumb.NSFW || CFG.Nsfw {
folders.WriteString(`<a href="`)
folders.WriteString(ConvertDeviantArtURLToSkunkyArt(s.Host, x.Thumb.Url))
folders.WriteString(`"><img loading="lazy" src="`)
folders.WriteString(ParseMedia(s.Host, x.Thumb.Media))
folders.WriteString(`" title="`)
folders.WriteString(x.Thumb.Title)
folders.WriteString(`"></a>`)
} else {
folders.WriteString(`<h1>[ <span class="nsfw">NSFW</span> ]</h1>`)
}
folders.WriteString("<br>")
folders.WriteString(`<a href="group_user?folder=`)
folders.WriteString(strconv.Itoa(x.FolderId))
folders.WriteString("&q=")
folders.WriteString(s.Query)
folders.WriteString("&type=")
folders.WriteRune(s.Type)
folders.WriteString(`">`)
folders.WriteString(x.Name)
folders.WriteString(`</a>`)
folders.WriteString("</div>")
}
}
folders.WriteString(`</div><h1 id="content"><a href="#content">#</a> Content</h1>`)
group.Gallery.Folders = folders.String()
}
if x.Name == "folder_deviations" {
group.Gallery.List = s.DeviationList(x.ModuleData.Folder.Deviations, true, DeviationList{
Pages: x.ModuleData.Folder.Pages,
More: x.ModuleData.Folder.HasMore,
})
}
}
}
default:
s.ReturnHTTPError(400)
}
if !s.Atom {
s.ExecuteTemplate("gruser.htm", "html", &s)
}
}
// Deviation renders a single artwork page, with its description, tags, comments
// and related work. It responds 403 for NSFW posts on instances that disallow them.
func (s skunkyart) Deviation(author, postname string) {
idSearch := regexp.MustCompile("[0-9]+").FindAllString(postname, -1)
if len(idSearch) < 1 {
s.ReturnHTTPError(400)
return
}
var err devianter.Error
post := &s.Templates.Deviation
id := idSearch[len(idSearch)-1]
post.Post, err = devianter.GetDeviation(id, author)
if err.RAW != nil {
s.Error(err)
return
}
if post.Post.Deviation.NSFW && !CFG.Nsfw {
s.Writer.WriteHeader(403)
wr(s.Writer, `<html><link rel="stylesheet" href="`+
URLBuilder(s.Host, "stylesheet")+
`" /><h1>NSFW content are disabled on this instance.</h1></html>`)
return
}
if post.Post.Comments.Total <= 50 {
post.Post.Comments.Cursor = ""
}
if post.Post.Deviation.TextContent.Excerpt != "" {
post.Post.Description = ParseDescription(s.Host, post.Post.Deviation.TextContent)
} else {
post.Post.Description = ParseDescription(s.Host, post.Post.Deviation.Extended.DescriptionText)
}
for _, x := range post.Post.Deviation.Extended.RelatedContent {
if len(x.Deviations) != 0 {
post.Related += s.DeviationList(x.Deviations, false)
}
}
// hashtags
for _, x := range post.Post.Deviation.Extended.Tags {
var tag strings.Builder
tag.WriteString(` <a href="`)
tag.WriteString(URLBuilder(s.Host, "search", "?q=", x.Name, "&type=tag"))
tag.WriteString(`">#`)
tag.WriteString(x.Name)
tag.WriteString("</a>")
post.Tags += tag.String()
}
post.Comments = s.ParseComments(devianter.GetComments(id, post.Post.Comments.Cursor, s.Page, 1))
post.StringTime = post.Post.Deviation.PublishedTime.UTC().String()
post.Post.IMG = ParseMedia(s.Host, post.Post.Deviation.Media)
s.ExecuteTemplate("deviantion.htm", "html", &s)
}
// DD renders the Daily Deviations page, including each themed strip.
func (s skunkyart) DD() {
dd, err := devianter.GetDailyDeviations(s.Page)
if err.RAW != nil {
s.Error(err)
return
}
var strips strings.Builder
for _, x := range dd.Strips {
strips.WriteString(`<h3 class="`)
strips.WriteString(x.Codename)
strips.WriteString(`"> <a href="#`)
strips.WriteString(x.Codename)
strips.WriteString(`"># </a>`)
strips.WriteString(x.Title)
strips.WriteString(`</h3>`)
strips.WriteString(s.DeviationList(x.Deviations, false))
}
s.Templates.DDStrips = strips.String()
s.Templates.SomeList = s.DeviationList(dd.Deviations, true, DeviationList{
Pages: 0,
More: dd.HasMore,
})
if !s.Atom {
s.ExecuteTemplate("daily.htm", "html", &s)
}
}
// Search renders search results for the request's query. Group search is scraped
// rather than fetched from the API, which DeviantArt does not expose to guests.
func (s skunkyart) Search() {
if s.Query == "" {
s.ReturnHTTPError(400)
return
}
var err error
var daError devianter.Error
ss := &s.Templates.Search
switch s.Type {
case 'a', 't':
ss.Content, daError, err = devianter.PerformSearch(s.Query, s.Page, s.Type)
case 'g', 'f':
ss.Content, daError, err = devianter.PerformSearch(s.Query, s.Page, s.Type, s.Args.Get("usr"))
case 'r': // scraper, since DeviantArt withholds the guest API for group search
var (
usernames = make(map[int]string)
url strings.Builder
num int
)
s.Page++
url.WriteString("https://www.deviantart.com/groups/?q=")
url.WriteString(s.Query)
if s.Page > 1 {
url.WriteString("&offset=")
url.WriteString(strconv.Itoa(10 * s.Page))
}
dwnld := Download(url.String())
for z := html.NewTokenizer(strings.NewReader(string(dwnld.Body))); ; {
if n, token := z.Next(), z.Token(); n == html.StartTagToken && token.Data == "a" {
for _, x := range token.Attr {
if x.Key == "class" && x.Val == "u regular username" {
usernames[num] = GetValueOfTag(z)
num++
}
}
} else if n == 0 {
break
} else {
continue
}
}
if l := len(usernames); l != 0 {
ss.List += `<div class="content plates">`
for x := range len(usernames) {
ss.List += BuildUserPlate(s.Host, usernames[x])
}
ss.List += `</div>`
ss.List += s.NavBase(DeviationList{
More: true,
})
}
default:
s.ReturnHTTPError(400)
return
}
try(err)
if s.Type != 'r' {
if daError.RAW != nil {
s.Error(daError)
return
}
ss.List = s.DeviationList(ss.Content.Results, false, DeviationList{
Pages: ss.Content.Pages,
More: ss.Content.HasMore,
})
}
s.ExecuteTemplate("search.htm", "html", &s)
}
// Emojitar proxies a user's avatar or emoji image, selected by the request's
// type argument.
func (s skunkyart) Emojitar(name string) {
if name == "" || (s.Type != 'a' && s.Type != 'e') {
s.ReturnHTTPError(400)
return
}
ae, e := devianter.AEmedia(name, s.Type)
if e != nil {
s.ReturnHTTPError(404)
}
wr(s.Writer, ae)
}
|