Commit c48badb79e

c48badb79eb055481d8c9022bcc67dfdf894b87f

parent: f0dfd6c02f

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-22 21:30 UTC

Add Qlty config; split page handlers, parsers, and config setup

ParseDescription renders Draft.js and HTML descriptions in their own
functions. GRUser, Search, DeviationList, NavBase, Handler,
ExecuteConfig, and addInstance move their sections into helpers, and
the group page's template data is a named groupUserPage. Gallery and
favourites fetches sit behind variables like fetchProfile. Output is
unchanged for 3,000 descriptions, 120 group/user pages, 600 lists,
3,000 nav bars, 64 routed requests, and the scraper and INSTANCES.md
row; tests pass with -race and golangci-lint is clean.

Layout: unified · split

.qlty/.gitignore added +7
@@ -0,0 +1,7 @@
1*
2!configs
3!configs/**
4!hooks
5!hooks/**
6!qlty.toml
7!.gitignore
.qlty/qlty.toml added +44
@@ -0,0 +1,44 @@
1config_version = "0"
2
3exclude_patterns = [
4 "**/vendor/**",
5 "**/node_modules/**",
6 "**/testdata/**",
7 "**/dist/**",
8 "**/.build/**",
9 "**/build/**",
10 "**/*.min.*",
11 "**/generated/**",
12 ".claude/**",
13 "**/Pods/**",
14]
15
16test_patterns = [
17 "**/test/**",
18 "**/tests/**",
19 "**/Tests/**",
20 "**/*_test.*",
21 "**/test_*.*",
22 "**/*.test.*",
23 "**/*Tests.swift",
24 "e2e/**",
25]
26
27[[source]]
28name = "default"
29default = true
30
31[[plugin]]
32name = "osv-scanner"
33
34[[plugin]]
35name = "trufflehog"
36
37# Early returns are guard clauses, which keep the happy path unindented.
38[smells.return_statements]
39enabled = false
40
41# Total file complexity is the sum of its functions, which function_complexity
42# already checks.
43[smells.file_complexity]
44enabled = false
app/cli.go +88 −85
@@ -70,22 +70,85 @@ type settings struct {
7070 Settings settingsParams `json:"settings"`
7171}
7272
73func addInstance() {
74 prompt := func(txt string, necessary bool) string {
75 input := bufio.NewScanner(os.Stdin)
76 for {
77 print(txt)
78 print(": ")
79 input.Scan()
80
81 if i := input.Text(); necessary && i == "" {
82 println("Please specify the", txt)
83 } else {
84 return i
85 }
73// promptLine asks for a line on stdin, repeating the question until it gets
74// an answer when necessary is set.
75func promptLine(txt string, necessary bool) string {
76 input := bufio.NewScanner(os.Stdin)
77 for {
78 print(txt)
79 print(": ")
80 input.Scan()
81
82 if i := input.Text(); necessary && i == "" {
83 println("Please specify the", txt)
84 } else {
85 return i
86 }
87 }
88}
89
90// promptInstance asks for this instance's listing details; its settings come
91// from the running configuration.
92func promptInstance() settings {
93 return settings{
94 Title: promptLine("Title", true),
95 Country: promptLine("Country", true),
96 ModifiedSrc: promptLine("Link to modified sources", false),
97 Settings: settingsParams{
98 Nsfw: CFG.Nsfw,
99 Proxy: CFG.Proxy,
100 HideAI: CFG.HideAI,
101 Theme: CFG.Theme,
102 },
103 Urls: settingsUrls{
104 Clearnet: promptLine("Clearnet link", false),
105 Ygg: promptLine("Yggdrasil link", false),
106 Tor: promptLine("Onion link", false),
107 I2P: promptLine("I2P link", false),
108 },
109 }
110}
111
112// instanceMarkdownRow is the INSTANCES.md table row for an instance.
113func instanceMarkdownRow(inst *settings) []byte {
114 var mdstr bytes.Buffer
115
116 mdbuilder := func(yes bool, link string, title string) {
117 switch {
118 case yes && (title != "" && link != ""):
119 mdstr.WriteString("[")
120 mdstr.WriteString(title)
121 mdstr.WriteString("](")
122 mdstr.WriteString(link)
123 mdstr.WriteString(")")
124 case yes && link != "":
125 mdstr.WriteString("[Yes](")
126 mdstr.WriteString(link)
127 mdstr.WriteString(")")
128 case yes:
129 mdstr.WriteString("Yes")
130 default:
131 mdstr.WriteString("No")
86132 }
133 mdstr.WriteString("|")
134 }
135
136 mdstr.WriteString("\n|")
137 mdbuilder(inst.Urls.Clearnet != "", inst.Urls.Clearnet, inst.Title)
138 for _, url := range []string{inst.Urls.Ygg, inst.Urls.I2P, inst.Urls.Tor} {
139 mdbuilder(url != "", url, "")
140 }
141 for _, on := range []bool{inst.Settings.Nsfw, inst.Settings.Proxy} {
142 mdbuilder(on, "", "")
87143 }
144 mdbuilder(inst.ModifiedSrc != "", inst.ModifiedSrc, "")
88145
146 mdstr.WriteString(inst.Country)
147 mdstr.WriteString("|")
148 return mdstr.Bytes()
149}
150
151func addInstance() {
89152 var settingsVar struct {
90153 Instances []settings `json:"instances"`
91154 }
@@ -103,82 +166,22 @@ func addInstance() {
103166 }
104167 defer func() { try(instancesFile.Close()) }()
105168
106 for {
107 if string(instances) == "" {
108 print("\rDownloading instance list...")
109 } else {
110 println("\r\033[2KDownloaded!")
111 try(json.Unmarshal(instances, &settingsVar))
112
113 settingsVar.Instances = append(settingsVar.Instances, settings{
114 Title: prompt("Title", true),
115 Country: prompt("Country", true),
116 ModifiedSrc: prompt("Link to modified sources", false),
117 Settings: settingsParams{
118 Nsfw: CFG.Nsfw,
119 Proxy: CFG.Proxy,
120 HideAI: CFG.HideAI,
121 Theme: CFG.Theme,
122 },
123 Urls: settingsUrls{
124 Clearnet: prompt("Clearnet link", false),
125 Ygg: prompt("Yggdrasil link", false),
126 Tor: prompt("Onion link", false),
127 I2P: prompt("I2P link", false),
128 },
129 })
130
131 j, err := json.MarshalIndent(&settingsVar, "", " ")
132 try(err)
133
134 try(func() error { _, err := instancesJSON.Write(j); return err }())
135
136 settingsVar := &settingsVar.Instances[len(settingsVar.Instances)-1]
137 var mdstr bytes.Buffer
138
139 mdbuilder := func(yes bool, link string, title string) {
140 switch {
141 case yes && (title != "" && link != ""):
142 mdstr.WriteString("[")
143 mdstr.WriteString(title)
144 mdstr.WriteString("](")
145 mdstr.WriteString(link)
146 mdstr.WriteString(")")
147 case yes && link != "":
148 mdstr.WriteString("[Yes](")
149 mdstr.WriteString(link)
150 mdstr.WriteString(")")
151 case yes:
152 mdstr.WriteString("Yes")
153 default:
154 mdstr.WriteString("No")
155 }
156 mdstr.WriteString("|")
157 }
158
159 mdstr.WriteString("\n|")
160 mdbuilder(settingsVar.Urls.Clearnet != "", settingsVar.Urls.Clearnet, settingsVar.Title)
169 for string(instances) == "" {
170 print("\rDownloading instance list...")
171 time.Sleep(500 * time.Millisecond)
172 }
173 println("\r\033[2KDownloaded!")
174 try(json.Unmarshal(instances, &settingsVar))
161175
162 urls := []string{settingsVar.Urls.Ygg, settingsVar.Urls.I2P, settingsVar.Urls.Tor}
163 for i, l := 0, len(urls); i < l; i++ {
164 url := urls[i]
165 mdbuilder(url != "", url, "")
166 }
176 settingsVar.Instances = append(settingsVar.Instances, promptInstance())
167177
168 settings := []bool{settingsVar.Settings.Nsfw, settingsVar.Settings.Proxy}
169 for i, l := 0, len(settings); i < l; i++ {
170 mdbuilder(settings[i], "", "")
171 }
178 j, err := json.MarshalIndent(&settingsVar, "", " ")
179 try(err)
172180
173 mdbuilder(settingsVar.ModifiedSrc != "", settingsVar.ModifiedSrc, "")
181 try(func() error { _, err := instancesJSON.Write(j); return err }())
174182
175 mdstr.WriteString(settingsVar.Country)
176 mdstr.WriteString("|")
183 row := instanceMarkdownRow(&settingsVar.Instances[len(settingsVar.Instances)-1])
184 try(func() error { _, err := instancesFile.Write(row); return err }())
177185
178 try(func() error { _, err := instancesFile.Write(mdstr.Bytes()); return err }())
179 break
180 }
181 time.Sleep(500 * time.Millisecond)
182 }
183186 exit("Done! Now add the files 'instances.json' and 'INSTANCES.md' to the 'main' branch by merge request to https://gitbay.org/krz/skunky-art", 0)
184187}
app/config.go +58 −47
@@ -167,46 +167,13 @@ var cfgExplicit bool
167167// a config that cannot be parsed, that asks for caching without proxying, or
168168// that points caching at a directory this process cannot write.
169169func ExecuteConfig() {
170 f, err := os.ReadFile(CFG.cfg)
171 switch {
172 case err == nil:
173 tryWithExitStatus(json.Unmarshal(f, &CFG), 1)
174 case os.IsNotExist(err) && !cfgExplicit:
175 // The default file is optional: the built-in defaults are a working
176 // instance. A path given with -c is not, since a typo there would
177 // otherwise start something the operator did not configure.
178 println("no", CFG.cfg, "found; running with the built-in defaults")
179 default:
180 tryWithExitStatus(err, 1)
181 }
170 readConfigFile()
182171
183172 if CFG.Cache.Enabled && !CFG.Proxy {
184173 exit("Incompatible settings detected: cannot use caching media content without proxy", 1)
185174 }
186
187175 if CFG.Cache.Enabled {
188 if err := checkCacheWritable(CFG.Cache.Path); err != nil {
189 exit("Cache directory is not writable by this process (uid "+
190 strconv.Itoa(os.Getuid())+"): "+err.Error()+
191 "\nGrant that uid write access to the directory, or set cache.enabled to false."+
192 "\nThe official container image runs as uid 10000, so a bind-mounted cache needs:"+
193 "\n chown -R 10000:10000 <cache dir on the host>", 1)
194 }
195
196 if CFG.Cache.Lifetime != "" {
197 d, err := parseLifetime(CFG.Cache.Lifetime)
198 if err != nil {
199 exit("config: cache.lifetime: "+err.Error(), 1)
200 }
201 lifetimeParsed = d.Milliseconds()
202 }
203 // max-size is documented in megabytes. This was 1024^2, which in Go is
204 // XOR (1026), not exponentiation — so the cap was ~1000x too small.
205 CFG.Cache.MaxSize *= 1024 * 1024
206 go InitCacheSystem()
207 if CFG.Cache.MemCache {
208 go InitMemCacheJanitor()
209 }
176 setupMediaCache()
210177 }
211178
212179 About = instanceAbout{
@@ -225,18 +192,7 @@ func ExecuteConfig() {
225192 }
226193
227194 if CFG.APICache.Enabled {
228 d, err := parseLifetime(CFG.APICache.TTL)
229 if err != nil {
230 exit("config: api-cache.ttl: "+err.Error(), 1)
231 }
232 apiCacheTTL = d
233 if CFG.APICache.Stale != "" {
234 d, err := parseLifetime(CFG.APICache.Stale)
235 if err != nil {
236 exit("config: api-cache.stale: "+err.Error(), 1)
237 }
238 apiCacheStale = d
239 }
195 setupAPICache()
240196 }
241197
242198 // per-minute 0 turns the limit off; a burst below one token would
@@ -254,6 +210,61 @@ func ExecuteConfig() {
254210 devianter.UserAgent = CFG.UserAgent
255211}
256212
213func readConfigFile() {
214 f, err := os.ReadFile(CFG.cfg)
215 switch {
216 case err == nil:
217 tryWithExitStatus(json.Unmarshal(f, &CFG), 1)
218 case os.IsNotExist(err) && !cfgExplicit:
219 // The default file is optional: the built-in defaults are a working
220 // instance. A path given with -c is not, since a typo there would
221 // otherwise start something the operator did not configure.
222 println("no", CFG.cfg, "found; running with the built-in defaults")
223 default:
224 tryWithExitStatus(err, 1)
225 }
226}
227
228func setupMediaCache() {
229 if err := checkCacheWritable(CFG.Cache.Path); err != nil {
230 exit("Cache directory is not writable by this process (uid "+
231 strconv.Itoa(os.Getuid())+"): "+err.Error()+
232 "\nGrant that uid write access to the directory, or set cache.enabled to false."+
233 "\nThe official container image runs as uid 10000, so a bind-mounted cache needs:"+
234 "\n chown -R 10000:10000 <cache dir on the host>", 1)
235 }
236
237 if CFG.Cache.Lifetime != "" {
238 d, err := parseLifetime(CFG.Cache.Lifetime)
239 if err != nil {
240 exit("config: cache.lifetime: "+err.Error(), 1)
241 }
242 lifetimeParsed = d.Milliseconds()
243 }
244 // max-size is documented in megabytes. This was 1024^2, which in Go is
245 // XOR (1026), not exponentiation — so the cap was ~1000x too small.
246 CFG.Cache.MaxSize *= 1024 * 1024
247 go InitCacheSystem()
248 if CFG.Cache.MemCache {
249 go InitMemCacheJanitor()
250 }
251}
252
253func setupAPICache() {
254 d, err := parseLifetime(CFG.APICache.TTL)
255 if err != nil {
256 exit("config: api-cache.ttl: "+err.Error(), 1)
257 }
258 apiCacheTTL = d
259 if CFG.APICache.Stale != "" {
260 d, err := parseLifetime(CFG.APICache.Stale)
261 if err != nil {
262 exit("config: api-cache.stale: "+err.Error(), 1)
263 }
264 apiCacheStale = d
265 }
266}
267
257268// forcedThemeCSS returns a block that pins the palette when the instance has
258269// chosen a theme, or "" for "auto". Light repeats what the prefers-color-scheme
259270// block already holds; dark repeats :root. Both are emitted after the
app/parsers.go +367 −304
@@ -110,7 +110,8 @@ func (s skunkyart) DeviationList(devs []devianter.Deviation, allowAtom bool, con
110110 return ""
111111 }
112112
113 var list, listContent strings.Builder
113 atom := allowAtom && s.Atom
114 var listContent strings.Builder
114115 var newest time.Time // the latest entry, for the feed's own <updated>
115116
116117 for i, l := 0, len(devs); i < l; i++ {
@@ -118,129 +119,156 @@ func (s skunkyart) DeviationList(devs []devianter.Deviation, allowAtom bool, con
118119 if !VisibleDeviation(data) {
119120 continue
120121 }
121 // Escaped once here: the same values go into both the HTML grid and the
122 // Atom feed, and html.EscapeString produces entities XML accepts too.
123 author, title := esc(data.Author.Username), esc(data.Title)
124 postURL := esc(ConvertDeviantArtURLToSkunkyArt(s.Host, data.Url))
125 if preview, fullview := esc(ParseMedia(s.Host, data.Media, 320)), esc(ParseMedia(s.Host, data.Media)); true {
126 if allowAtom && s.Atom {
127 s.Writer.Header().Add("Content-Type", "application/atom+xml")
128 // The entry id is the post's URL here: Atom wants an IRI, and a
129 // bare number is not one. Timestamps are RFC 3339, the only form
130 // the format allows.
131 entryURL := esc(URLBuilder(s.Host, "post", data.Author.Username, "atom-"+strconv.Itoa(data.ID)))
132 published := data.PublishedTime.UTC()
133 if published.After(newest) {
134 newest = published
135 }
136 listContent.WriteString(`<entry><author><name>`)
137 listContent.WriteString(author)
138 listContent.WriteString(`</name></author><title>`)
139 listContent.WriteString(title)
140 listContent.WriteString(`</title><link rel="alternate" type="text/html" href="`)
141 listContent.WriteString(entryURL)
142 listContent.WriteString(`"/><id>`)
143 listContent.WriteString(entryURL)
144 listContent.WriteString(`</id><published>`)
145 listContent.WriteString(published.Format(time.RFC3339))
146 listContent.WriteString(`</published><updated>`)
147 listContent.WriteString(published.Format(time.RFC3339))
148 listContent.WriteString(`</updated>`)
149 listContent.WriteString(`<media:group><media:title>`)
150 listContent.WriteString(title)
151 listContent.WriteString(`</media:title><media:thumbnail url="`)
152 listContent.WriteString(preview)
153 listContent.WriteString(`"/></media:group><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><a href="`)
154 listContent.WriteString(postURL)
155 listContent.WriteString(`"><img src="`)
156 listContent.WriteString(fullview)
157 listContent.WriteString(`"/></a><p>`)
158 listContent.WriteString(ParseDescription(s.Host, data.TextContent))
159 listContent.WriteString(`</p></div></content></entry>`)
160 } else {
161 listContent.WriteString(`<div class="block">`)
162 if fullview != "" && preview != "" {
163 listContent.WriteString(`<a title="` + esc(T(s.Lang, "deviation.open")) + `" href="`)
164 listContent.WriteString(fullview)
165 listContent.WriteString(`"><img loading="lazy" src="`)
166 listContent.WriteString(preview)
167 listContent.WriteString(`" width="15%" alt="`)
168 listContent.WriteString(author)
169 listContent.WriteString(" - ")
170 listContent.WriteString(title)
171 listContent.WriteString(`"></a>`)
172 } else {
173 listContent.WriteString("<h1>[ " + esc(T(s.Lang, "list.text")) + " ]</h1>")
174 }
175 listContent.WriteString(`<br><a href="`)
176 listContent.WriteString(postURL)
177 listContent.WriteString(`">`)
178 listContent.WriteString(author)
179 listContent.WriteString(" - ")
180 listContent.WriteString(title)
181
182 if data.NSFW {
183 listContent.WriteString(` [<span class="nsfw">NSFW</span>]`)
184 }
185 if data.AI {
186 listContent.WriteString(" [🤖]")
187 }
188 if data.DD {
189 listContent.WriteString(` [<span class="dd">DD</span>]`)
190 }
191
192 listContent.WriteString("</a></div>")
122 item := s.listItem(data)
123 if atom {
124 s.Writer.Header().Add("Content-Type", "application/atom+xml")
125 if published := s.writeAtomEntry(&listContent, data, item); published.After(newest) {
126 newest = published
193127 }
128 } else {
129 s.writeGridEntry(&listContent, data, item)
194130 }
195131 }
196132
197 if allowAtom && s.Atom {
198 list.WriteString(`<?xml version="1.0" encoding="UTF-8"?><feed xmlns:media="http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom">`)
199
200 list.WriteString(`<title>`)
201 switch {
202 case s.Type == 0:
203 list.WriteString("Daily Deviations")
204 case s.Type == 'g' && len(devs) != 0:
205 list.WriteString(esc(devs[0].Author.Username))
206 default:
207 list.WriteString("SkunkyArt")
208 }
209 list.WriteString(`</title>`)
133 if atom {
134 feed := s.atomFeed(devs, listContent.String(), newest)
135 wr(s.Writer, feed)
136 return feed
137 }
210138
211 // Atom requires a feed id and updated time; readers reject a feed
212 // without them. The id is the feed's own URL on this instance.
213 feedURL := esc(s.Host + s._pth + "?" + s.Args.Encode())
214 if newest.IsZero() {
215 newest = time.Now().UTC()
216 }
217 list.WriteString(`<id>`)
218 list.WriteString(feedURL)
219 list.WriteString(`</id><updated>`)
220 list.WriteString(newest.Format(time.RFC3339))
221 list.WriteString(`</updated><link rel="self" type="application/atom+xml" href="`)
222 list.WriteString(feedURL)
223 list.WriteString(`"/>`)
224
225 list.WriteString(`<link rel="alternate" href="`)
226 list.WriteString(esc(s.Host))
227 list.WriteString(`"/>`)
228
229 list.WriteString(listContent.String())
230
231 list.WriteString("</feed>")
232 wr(s.Writer, list.String())
139 var list strings.Builder
140 list.WriteString(`<div class="content">`)
141 list.WriteString(listContent.String())
142 list.WriteString("</div>")
143 if content != nil {
144 list.WriteString(s.NavBase(content[0]))
145 }
146 return list.String()
147}
148
149// listEntry holds one deviation's values for a list, escaped once: the same
150// values go into both the HTML grid and the Atom feed, and html.EscapeString
151// produces entities XML accepts too.
152type listEntry struct {
153 author, title, postURL, preview, fullview string
154}
155
156func (s skunkyart) listItem(data *devianter.Deviation) listEntry {
157 return listEntry{
158 author: esc(data.Author.Username),
159 title: esc(data.Title),
160 postURL: esc(ConvertDeviantArtURLToSkunkyArt(s.Host, data.Url)),
161 preview: esc(ParseMedia(s.Host, data.Media, 320)),
162 fullview: esc(ParseMedia(s.Host, data.Media)),
163 }
164}
165
166// writeAtomEntry writes one feed entry and returns its published time.
167func (s skunkyart) writeAtomEntry(b *strings.Builder, data *devianter.Deviation, item listEntry) time.Time {
168 // The entry id is the post's URL here: Atom wants an IRI, and a
169 // bare number is not one. Timestamps are RFC 3339, the only form
170 // the format allows.
171 entryURL := esc(URLBuilder(s.Host, "post", data.Author.Username, "atom-"+strconv.Itoa(data.ID)))
172 published := data.PublishedTime.UTC()
173 b.WriteString(`<entry><author><name>`)
174 b.WriteString(item.author)
175 b.WriteString(`</name></author><title>`)
176 b.WriteString(item.title)
177 b.WriteString(`</title><link rel="alternate" type="text/html" href="`)
178 b.WriteString(entryURL)
179 b.WriteString(`"/><id>`)
180 b.WriteString(entryURL)
181 b.WriteString(`</id><published>`)
182 b.WriteString(published.Format(time.RFC3339))
183 b.WriteString(`</published><updated>`)
184 b.WriteString(published.Format(time.RFC3339))
185 b.WriteString(`</updated>`)
186 b.WriteString(`<media:group><media:title>`)
187 b.WriteString(item.title)
188 b.WriteString(`</media:title><media:thumbnail url="`)
189 b.WriteString(item.preview)
190 b.WriteString(`"/></media:group><content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><a href="`)
191 b.WriteString(item.postURL)
192 b.WriteString(`"><img src="`)
193 b.WriteString(item.fullview)
194 b.WriteString(`"/></a><p>`)
195 b.WriteString(ParseDescription(s.Host, data.TextContent))
196 b.WriteString(`</p></div></content></entry>`)
197 return published
198}
199
200func (s skunkyart) writeGridEntry(b *strings.Builder, data *devianter.Deviation, item listEntry) {
201 b.WriteString(`<div class="block">`)
202 if item.fullview != "" && item.preview != "" {
203 b.WriteString(`<a title="` + esc(T(s.Lang, "deviation.open")) + `" href="`)
204 b.WriteString(item.fullview)
205 b.WriteString(`"><img loading="lazy" src="`)
206 b.WriteString(item.preview)
207 b.WriteString(`" width="15%" alt="`)
208 b.WriteString(item.author)
209 b.WriteString(" - ")
210 b.WriteString(item.title)
211 b.WriteString(`"></a>`)
233212 } else {
234 list.WriteString(`<div class="content">`)
213 b.WriteString("<h1>[ " + esc(T(s.Lang, "list.text")) + " ]</h1>")
214 }
215 b.WriteString(`<br><a href="`)
216 b.WriteString(item.postURL)
217 b.WriteString(`">`)
218 b.WriteString(item.author)
219 b.WriteString(" - ")
220 b.WriteString(item.title)
221
222 if data.NSFW {
223 b.WriteString(` [<span class="nsfw">NSFW</span>]`)
224 }
225 if data.AI {
226 b.WriteString(" [🤖]")
227 }
228 if data.DD {
229 b.WriteString(` [<span class="dd">DD</span>]`)
230 }
235231
236 list.WriteString(listContent.String())
232 b.WriteString("</a></div>")
233}
237234
238 list.WriteString("</div>")
239 if content != nil {
240 list.WriteString(s.NavBase(content[0]))
241 }
235// atomFeed wraps the entries in an Atom feed for this request.
236func (s skunkyart) atomFeed(devs []devianter.Deviation, entries string, newest time.Time) string {
237 var list strings.Builder
238 list.WriteString(`<?xml version="1.0" encoding="UTF-8"?><feed xmlns:media="http://search.yahoo.com/mrss/" xmlns="http://www.w3.org/2005/Atom">`)
239
240 list.WriteString(`<title>`)
241 switch {
242 case s.Type == 0:
243 list.WriteString("Daily Deviations")
244 case s.Type == 'g' && len(devs) != 0:
245 list.WriteString(esc(devs[0].Author.Username))
246 default:
247 list.WriteString("SkunkyArt")
242248 }
249 list.WriteString(`</title>`)
243250
251 // Atom requires a feed id and updated time; readers reject a feed
252 // without them. The id is the feed's own URL on this instance.
253 feedURL := esc(s.Host + s._pth + "?" + s.Args.Encode())
254 if newest.IsZero() {
255 newest = time.Now().UTC()
256 }
257 list.WriteString(`<id>`)
258 list.WriteString(feedURL)
259 list.WriteString(`</id><updated>`)
260 list.WriteString(newest.Format(time.RFC3339))
261 list.WriteString(`</updated><link rel="self" type="application/atom+xml" href="`)
262 list.WriteString(feedURL)
263 list.WriteString(`"/>`)
264
265 list.WriteString(`<link rel="alternate" href="`)
266 list.WriteString(esc(s.Host))
267 list.WriteString(`"/>`)
268
269 list.WriteString(entries)
270
271 list.WriteString("</feed>")
244272 return list.String()
245273}
246274
@@ -285,206 +313,241 @@ func ParseDescription(host string, dscr devianter.Text) string {
285313 return renderDocument(host, doc)
286314 }
287315
316 description, dl := dscr.Html.Markup, len(dscr.Html.Markup)
317 if dl != 0 && description[0] == '{' && description[dl-1] == '}' {
318 return renderDraftJS(host, description)
319 }
320 if dl != 0 {
321 return renderMarkupHTML(host, description)
322 }
323 return ""
324}
325
326// tagBuilder wraps content in each tag in turn, innermost first.
327func tagBuilder(content string, tags ...string) string {
328 for _, tag := range tags {
329 var htm strings.Builder
330 htm.WriteString("<")
331 htm.WriteString(tag)
332 htm.WriteString(">")
333 htm.WriteString(content)
334 htm.WriteString("</")
335 htm.WriteString(tag)
336 htm.WriteString(">")
337 content = htm.String()
338 }
339 return content
340}
341
342type draftBlock struct {
343 Text string `json:"text"`
344 Type string `json:"type"`
345 InlineStyleRanges []struct {
346 Offset int `json:"offset"`
347 Length int `json:"length"`
348 Style string `json:"style"`
349 } `json:"inlineStyleRanges"`
350 EntityRanges []struct {
351 Offset int `json:"offset"`
352 Length int `json:"length"`
353 Key int `json:"key"`
354 } `json:"entityRanges"`
355 Data struct {
356 TextAlignment string `json:"textAlignment"`
357 } `json:"data"`
358}
359
360type draftDescription struct {
361 Blocks []draftBlock `json:"blocks"`
362 EntityMap map[string]struct {
363 Type string `json:"type"`
364 Data struct {
365 URL string `json:"url"`
366 Config struct {
367 // "aligment" is DeviantArt's own spelling; do not correct it.
368 Aligment string `json:"aligment"`
369 Width int `json:"width"`
370 } `json:"config"`
371 Data devianter.Deviation `json:"data"`
372 } `json:"data"`
373 } `json:"entityMap"`
374}
375
376// renderDraftJS renders the older Draft.js description JSON.
377func renderDraftJS(host, description string) string {
378 var descr draftDescription
379 e := json.Unmarshal([]byte(description), &descr)
380 try(e)
381
382 entities := make(map[int]devianter.Deviation)
383 urls := make(map[int]string)
384 for n, x := range descr.EntityMap {
385 num, _ := strconv.Atoi(n)
386 if x.Data.URL != "" {
387 urls[num] = deleteTrackingFromURL(x.Data.URL)
388 }
389 entities[num] = x.Data.Data
390 }
391
288392 var parsedDescription strings.Builder
289 TagBuilder := func(content string, tags ...string) string {
290 l := len(tags)
291 for x := range l {
292 var htm strings.Builder
293 htm.WriteString("<")
294 htm.WriteString(tags[x])
295 htm.WriteString(">")
296
297 htm.WriteString(content)
298
299 htm.WriteString("</")
300 htm.WriteString(tags[x])
301 htm.WriteString(">")
302 content = htm.String()
393 for _, x := range descr.Blocks {
394 styles := draftStyles(x)
395 switch x.Type {
396 case "atomic":
397 if len(x.EntityRanges) != 0 {
398 writeDraftArtwork(&parsedDescription, host, entities[x.EntityRanges[0].Key])
399 }
400 case "unstyled":
401 writeDraftText(&parsedDescription, x, styles, urls)
303402 }
304 return content
403 parsedDescription.WriteString("<br>")
305404 }
306 DeleteTrackingFromURL := deleteTrackingFromURL
307
308 if description, dl := dscr.Html.Markup, len(dscr.Html.Markup); dl != 0 &&
309 description[0] == '{' &&
310 description[dl-1] == '}' {
311 var descr struct {
312 Blocks []struct {
313 Text string `json:"text"`
314 Type string `json:"type"`
315 InlineStyleRanges []struct {
316 Offset int `json:"offset"`
317 Length int `json:"length"`
318 Style string `json:"style"`
319 } `json:"inlineStyleRanges"`
320 EntityRanges []struct {
321 Offset int `json:"offset"`
322 Length int `json:"length"`
323 Key int `json:"key"`
324 } `json:"entityRanges"`
325 Data struct {
326 TextAlignment string `json:"textAlignment"`
327 } `json:"data"`
328 } `json:"blocks"`
329 EntityMap map[string]struct {
330 Type string `json:"type"`
331 Data struct {
332 URL string `json:"url"`
333 Config struct {
334 // "aligment" is DeviantArt's own spelling; do not correct it.
335 Aligment string `json:"aligment"`
336 Width int `json:"width"`
337 } `json:"config"`
338 Data devianter.Deviation `json:"data"`
339 } `json:"data"`
340 } `json:"entityMap"`
405 return parsedDescription.String()
406}
407
408// draftStyles renders each inline style range of a block as tagged text.
409func draftStyles(x draftBlock) []text {
410 styles := make([]text, len(x.InlineStyleRanges))
411 if len(x.InlineStyleRanges) == 0 {
412 return styles
413 }
414 var tags = make(map[int][]string)
415 for n, rngs := range x.InlineStyleRanges {
416 style := &styles[n]
417 switch rngs.Style {
418 case "BOLD":
419 rngs.Style = "b"
420 case "UNDERLINE":
421 rngs.Style = "u"
422 case "ITALIC":
423 rngs.Style = "i"
341424 }
342 e := json.Unmarshal([]byte(description), &descr)
343 try(e)
344
345 entities := make(map[int]devianter.Deviation)
346 urls := make(map[int]string)
347 for n, x := range descr.EntityMap {
348 num, _ := strconv.Atoi(n)
349 if x.Data.URL != "" {
350 urls[num] = DeleteTrackingFromURL(x.Data.URL)
351 }
352 entities[num] = x.Data.Data
425 style.From = rngs.Offset
426 style.To = rngs.Offset + rngs.Length
427 ft := style.From * style.To
428 tags[ft] = append(tags[ft], rngs.Style)
429 }
430 for n := range styles {
431 style := &styles[n]
432 style.TxtRaw = x.Text[style.From:style.To]
433 style.Txt = tagBuilder(esc(style.TxtRaw), tags[style.From*style.To]...)
434 }
435 return styles
436}
437
438// writeDraftArtwork writes an embedded deviation as a linked thumbnail.
439func writeDraftArtwork(b *strings.Builder, host string, d devianter.Deviation) {
440 b.WriteString(`<a href="`)
441 b.WriteString(esc(ConvertDeviantArtURLToSkunkyArt(host, d.Url)))
442 b.WriteString(`"><img width="50%" src="`)
443 b.WriteString(esc(ParseMedia(host, d.Media)))
444 b.WriteString(`" alt="`)
445 b.WriteString(esc(d.Author.Username))
446 b.WriteString(" - ")
447 b.WriteString(esc(d.Title))
448 b.WriteString(`" title="`)
449 b.WriteString(esc(d.Author.Username))
450 b.WriteString(" - ")
451 b.WriteString(esc(d.Title))
452 b.WriteString(`"></a>`)
453}
454
455// writeDraftText writes an unstyled block with its styled ranges and link.
456func writeDraftText(b *strings.Builder, x draftBlock, styles []text, urls map[int]string) {
457 l := len(styles)
458 if l == 0 {
459 b.WriteString(esc(x.Text))
460 return
461 }
462 for n, r := range styles {
463 var tag string
464 if x.Type == "header-two" {
465 tag = "h2"
353466 }
354467
355 for _, x := range descr.Blocks {
356 Styles := make([]text, len(x.InlineStyleRanges))
357
358 if len(x.InlineStyleRanges) != 0 {
359 var tags = make(map[int][]string)
360 for n, rngs := range x.InlineStyleRanges {
361 Styles := &Styles[n]
362 switch rngs.Style {
363 case "BOLD":
364 rngs.Style = "b"
365 case "UNDERLINE":
366 rngs.Style = "u"
367 case "ITALIC":
368 rngs.Style = "i"
369 }
370 Styles.From = rngs.Offset
371 Styles.To = rngs.Offset + rngs.Length
372 FT := Styles.From * Styles.To
373 tags[FT] = append(tags[FT], rngs.Style)
374 }
375 for n := range Styles {
376 Styles := &Styles[n]
377 Styles.TxtRaw = x.Text[Styles.From:Styles.To]
378 Styles.Txt = TagBuilder(esc(Styles.TxtRaw), tags[Styles.From*Styles.To]...)
379 }
380 }
468 b.WriteString(esc(x.Text[:r.From]))
469 if len(urls) != 0 && len(x.EntityRanges) != 0 {
470 ra := &x.EntityRanges[0]
471
472 b.WriteString(`<a target="_blank" href="`)
473 b.WriteString(esc(urls[ra.Key]))
474 b.WriteString(`">`)
475 b.WriteString(r.Txt)
476 b.WriteString(`</a>`)
477 } else if l > n+1 {
478 b.WriteString(r.Txt)
479 }
480 b.WriteString(tagBuilder(tag, esc(x.Text[r.To:])))
481 }
482}
381483
382 switch x.Type {
383 case "atomic":
384 if len(x.EntityRanges) != 0 {
385 d := entities[x.EntityRanges[0].Key]
386 parsedDescription.WriteString(`<a href="`)
387 parsedDescription.WriteString(esc(ConvertDeviantArtURLToSkunkyArt(host, d.Url)))
388 parsedDescription.WriteString(`"><img width="50%" src="`)
389 parsedDescription.WriteString(esc(ParseMedia(host, d.Media)))
390 parsedDescription.WriteString(`" alt="`)
391 parsedDescription.WriteString(esc(d.Author.Username))
392 parsedDescription.WriteString(" - ")
393 parsedDescription.WriteString(esc(d.Title))
394 parsedDescription.WriteString(`" title="`)
395 parsedDescription.WriteString(esc(d.Author.Username))
396 parsedDescription.WriteString(" - ")
397 parsedDescription.WriteString(esc(d.Title))
398 parsedDescription.WriteString(`"></a>`)
399 }
400 case "unstyled":
401 if l := len(Styles); l != 0 {
402 for n, r := range Styles {
403 var tag string
404 if x.Type == "header-two" {
405 tag = "h2"
406 }
407
408 parsedDescription.WriteString(esc(x.Text[:r.From]))
409 if len(urls) != 0 && len(x.EntityRanges) != 0 {
410 ra := &x.EntityRanges[0]
411
412 parsedDescription.WriteString(`<a target="_blank" href="`)
413 parsedDescription.WriteString(esc(urls[ra.Key]))
414 parsedDescription.WriteString(`">`)
415 parsedDescription.WriteString(r.Txt)
416 parsedDescription.WriteString(`</a>`)
417 } else if l > n+1 {
418 parsedDescription.WriteString(r.Txt)
419 }
420 parsedDescription.WriteString(TagBuilder(tag, esc(x.Text[r.To:])))
421 }
422 } else {
423 parsedDescription.WriteString(esc(x.Text))
424 }
425 }
426 parsedDescription.WriteString("<br>")
484// renderMarkupHTML renders plain HTML markup, keeping links, DeviantArt
485// emoticons, and a few bare formatting tags.
486func renderMarkupHTML(host, markup string) string {
487 var parsedDescription strings.Builder
488 for tt := html.NewTokenizer(strings.NewReader(markup)); ; {
489 switch tt.Next() {
490 case html.ErrorToken:
491 return parsedDescription.String()
492 case html.CommentToken, html.DoctypeToken:
493 // No renderable content; skip.
494 case html.StartTagToken, html.EndTagToken, html.SelfClosingTagToken:
495 writeMarkupTag(&parsedDescription, host, tt, tt.Token())
496 case html.TextToken:
497 parsedDescription.WriteString(esc(string(tt.Text())))
427498 }
428 } else if dl != 0 {
429 for tt := html.NewTokenizer(strings.NewReader(dscr.Html.Markup)); ; {
430 switch tt.Next() {
431 case html.ErrorToken:
432 return parsedDescription.String()
433 case html.CommentToken, html.DoctypeToken:
434 // No renderable content; skip.
435 case html.StartTagToken, html.EndTagToken, html.SelfClosingTagToken:
436 token := tt.Token()
437 switch token.Data {
438 case "a":
439 for _, a := range token.Attr {
440 if a.Key == "href" {
441 url := DeleteTrackingFromURL(a.Val)
442 parsedDescription.WriteString(`<a target="_blank" href="`)
443 parsedDescription.WriteString(esc(url))
444 parsedDescription.WriteString(`">`)
445 parsedDescription.WriteString(esc(GetValueOfTag(tt)))
446 parsedDescription.WriteString("</a> ")
447 }
448 }
449 case "img":
450 // Only DeviantArt's emoticons are carried over, served
451 // through this instance; any other image is dropped.
452 var uri, title string
453 for _, a := range token.Attr {
454 switch a.Key {
455 case "src":
456 uri = emoticonURL(host, a.Val)
457 case "title":
458 title = a.Val
459 }
460 }
461 if uri != "" {
462 parsedDescription.WriteString(`<img src="`)
463 parsedDescription.WriteString(esc(uri))
464 parsedDescription.WriteString(`" alt="`)
465 parsedDescription.WriteString(esc(title))
466 parsedDescription.WriteString(`" title="`)
467 parsedDescription.WriteString(esc(title))
468 parsedDescription.WriteString(`">`)
469 }
470 case "br", "li", "ul", "p", "b":
471 // The bare tag, not token.String(): that would carry over
472 // whatever attributes DeviantArt's markup put on it.
473 if token.Type == html.EndTagToken {
474 parsedDescription.WriteString("</")
475 } else {
476 parsedDescription.WriteString("<")
477 }
478 parsedDescription.WriteString(token.Data)
479 parsedDescription.WriteString(">")
480 case "div":
481 parsedDescription.WriteString("<p> ")
482 }
483 case html.TextToken:
484 parsedDescription.WriteString(esc(string(tt.Text())))
499 }
500}
501
502func writeMarkupTag(b *strings.Builder, host string, tt *html.Tokenizer, token html.Token) {
503 switch token.Data {
504 case "a":
505 for _, a := range token.Attr {
506 if a.Key == "href" {
507 url := deleteTrackingFromURL(a.Val)
508 b.WriteString(`<a target="_blank" href="`)
509 b.WriteString(esc(url))
510 b.WriteString(`">`)
511 b.WriteString(esc(GetValueOfTag(tt)))
512 b.WriteString("</a> ")
485513 }
486514 }
515 case "img":
516 writeEmoticon(b, host, token)
517 case "br", "li", "ul", "p", "b":
518 // The bare tag, not token.String(): that would carry over
519 // whatever attributes DeviantArt's markup put on it.
520 if token.Type == html.EndTagToken {
521 b.WriteString("</")
522 } else {
523 b.WriteString("<")
524 }
525 b.WriteString(token.Data)
526 b.WriteString(">")
527 case "div":
528 b.WriteString("<p> ")
487529 }
530}
488531
489 return parsedDescription.String()
532// writeEmoticon carries over DeviantArt's emoticons, served through this
533// instance; any other image is dropped.
534func writeEmoticon(b *strings.Builder, host string, token html.Token) {
535 var uri, title string
536 for _, a := range token.Attr {
537 switch a.Key {
538 case "src":
539 uri = emoticonURL(host, a.Val)
540 case "title":
541 title = a.Val
542 }
543 }
544 if uri != "" {
545 b.WriteString(`<img src="`)
546 b.WriteString(esc(uri))
547 b.WriteString(`" alt="`)
548 b.WriteString(esc(title))
549 b.WriteString(`" title="`)
550 b.WriteString(esc(title))
551 b.WriteString(`">`)
552 }
490553}
app/router.go +174 −150
@@ -40,178 +40,202 @@ func Router() {
4040 tryWithExitStatus(srv.ListenAndServe(), 1)
4141}
4242
43// Handler returns the single catch-all handler that dispatches every path.
44func Handler() http.HandlerFunc {
45 parsepath := func(path string) map[int]string {
46 if l := len(CFG.URI); len(path) > l {
47 path = path[l-1:]
48 } else {
49 path = "/"
50 }
43// parsePath splits a request path below CFG.URI into its segments.
44func parsePath(path string) map[int]string {
45 if l := len(CFG.URI); len(path) > l {
46 path = path[l-1:]
47 } else {
48 path = "/"
49 }
5150
52 parsedpath := make(map[int]string)
53 for x := 0; true; x++ {
54 slash := strings.Index(path, "/") + 1
55 content := path[:slash]
56 path = path[slash:]
57 if slash == 0 {
58 parsedpath[x] = path
59 break
60 }
61 parsedpath[x] = content[:slash-1]
51 parsedpath := make(map[int]string)
52 for x := 0; true; x++ {
53 slash := strings.Index(path, "/") + 1
54 content := path[:slash]
55 path = path[slash:]
56 if slash == 0 {
57 parsedpath[x] = path
58 break
6259 }
63 return parsedpath
60 parsedpath[x] = content[:slash-1]
6461 }
62 return parsedpath
63}
6564
66 next := func(path map[int]string, from int) string {
67 var out strings.Builder
68 for x, l := from, len(path)-1; x <= l; x++ {
69 out.WriteString(path[x])
70 if x != l {
71 out.WriteString("/")
72 }
65// joinPath rejoins the path segments from index from onward.
66func joinPath(path map[int]string, from int) string {
67 var out strings.Builder
68 for x, l := from, len(path)-1; x <= l; x++ {
69 out.WriteString(path[x])
70 if x != l {
71 out.WriteString("/")
7372 }
74 return out.String()
7573 }
74 return out.String()
75}
7676
77 open := func(name string) []byte {
78 file, err := static.Templates.Open(name)
79 if err != nil {
80 try(err)
81 return nil
82 }
83 defer func() { try(file.Close()) }()
77// openStatic reads an embedded static file.
78func openStatic(name string) []byte {
79 file, err := static.Templates.Open(name)
80 if err != nil {
81 try(err)
82 return nil
83 }
84 defer func() { try(file.Close()) }()
8485
85 fileReaded, err := io.ReadAll(file)
86 if err != nil {
87 try(err)
88 return nil
89 }
90 return fileReaded
86 fileReaded, err := io.ReadAll(file)
87 if err != nil {
88 try(err)
89 return nil
9190 }
91 return fileReaded
92}
9293
94// Handler returns the single catch-all handler that dispatches every path.
95func Handler() http.HandlerFunc {
9396 // the function that drives everything
9497 return func(w http.ResponseWriter, r *http.Request) {
95 path := parsepath(r.URL.Path)
96
97 // Per-request, not a package global: requests arrive concurrently on
98 // different hosts and ports (bots hitting a proxy's alternate ports, for
99 // one), and a shared global lets one request's host leak into another's
100 // rendered URLs. Those URLs then point at a different origin, which this
101 // handler's own default-src 'self' CSP blocks.
102 host := "http://" + r.Host
103 if h := r.Header["X-Forwarded-Proto"]; len(h) != 0 && h[0] == "https" {
104 host = "https://" + r.Host
98 path := parsePath(r.URL.Path)
99 skunky := newSkunkyart(w, r, path[1])
100 skunky.API.main = &skunky
101 setPageHeaders(w)
102
103 if daLimiter != nil && limited(skunky.Endpoint) && !daLimiter.allow(clientAddr(r)) {
104 w.Header().Set("Retry-After", "60")
105 skunky.ReturnHTTPError(http.StatusTooManyRequests)
106 return
105107 }
108 dispatch(&skunky, w, path)
109 }
110}
106111
107 var skunky = skunkyart{Version: Release.Version, Host: host}
108 skunky._pth = r.URL.Path
112// newSkunkyart builds the per-request state.
113func newSkunkyart(w http.ResponseWriter, r *http.Request, endpoint string) skunkyart {
114 // Per-request, not a package global: requests arrive concurrently on
115 // different hosts and ports (bots hitting a proxy's alternate ports, for
116 // one), and a shared global lets one request's host leak into another's
117 // rendered URLs. Those URLs then point at a different origin, which this
118 // handler's own default-src 'self' CSP blocks.
119 host := "http://" + r.Host
120 if h := r.Header["X-Forwarded-Proto"]; len(h) != 0 && h[0] == "https" {
121 host = "https://" + r.Host
122 }
109123
110 skunky.Args = r.URL.Query()
111 arg := skunky.Args.Get
112 p, _ := strconv.Atoi(arg("p"))
124 var skunky = skunkyart{Version: Release.Version, Host: host}
125 skunky._pth = r.URL.Path
113126
114 skunky.Endpoint = path[1]
115 skunky.API.main = &skunky
116 skunky.Writer = w
117 skunky.BasePath = CFG.URI
118 skunky.Lang = ResolveLang(r.Header.Get("Accept-Language"))
119 skunky.QueryRaw = arg("q")
120 skunky.Query = url.QueryEscape(skunky.QueryRaw)
121 skunky.Page = p
122
123 if t := arg("type"); len(t) > 0 {
124 skunky.Type = rune(t[0])
125 }
127 skunky.Args = r.URL.Query()
128 arg := skunky.Args.Get
129 p, _ := strconv.Atoi(arg("p"))
126130
127 if arg("atom") == "true" {
128 skunky.Atom = true
129 }
131 skunky.Endpoint = endpoint
132 skunky.Writer = w
133 skunky.BasePath = CFG.URI
134 skunky.Lang = ResolveLang(r.Header.Get("Accept-Language"))
135 skunky.QueryRaw = arg("q")
136 skunky.Query = url.QueryEscape(skunky.QueryRaw)
137 skunky.Page = p
130138
131 if CFG.Proxy {
132 w.Header().Add("Content-Security-Policy", "default-src 'self'; script-src 'none'; style-src 'self' 'unsafe-inline'")
133 } else {
134 w.Header().Add("Content-Security-Policy", "default-src 'self'; img-src 'self' *.wixmp.com; script-src 'none'; style-src 'self' 'unsafe-inline'")
135 }
139 if t := arg("type"); len(t) > 0 {
140 skunky.Type = rune(t[0])
141 }
136142
137 w.Header().Add("X-Frame-Options", "DENY")
138 w.Header().Set("Cache-Control", cacheControlPage)
143 if arg("atom") == "true" {
144 skunky.Atom = true
145 }
146 return skunky
147}
139148
140 if daLimiter != nil && limited(skunky.Endpoint) && !daLimiter.allow(clientAddr(r)) {
141 w.Header().Set("Retry-After", "60")
142 skunky.ReturnHTTPError(http.StatusTooManyRequests)
143 return
149func setPageHeaders(w http.ResponseWriter) {
150 if CFG.Proxy {
151 w.Header().Add("Content-Security-Policy", "default-src 'self'; script-src 'none'; style-src 'self' 'unsafe-inline'")
152 } else {
153 w.Header().Add("Content-Security-Policy", "default-src 'self'; img-src 'self' *.wixmp.com; script-src 'none'; style-src 'self' 'unsafe-inline'")
154 }
155
156 w.Header().Add("X-Frame-Options", "DENY")
157 w.Header().Set("Cache-Control", cacheControlPage)
158}
159
160// dispatch routes a request to the page, media, asset, or API handler for its endpoint.
161func dispatch(skunky *skunkyart, w http.ResponseWriter, path map[int]string) {
162 switch skunky.Endpoint {
163 // main
164 case "":
165 skunky.ExecuteTemplate("index.htm", "html", skunky)
166 case "about":
167 skunky.Templates.About = About
168 skunky.ExecuteTemplate("about.htm", "html", skunky)
169 case "post":
170 skunky.Deviation(path[2], path[3])
171 case "search":
172 skunky.Search()
173 case "dd":
174 skunky.DD()
175 case "group_user":
176 skunky.GRUser()
177 case "media":
178 serveMedia(skunky, w, path)
179 case "stylesheet", "favicon.ico", "robots.txt":
180 serveAsset(skunky.Endpoint, w)
181 case "api":
182 w.Header().Add("Content-Type", "application/json")
183 serveAPI(skunky, path)
184
185 // 404
186 default:
187 skunky.ReturnHTTPError(404)
188 }
189}
190
191func serveMedia(skunky *skunkyart, w http.ResponseWriter, path map[int]string) {
192 switch path[2] {
193 case "file":
194 if a := skunky.Args.Get("filename"); a != "" {
195 skunky.SetFilename(a)
144196 }
197 w.Header().Set("Cache-Control", cacheControlMedia)
198 skunky.DownloadAndSendMedia(path[3], joinPath(path, 4))
199 case "emojitar":
200 w.Header().Set("Cache-Control", cacheControlAssets)
201 skunky.Emojitar(path[3])
202 default:
203 skunky.ReturnHTTPError(404)
204 }
205}
145206
146 switch skunky.Endpoint {
147 // main
148 case "":
149 skunky.ExecuteTemplate("index.htm", "html", &skunky)
150 case "about":
151 skunky.Templates.About = About
152 skunky.ExecuteTemplate("about.htm", "html", &skunky)
153 case "post":
154 skunky.Deviation(path[2], path[3])
155 case "search":
156 skunky.Search()
157 case "dd":
158 skunky.DD()
159 case "group_user":
160 skunky.GRUser()
161
162 // media
163 case "media":
164 switch path[2] {
165 case "file":
166 if a := arg("filename"); a != "" {
167 skunky.SetFilename(a)
168 }
169 w.Header().Set("Cache-Control", cacheControlMedia)
170 skunky.DownloadAndSendMedia(path[3], next(path, 4))
171 case "emojitar":
172 w.Header().Set("Cache-Control", cacheControlAssets)
173 skunky.Emojitar(path[3])
174 default:
175 skunky.ReturnHTTPError(404)
176 }
177 case "stylesheet":
178 w.Header().Set("Cache-Control", cacheControlAssets)
179 w.Header().Add("Content-Type", "text/css")
180 _, _ = w.Write(open("css/skunky.css"))
181 // "auto" is the stylesheet as written: dark, with a light palette
182 // behind prefers-color-scheme. Forcing a theme means re-declaring
183 // that palette unconditionally, which outranks the media query
184 // because it comes later with equal specificity.
185 if css := forcedThemeCSS(); css != "" {
186 _, _ = w.Write([]byte(css))
187 }
188 case "favicon.ico":
189 w.Header().Set("Cache-Control", cacheControlAssets)
190 _, _ = w.Write(open("images/logo.png"))
191 case "robots.txt":
192 w.Header().Set("Cache-Control", cacheControlAssets)
193 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
194 wr(w, robotsTXT(CFG.URI))
195
196 // API
197 case "api":
198 w.Header().Add("Content-Type", "application/json")
199 switch path[2] {
200 case "instance":
201 skunky.API.Info()
202 case "random":
203 skunky.API.Random()
204 case "search":
205 skunky.API.Search()
206 case "post":
207 skunky.API.Post(path[3], path[4])
208 default:
209 skunky.API.Error("Not Found", 404)
210 }
211
212 // 404
213 default:
214 skunky.ReturnHTTPError(404)
207func serveAsset(endpoint string, w http.ResponseWriter) {
208 w.Header().Set("Cache-Control", cacheControlAssets)
209 switch endpoint {
210 case "stylesheet":
211 w.Header().Add("Content-Type", "text/css")
212 _, _ = w.Write(openStatic("css/skunky.css"))
213 // "auto" is the stylesheet as written: dark, with a light palette
214 // behind prefers-color-scheme. Forcing a theme means re-declaring
215 // that palette unconditionally, which outranks the media query
216 // because it comes later with equal specificity.
217 if css := forcedThemeCSS(); css != "" {
218 _, _ = w.Write([]byte(css))
215219 }
220 case "favicon.ico":
221 _, _ = w.Write(openStatic("images/logo.png"))
222 case "robots.txt":
223 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
224 wr(w, robotsTXT(CFG.URI))
225 }
226}
227
228func serveAPI(skunky *skunkyart, path map[int]string) {
229 switch path[2] {
230 case "instance":
231 skunky.API.Info()
232 case "random":
233 skunky.API.Random()
234 case "search":
235 skunky.API.Search()
236 case "post":
237 skunky.API.Post(path[3], path[4])
238 default:
239 skunky.API.Error("Not Found", 404)
216240 }
217241}
app/util.go +69 −61
@@ -130,35 +130,38 @@ type skunkyart struct {
130130 Comments template.HTML
131131 }
132132
133 GroupUser struct {
134 GR devianter.GRuser
135 Admins template.HTML
136 Group bool
137 CreationDate string
138
139 About struct {
140 A devianter.About
141
142 DescriptionFormatted template.HTML
143 Interests, Social template.HTML
144 Comments template.HTML
145 BG string
146 BGMeta devianter.Deviation
147 }
148
149 Gallery struct {
150 Folders template.HTML
151 Pages int
152 List template.HTML
153 }
154 }
155 Search struct {
133 GroupUser groupUserPage
134 Search struct {
156135 Content devianter.Search
157136 List template.HTML
158137 }
159138 }
160139}
161140
141// groupUserPage is the data the group/user page template renders.
142type groupUserPage struct {
143 GR devianter.GRuser
144 Admins template.HTML
145 Group bool
146 CreationDate string
147
148 About struct {
149 A devianter.About
150
151 DescriptionFormatted template.HTML
152 Interests, Social template.HTML
153 Comments template.HTML
154 BG string
155 BGMeta devianter.Deviation
156 }
157
158 Gallery struct {
159 Folders template.HTML
160 Pages int
161 List template.HTML
162 }
163}
164
162165// pageTemplates is every page template parsed once per language, by
163166// ParseTemplates. One set per language because T is bound at parse time, so
164167// templates ask for a key and never have to know which catalogue answered.
@@ -434,40 +437,10 @@ func (s skunkyart) NavBase(c DeviationList) string {
434437 var list strings.Builder
435438
436439 list.WriteString("<br>")
437 prevrev := func(msg string, page int, onpage bool) {
438 if !onpage {
439 list.WriteString(`<a href="`)
440 list.WriteString(esc(s._pth))
441 list.WriteString(`?p=`)
442 list.WriteString(strconv.Itoa(page))
443 if s.Type != 0 {
444 list.WriteString("&type=")
445 list.WriteRune(s.Type)
446 }
447 if s.Query != "" {
448 list.WriteString("&q=")
449 list.WriteString(esc(s.Query))
450 }
451 if f := s.Args.Get("folder"); f != "" {
452 list.WriteString("&folder=")
453 list.WriteString(esc(f))
454 }
455 if s.Args.Get("comments") != "" {
456 list.WriteString("&comments=1")
457 }
458 list.WriteString(`">`)
459 list.WriteString(msg)
460 list.WriteString("</a> ")
461 } else {
462 list.WriteString(strconv.Itoa(page))
463 list.WriteString(" ")
464 }
465 }
466
467440 p := s.Page
468441
469442 if p > 1 {
470 prevrev("<= "+esc(T(s.Lang, "nav.prev"))+" |", p-1, false)
443 s.writeNavLink(&list, "<= "+esc(T(s.Lang, "nav.prev"))+" |", p-1, false)
471444 } else {
472445 p = 1
473446 }
@@ -482,19 +455,54 @@ func (s skunkyart) NavBase(c DeviationList) string {
482455
483456 for i, x := p-6, 0; (i <= last && i <= p+6) && x < 12; i++ {
484457 if i > 0 {
485 var onPage bool
486 if i == p {
487 onPage = true
488 }
489
490 prevrev(strconv.Itoa(i), i, onPage)
458 s.writeNavLink(&list, strconv.Itoa(i), i, i == p)
491459 x++
492460 }
493461 }
494462
495463 if c.More {
496 prevrev("| "+esc(T(s.Lang, "nav.next"))+" =>", p+1, false)
464 s.writeNavLink(&list, "| "+esc(T(s.Lang, "nav.next"))+" =>", p+1, false)
497465 }
498466
499467 return list.String()
500468}
469
470// writeNavLink writes a link to page labelled msg, or just the page number
471// when it is the current page.
472func (s skunkyart) writeNavLink(list *strings.Builder, msg string, page int, onpage bool) {
473 if onpage {
474 list.WriteString(strconv.Itoa(page))
475 list.WriteString(" ")
476 return
477 }
478 list.WriteString(`<a href="`)
479 list.WriteString(esc(s._pth))
480 list.WriteString(s.pageQuery(page))
481 list.WriteString(`">`)
482 list.WriteString(msg)
483 list.WriteString("</a> ")
484}
485
486// pageQuery is the query string for page, carrying over the request's type,
487// search, folder, and comments arguments.
488func (s skunkyart) pageQuery(page int) string {
489 var q strings.Builder
490 q.WriteString(`?p=`)
491 q.WriteString(strconv.Itoa(page))
492 if s.Type != 0 {
493 q.WriteString("&type=")
494 q.WriteRune(s.Type)
495 }
496 if s.Query != "" {
497 q.WriteString("&q=")
498 q.WriteString(esc(s.Query))
499 }
500 if f := s.Args.Get("folder"); f != "" {
501 q.WriteString("&folder=")
502 q.WriteString(esc(f))
503 }
504 if s.Args.Get("comments") != "" {
505 q.WriteString("&comments=1")
506 }
507 return q.String()
508}
app/wrapper.go +175 −138
@@ -22,6 +22,12 @@ var (
2222 g := devianter.Group{Name: name}
2323 return g.Get()
2424 }
25 fetchGallery = func(g devianter.Group, page, folderid int) (devianter.Group, devianter.Error, error) {
26 return g.Gallery(page, folderid)
27 }
28 fetchFavourites = func(g devianter.Group, page int, all bool, folderid int) (devianter.Group, devianter.Error) {
29 return g.Favourites(page, all, folderid)
30 }
2531)
2632
2733// groupSearchURL is the DeviantArt group search page for query, paged ten
@@ -88,43 +94,11 @@ func (s skunkyart) GRUser() {
8894
8995 switch s.Type {
9096 case 'a':
91 g := group.GR
9297 s.Atom = false
93 for _, x := range g.Gruser.Page.Modules {
98 for _, x := range group.GR.Gruser.Page.Modules {
9499 switch x.Name {
95100 case "about", "group_about":
96 if g.Owner.Group {
97 var about = &x.ModuleData.GroupAbout
98 group.Group = true
99 group.CreationDate = x.ModuleData.GroupAbout.FoundatedAt.UTC().String()
100 group.About.DescriptionFormatted = template.HTML(ParseDescription(s.Host, about.Description)) //nolint:gosec // G203: ParseDescription escapes its input
101 } else {
102 group.About.A = x.ModuleData.About
103 var about = &group.About.A
104 group.CreationDate = time.Unix(time.Now().Unix()-x.ModuleData.About.RegDate, 0).UTC().String()
105 group.About.DescriptionFormatted = template.HTML(ParseDescription(s.Host, about.Description)) //nolint:gosec // G203: ParseDescription escapes its input
106
107 for _, val := range x.ModuleData.About.SocialLinks {
108 var social strings.Builder
109 social.WriteString(`<a target="_blank" href="`)
110 social.WriteString(esc(val.Value))
111 social.WriteString(`">`)
112 social.WriteString(esc(val.Value))
113 social.WriteString("</a><br>")
114 group.About.Social += template.HTML(social.String()) //nolint:gosec // G203: escaped above
115 }
116
117 for _, val := range x.ModuleData.About.Interests {
118 var interest strings.Builder
119 interest.WriteString(esc(val.Label))
120 interest.WriteString(": <b>")
121 interest.WriteString(esc(val.Value))
122 interest.WriteString("</b><br>")
123 group.About.Interests += template.HTML(interest.String()) //nolint:gosec // G203: escaped above
124 }
125 }
126 group.About.Comments = s.commentsOrLink(strconv.Itoa(group.GR.Gruser.ID), "", 4, -1)
127
101 s.fillAbout(group, x.ModuleData.GroupAbout, x.ModuleData.About)
128102 case "cover_deviation":
129103 group.About.BGMeta = x.ModuleData.CoverDeviation.Deviation
130104 group.About.BGMeta.Url = ConvertDeviantArtURLToSkunkyArt(s.Host, group.About.BGMeta.Url)
@@ -136,94 +110,187 @@ func (s skunkyart) GRUser() {
136110 }
137111 group.Admins += template.HTML(htm.String()) //nolint:gosec // G203: BuildUserPlate escapes its input
138112 }
139
140113 }
141114 case 'g', 'f':
142 var all bool
143 var content devianter.Group
144
145 folderid, _ := strconv.Atoi(s.Args.Get("folder"))
146
147 if s.Args.Get("all") == "true" {
148 all = true
149 }
150
151115 if s.Page == 0 {
152116 s.Page++
153117 }
154
155 if s.Type == 'f' {
156 content, daError = g.Favourites(s.Page, all, folderid)
157 } else {
158 content, daError, err = g.Gallery(s.Page, folderid)
159 try(err)
160 }
161
162 if daError.RAW != nil {
163 s.Error(daError)
118 if !s.fillGallery(group, g) {
164119 return
165120 }
121 default:
122 s.ReturnHTTPError(400)
123 }
124
125 if !s.Atom {
126 s.ExecuteTemplate("gruser.htm", "html", &s)
127 }
128}
129
130// fillAbout fills the about tab from a group's or a user's about module.
131func (s skunkyart) fillAbout(group *groupUserPage, groupAbout devianter.GroupAbout, about devianter.About) {
132 if group.GR.Owner.Group {
133 group.Group = true
134 group.CreationDate = groupAbout.FoundatedAt.UTC().String()
135 group.About.DescriptionFormatted = template.HTML(ParseDescription(s.Host, groupAbout.Description)) //nolint:gosec // G203: ParseDescription escapes its input
136 } else {
137 group.About.A = about
138 group.CreationDate = time.Unix(time.Now().Unix()-about.RegDate, 0).UTC().String()
139 group.About.DescriptionFormatted = template.HTML(ParseDescription(s.Host, about.Description)) //nolint:gosec // G203: ParseDescription escapes its input
140 group.About.Social += profileLinks(about)
141 group.About.Interests += profileInterests(about)
142 }
143 group.About.Comments = s.commentsOrLink(strconv.Itoa(group.GR.Gruser.ID), "", 4, -1)
144}
145
146func profileLinks(about devianter.About) template.HTML {
147 var out template.HTML
148 for _, val := range about.SocialLinks {
149 var social strings.Builder
150 social.WriteString(`<a target="_blank" href="`)
151 social.WriteString(esc(val.Value))
152 social.WriteString(`">`)
153 social.WriteString(esc(val.Value))
154 social.WriteString("</a><br>")
155 out += template.HTML(social.String()) //nolint:gosec // G203: escaped above
156 }
157 return out
158}
159
160func profileInterests(about devianter.About) template.HTML {
161 var out template.HTML
162 for _, val := range about.Interests {
163 var interest strings.Builder
164 interest.WriteString(esc(val.Label))
165 interest.WriteString(": <b>")
166 interest.WriteString(esc(val.Value))
167 interest.WriteString("</b><br>")
168 out += template.HTML(interest.String()) //nolint:gosec // G203: escaped above
169 }
170 return out
171}
172
173// fillGallery fills the gallery or favourites tab. It returns false when
174// DeviantArt answered with an error, which has already been rendered.
175func (s skunkyart) fillGallery(group *groupUserPage, g devianter.Group) bool {
176 var err error
177 var daError devianter.Error
178 var content devianter.Group
179 folderid, _ := strconv.Atoi(s.Args.Get("folder"))
180 all := s.Args.Get("all") == "true"
181
182 if s.Type == 'f' {
183 content, daError = fetchFavourites(g, s.Page, all, folderid)
184 } else {
185 content, daError, err = fetchGallery(g, s.Page, folderid)
186 try(err)
187 }
188
189 if daError.RAW != nil {
190 s.Error(daError)
191 return false
192 }
166193
167 if folderid > 0 || (s.Type == 'f' && all) {
168 group.Gallery.List = template.HTML(s.DeviationList(content.Content.Results, true, DeviationList{ //nolint:gosec // G203: DeviationList escapes its input
169 More: content.Content.HasMore,
194 if folderid > 0 || (s.Type == 'f' && all) {
195 group.Gallery.List = template.HTML(s.DeviationList(content.Content.Results, true, DeviationList{ //nolint:gosec // G203: DeviationList escapes its input
196 More: content.Content.HasMore,
197 }))
198 return true
199 }
200 for _, x := range content.Content.Gruser.Page.Modules {
201 if len(x.ModuleData.Folders.Results) != 0 {
202 group.Gallery.Folders = s.folderGrid(x.ModuleData.Folders.Results)
203 }
204 if x.Name == "folder_deviations" {
205 group.Gallery.List = template.HTML(s.DeviationList(x.ModuleData.Folder.Deviations, true, DeviationList{ //nolint:gosec // G203: DeviationList escapes its input
206 Pages: x.ModuleData.Folder.Pages,
207 More: x.ModuleData.Folder.HasMore,
170208 }))
209 }
210 }
211 return true
212}
213
214// galleryFolder is one entry of a gallery's folder list, as devianter decodes it.
215type galleryFolder = struct {
216 Deviations int `json:"totalItemCount"`
217 FolderId int //nolint:staticcheck // ST1003: must match devianter's field for the types to be identical
218 Size int
219 Name string
220 Thumb devianter.Deviation
221}
222
223// folderGrid renders the non-empty folders of a gallery as thumbnail links.
224func (s skunkyart) folderGrid(results []galleryFolder) template.HTML {
225 var folders strings.Builder
226 folders.WriteString(`<h1 id="folders"><a href="#folders">#</a> ` + esc(T(s.Lang, "gallery.folders")) + `</h1><div class="folders"><br>`)
227 for _, x := range results {
228 if x.FolderId == -1 || x.Size == 0 {
229 continue
230 }
231 folders.WriteString(`<div class="block folder-item">`)
232 if !x.Thumb.NSFW || CFG.Nsfw {
233 folders.WriteString(`<a href="`)
234 folders.WriteString(esc(ConvertDeviantArtURLToSkunkyArt(s.Host, x.Thumb.Url)))
235 folders.WriteString(`"><img loading="lazy" src="`)
236 folders.WriteString(esc(ParseMedia(s.Host, x.Thumb.Media)))
237 folders.WriteString(`" title="`)
238 folders.WriteString(esc(x.Thumb.Title))
239 folders.WriteString(`" alt="`)
240 folders.WriteString(esc(x.Thumb.Title))
241 folders.WriteString(`"></a>`)
171242 } else {
172 for _, x := range content.Content.Gruser.Page.Modules {
173 if len(x.ModuleData.Folders.Results) != 0 {
174 var folders strings.Builder
175 folders.WriteString(`<h1 id="folders"><a href="#folders">#</a> ` + esc(T(s.Lang, "gallery.folders")) + `</h1><div class="folders"><br>`)
176 for _, x := range x.ModuleData.Folders.Results {
177 if x.FolderId != -1 && x.Size != 0 {
178 folders.WriteString(`<div class="block folder-item">`)
179
180 if !x.Thumb.NSFW || CFG.Nsfw {
181 folders.WriteString(`<a href="`)
182 folders.WriteString(esc(ConvertDeviantArtURLToSkunkyArt(s.Host, x.Thumb.Url)))
183 folders.WriteString(`"><img loading="lazy" src="`)
184 folders.WriteString(esc(ParseMedia(s.Host, x.Thumb.Media)))
185 folders.WriteString(`" title="`)
186 folders.WriteString(esc(x.Thumb.Title))
187 folders.WriteString(`" alt="`)
188 folders.WriteString(esc(x.Thumb.Title))
189 folders.WriteString(`"></a>`)
190 } else {
191 folders.WriteString(`<h1>[ <span class="nsfw">NSFW</span> ]</h1>`)
192 }
193 folders.WriteString("<br>")
194
195 folders.WriteString(`<a href="group_user?folder=`)
196 folders.WriteString(strconv.Itoa(x.FolderId))
197 folders.WriteString("&q=")
198 folders.WriteString(esc(s.Query))
199 folders.WriteString("&type=")
200 folders.WriteRune(s.Type)
201 folders.WriteString(`">`)
202 folders.WriteString(esc(x.Name))
203 folders.WriteString(`</a>`)
204
205 folders.WriteString("</div>")
206 }
207 }
208 folders.WriteString(`</div><h1 id="content"><a href="#content">#</a> ` + esc(T(s.Lang, "gallery.content")) + `</h1>`)
209 group.Gallery.Folders = template.HTML(folders.String()) //nolint:gosec // G203: escaped above
210 }
243 folders.WriteString(`<h1>[ <span class="nsfw">NSFW</span> ]</h1>`)
244 }
245 folders.WriteString("<br>")
246
247 folders.WriteString(`<a href="group_user?folder=`)
248 folders.WriteString(strconv.Itoa(x.FolderId))
249 folders.WriteString("&q=")
250 folders.WriteString(esc(s.Query))
251 folders.WriteString("&type=")
252 folders.WriteRune(s.Type)
253 folders.WriteString(`">`)
254 folders.WriteString(esc(x.Name))
255 folders.WriteString(`</a>`)
256
257 folders.WriteString("</div>")
258 }
259 folders.WriteString(`</div><h1 id="content"><a href="#content">#</a> ` + esc(T(s.Lang, "gallery.content")) + `</h1>`)
260 return template.HTML(folders.String()) //nolint:gosec // G203: escaped above
261}
211262
212 if x.Name == "folder_deviations" {
213 group.Gallery.List = template.HTML(s.DeviationList(x.ModuleData.Folder.Deviations, true, DeviationList{ //nolint:gosec // G203: DeviationList escapes its input
214 Pages: x.ModuleData.Folder.Pages,
215 More: x.ModuleData.Folder.HasMore,
216 }))
217 }
263// groupSearchUsernames scrapes the group names from DeviantArt's group search page.
264func groupSearchUsernames(body []byte) []string {
265 var usernames []string
266 for z := html.NewTokenizer(strings.NewReader(string(body))); ; {
267 n, token := z.Next(), z.Token()
268 if n == html.ErrorToken {
269 return usernames
270 }
271 if n != html.StartTagToken || token.Data != "a" {
272 continue
273 }
274 for _, x := range token.Attr {
275 if x.Key == "class" && x.Val == "u regular username" {
276 usernames = append(usernames, GetValueOfTag(z))
218277 }
219278 }
220 default:
221 s.ReturnHTTPError(400)
222279 }
280}
223281
224 if !s.Atom {
225 s.ExecuteTemplate("gruser.htm", "html", &s)
282// groupPlates renders scraped group names as user plates with page navigation.
283func (s skunkyart) groupPlates(usernames []string) template.HTML {
284 var plates strings.Builder
285 plates.WriteString(`<div class="content plates">`)
286 for _, name := range usernames {
287 plates.WriteString(BuildUserPlate(s.Host, name))
226288 }
289 plates.WriteString(`</div>`)
290 plates.WriteString(s.NavBase(DeviationList{
291 More: true,
292 }))
293 return template.HTML(plates.String()) //nolint:gosec // G203: BuildUserPlate escapes its input
227294}
228295
229296// Deviation renders a single artwork page, with its description, tags, comments
@@ -335,39 +402,9 @@ func (s skunkyart) Search() {
335402 case 'g', 'f':
336403 ss.Content, daError, err = devianter.PerformSearch(s.Query, s.Page, s.Type, s.Args.Get("usr"))
337404 case 'r': // scraper, since DeviantArt withholds the guest API for group search
338 var (
339 usernames = make(map[int]string)
340 num int
341 )
342
343405 dwnld := Download(groupSearchURL(s.Query, s.Page))
344
345 for z := html.NewTokenizer(strings.NewReader(string(dwnld.Body))); ; {
346 if n, token := z.Next(), z.Token(); n == html.StartTagToken && token.Data == "a" {
347 for _, x := range token.Attr {
348 if x.Key == "class" && x.Val == "u regular username" {
349 usernames[num] = GetValueOfTag(z)
350 num++
351 }
352 }
353 } else if n == 0 {
354 break
355 } else {
356 continue
357 }
358 }
359
360 if len(usernames) != 0 {
361 var plates strings.Builder
362 plates.WriteString(`<div class="content plates">`)
363 for x := range len(usernames) {
364 plates.WriteString(BuildUserPlate(s.Host, usernames[x]))
365 }
366 plates.WriteString(`</div>`)
367 plates.WriteString(s.NavBase(DeviationList{
368 More: true,
369 }))
370 ss.List = template.HTML(plates.String()) //nolint:gosec // G203: BuildUserPlate escapes its input
406 if usernames := groupSearchUsernames(dwnld.Body); len(usernames) != 0 {
407 ss.List = s.groupPlates(usernames)
371408 }
372409 default:
373410 s.ReturnHTTPError(400)